diff options
Diffstat (limited to 'client')
| -rw-r--r-- | client/client.go | 8 | ||||
| -rw-r--r-- | client/proxy.go | 125 | ||||
| -rw-r--r-- | client/proxy_test.go | 36 |
3 files changed, 0 insertions, 169 deletions
diff --git a/client/client.go b/client/client.go index e5a39c0..e8fc02c 100644 --- a/client/client.go +++ b/client/client.go @@ -49,9 +49,6 @@ type Client struct { // cfg is the config cfg *config.Config - // proxy is proxyguard - proxy Proxy - mu sync.Mutex discoMan *discovery.Manager @@ -557,11 +554,6 @@ func (c *Client) retrieveTokens(sid string, t srvtypes.Type) (*eduoauth.Token, e // Cleanup cleans up the VPN connection by sending a /disconnect func (c *Client) Cleanup(ck *cookie.Cookie) error { defer c.TrySave() - // cleanup proxyguard - cerr := c.proxy.Cancel() - if cerr != nil { - log.Logger.Debugf("ProxyGuard cancel gave an error: %v", cerr) - } srv, err := c.Servers.CurrentServer() if err != nil { return i18nerr.WrapInternal(err, "The current server was not found when cleaning up the connection") diff --git a/client/proxy.go b/client/proxy.go deleted file mode 100644 index 2a900e0..0000000 --- a/client/proxy.go +++ /dev/null @@ -1,125 +0,0 @@ -package client - -import ( - "context" - "encoding/json" - "errors" - "sync" - - "codeberg.org/eduVPN/proxyguard" - - "github.com/eduvpn/eduvpn-common/i18nerr" - httpw "github.com/eduvpn/eduvpn-common/internal/http" - "github.com/eduvpn/eduvpn-common/internal/log" - "github.com/eduvpn/eduvpn-common/types/cookie" -) - -// ProxyLogger is defined here such that we can update the proxyguard logger -type ProxyLogger struct{} - -// Logf logs a message with parameters -func (pl *ProxyLogger) Logf(msg string, params ...interface{}) { - log.Logger.Infof("[Proxyguard] "+msg, params...) -} - -// Log logs a message -func (pl *ProxyLogger) Log(msg string) { - log.Logger.Infof("[Proxyguard] %s", msg) -} - -// Proxy is a wrapper around ProxyGuard -// that has the client -// and a cancel for cancellation by common -// and a mutex to protect against race conditions -type Proxy struct { - c *proxyguard.Client - mu sync.Mutex - cancel context.CancelFunc -} - -// NewClient creates a new ProxyGuard wrapper from client `c` -func (p *Proxy) NewClient(c *proxyguard.Client) { - p.mu.Lock() - defer p.mu.Unlock() - p.c = c -} - -// Delete sets the inner client to nil -func (p *Proxy) Delete() { - p.mu.Lock() - defer p.mu.Unlock() - p.c = nil -} - -// ErrNoProxyGuardCancel indicates that no ProxyGuard cancel function -// was ever defined. You probably forgot to call `Tunnel` -var ErrNoProxyGuardCancel = errors.New("no ProxyGuard cancel function") - -// Cancel cancels a running ProxyGuard tunnel -// it returns an error if it cannot be canceled -func (p *Proxy) Cancel() error { - p.mu.Lock() - defer p.mu.Unlock() - if p.cancel == nil { - return ErrNoProxyGuardCancel - } - p.cancel() - p.cancel = nil - return nil -} - -// ErrNoProxyGuardClient is an error that is returned when no ProxyGuard client is created -var ErrNoProxyGuardClient = errors.New("no ProxyGuard client created") - -// Tunnel is a wrapper around ProxyGuard tunnel that -// that creates a new context that can be canceled -func (p *Proxy) Tunnel(ctx context.Context, peer string) error { - p.mu.Lock() - if p.c == nil { - p.mu.Unlock() - return ErrNoProxyGuardClient - } - cctx, cf := context.WithCancel(ctx) - p.cancel = cf - client := *p.c - p.mu.Unlock() - defer func() { - p.mu.Lock() - p.cancel = nil - p.mu.Unlock() - }() - // we set peer IPs to nil here as proxyguard already does a DNS request for us - return client.Tunnel(cctx, peer, nil) -} - -// StartProxyguard starts proxyguard for proxied WireGuard connections -func (c *Client) StartProxyguard(ck *cookie.Cookie, listen string, tcpsp int, peer string, gotFD func(fd int, pips string), ready func()) error { - var err error - proxyguard.UpdateLogger(&ProxyLogger{}) - - proxyc := proxyguard.Client{ - Listen: listen, - TCPSourcePort: tcpsp, - SetupSocket: func(fd int, pips []string) { - if gotFD == nil { - return - } - b, err := json.Marshal(pips) - if err != nil { - log.Logger.Errorf("marshalling peer IPs failed: %v", err) - return - } - gotFD(fd, string(b)) - }, - UserAgent: httpw.UserAgent, - Ready: ready, - } - - c.proxy.NewClient(&proxyc) - defer c.proxy.Delete() - err = c.proxy.Tunnel(ck.Context(), peer) - if err != nil { - return i18nerr.WrapInternal(err, "The VPN proxy exited") - } - return err -} diff --git a/client/proxy_test.go b/client/proxy_test.go deleted file mode 100644 index ddb0c4f..0000000 --- a/client/proxy_test.go +++ /dev/null @@ -1,36 +0,0 @@ -package client - -import ( - "context" - "errors" - "testing" - - "codeberg.org/eduVPN/proxyguard" -) - -func TestProxy(t *testing.T) { - // test race - p := Proxy{} - p.NewClient(&proxyguard.Client{}) - go func() { - // connect to localhost will fail - // but we don't care about the error - _ = p.Tunnel(context.Background(), "127.0.0.1") - }() - // race! - _ = p.Cancel() - - // cancel before tunneling - p.NewClient(&proxyguard.Client{}) - if !errors.Is(p.Cancel(), ErrNoProxyGuardCancel) { - t.Fatalf("proxyguard cancel err not equal") - } - _ = p.Tunnel(context.Background(), "127.0.0.1") - p.Delete() - - // tunnel without client - gerr := p.Tunnel(context.Background(), "127.0.0.1") - if !errors.Is(gerr, ErrNoProxyGuardClient) { - t.Fatalf("no proxyguard client err not equal") - } -} |
