diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2024-10-23 11:31:39 +0200 |
|---|---|---|
| committer | Jeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com> | 2024-10-29 12:08:36 +0100 |
| commit | e85070a3fb601e1872d121ce3c1c9d39f8f41036 (patch) | |
| tree | 96d57bf647f2cdc3408ad5c3163ca91ed571cb63 /wrappers/python/eduvpn_common/main.py | |
| parent | 0076386bca8b1e49673f50323cd147ac080cfc2f (diff) | |
All: Refactor to latest ProxyGuard
Diffstat (limited to 'wrappers/python/eduvpn_common/main.py')
| -rw-r--r-- | wrappers/python/eduvpn_common/main.py | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/wrappers/python/eduvpn_common/main.py b/wrappers/python/eduvpn_common/main.py index ce52024..04a2302 100644 --- a/wrappers/python/eduvpn_common/main.py +++ b/wrappers/python/eduvpn_common/main.py @@ -1,13 +1,12 @@ import ctypes import json from enum import IntEnum -from typing import Any, Callable, Iterator, Optional +from typing import Any, Callable, Iterator, List, Optional from eduvpn_common.event import EventHandler from eduvpn_common.loader import initialize_functions, load_lib from eduvpn_common.state import State from eduvpn_common.types import ( - ProxyReady, ProxySetup, ReadRxBytes, RefreshList, @@ -21,6 +20,24 @@ from eduvpn_common.types import ( global_object = None +class Proxyguard(object): + def __init__(self, parent, handler): + self.parent = parent + self.handler = handler + + def tunnel(self, wglisten: int): + tunnel_err = self.parent.go_cookie_function(self.parent.lib.ProxyguardTunnel, self.handler, wglisten) + if tunnel_err: + forwardError(tunnel_err) + + @property + def peer_ips(self) -> List[str]: + peer_ips, peer_ips_err = self.parent.go_function(self.parent.lib.ProxyguardPeerIPs, self.handler) + if peer_ips_err: + forwardError(peer_ips_err) + return json.loads(peer_ips) + + class WrappedError(Exception): def __init__(self, translations, language, misc): self.translations = translations @@ -359,24 +376,23 @@ class EduVPN(object): forwardError(dropped_err) return dropped - def start_proxyguard( + def new_proxyguard( self, - listen: str, - source_port: int, + listen_port: int, + tcp_source_port: int, peer: str, setup: ProxySetup, - ready: ProxyReady, - ): - proxy_err = self.go_cookie_function( - self.lib.StartProxyguard, - listen, - source_port, + ) -> Proxyguard: + proxy, proxy_err = self.go_cookie_function( + self.lib.NewProxyguard, + listen_port, + tcp_source_port, peer, setup, - ready, ) if proxy_err: forwardError(proxy_err) + return Proxyguard(self, proxy) def cancel(self): self.jar.cancel() |
