diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2024-11-14 14:59:20 +0100 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2024-12-19 10:50:36 +0100 |
| commit | 4de4d76ad1ef1dc52b6e2e03c4fc81d4ea8d467e (patch) | |
| tree | f09aadb416c61c94eb703d950b1689645aad4c4c | |
| parent | 2f3a9d0c1687e6f591ccdb7d44a36cdc09359321 (diff) | |
ProxyGuard: Add a restart function
| -rw-r--r-- | exports/exports.go | 16 | ||||
| -rw-r--r-- | go.mod | 2 | ||||
| -rw-r--r-- | proxy/proxy.go | 36 | ||||
| -rw-r--r-- | wrappers/python/eduvpn_common/loader.py | 6 | ||||
| -rw-r--r-- | wrappers/python/eduvpn_common/main.py | 5 |
5 files changed, 60 insertions, 5 deletions
diff --git a/exports/exports.go b/exports/exports.go index f2fa75e..3c9c59a 100644 --- a/exports/exports.go +++ b/exports/exports.go @@ -912,6 +912,22 @@ func NewProxyguard(c C.uintptr_t, lp C.int, tcpsp C.int, peer *C.char, proxySetu return C.uintptr_t(cgo.NewHandle(proxy)), nil } +// ProxyguardRestart restarts ProxyGuard, call this when a network change happens +// +// Example Input: ```ProxyguardRestart(proxyHandle)``` +// +// Example Output: ```"failed restarting ProxyGuard"``` +// +//export ProxyguardRestart +func ProxyguardRestart(proxyH C.uintptr_t) *C.char { + pr, err := getProxy(proxyH) + if err != nil { + return getCError(err) + } + pr.Restart() + return nil +} + func getProxy(proxyH C.uintptr_t) (*proxy.Proxy, error) { h := cgo.Handle(proxyH) v, ok := h.Value().(*proxy.Proxy) @@ -2,6 +2,8 @@ module codeberg.org/eduVPN/eduvpn-common go 1.22 +replace codeberg.org/eduVPN/proxyguard => ../proxyguard + require ( codeberg.org/eduVPN/proxyguard v0.0.0-20241028155505-e9ee8522373e github.com/jedisct1/go-minisign v0.0.0-20230811132847-661be99b8267 diff --git a/proxy/proxy.go b/proxy/proxy.go index 439e239..06c833f 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -29,19 +29,21 @@ func (l *Logger) Log(msg string) { type Proxy struct { proxyguard.Client + resChan chan struct{} } // NewProxyguard sets up proxyguard for proxied WireGuard connections func NewProxyguard(ctx context.Context, lp int, tcpsp int, peer string, setupSocket func(fd int)) (*Proxy, error) { proxyguard.UpdateLogger(&Logger{}) proxy := Proxy{ - proxyguard.Client{ + Client: proxyguard.Client{ Peer: peer, ListenPort: lp, TCPSourcePort: tcpsp, SetupSocket: setupSocket, UserAgent: httpw.UserAgent, }, + resChan: make(chan struct{}), } err := proxy.Client.SetupDNS(ctx) if err != nil { @@ -52,9 +54,33 @@ func NewProxyguard(ctx context.Context, lp int, tcpsp int, peer string, setupSoc } func (p *Proxy) Tunnel(ctx context.Context, wglisten int) error { - err := p.Client.Tunnel(ctx, wglisten) - if err != nil { - return i18nerr.WrapInternal(err, "The VPN proxy exited") + log.Logger.Infof("callying tunnel") + errChan := make(chan error, 1) + gctx, cancel := context.WithCancel(ctx) + go func() { + err := p.Client.Tunnel(gctx, wglisten) + defer log.Logger.Infof("exit goroutine") + if err != nil { + err = i18nerr.WrapInternal(err, "The VPN proxy exited") + } + errChan <- err + }() + + select { + case err := <- errChan: + log.Logger.Infof("exit hier") + cancel() + return err + case <- p.resChan: + log.Logger.Infof("before cancel") + cancel() + log.Logger.Infof("after cancel") + <- errChan + log.Logger.Infof("after errChan") + return p.Tunnel(ctx, wglisten) } - return nil +} + +func (p *Proxy) Restart() { + p.resChan <- struct{}{} } diff --git a/wrappers/python/eduvpn_common/loader.py b/wrappers/python/eduvpn_common/loader.py index 8ac6372..11307ef 100644 --- a/wrappers/python/eduvpn_common/loader.py +++ b/wrappers/python/eduvpn_common/loader.py @@ -144,6 +144,12 @@ def initialize_functions(lib: CDLL) -> None: ], HandlerError, ) + lib.ProxyguardRestart.argtypes, lib.ProxyguardRestart.restype = ( + [ + c_int, + ], + c_char_p, + ) lib.ProxyguardTunnel.argtypes, lib.ProxyguardTunnel.restype = ( [ c_int, diff --git a/wrappers/python/eduvpn_common/main.py b/wrappers/python/eduvpn_common/main.py index 04a2302..8d78afd 100644 --- a/wrappers/python/eduvpn_common/main.py +++ b/wrappers/python/eduvpn_common/main.py @@ -37,6 +37,11 @@ class Proxyguard(object): forwardError(peer_ips_err) return json.loads(peer_ips) + def restart(self): + restart_err = self.parent.go_function(self.parent.lib.ProxyguardRestart, self.handler) + if restart_err: + forwardError(restart_err) + class WrappedError(Exception): def __init__(self, translations, language, misc): |
