summaryrefslogtreecommitdiff
path: root/proxy
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2024-10-23 11:31:39 +0200
committerJeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com>2024-10-29 12:08:36 +0100
commite85070a3fb601e1872d121ce3c1c9d39f8f41036 (patch)
tree96d57bf647f2cdc3408ad5c3163ca91ed571cb63 /proxy
parent0076386bca8b1e49673f50323cd147ac080cfc2f (diff)
All: Refactor to latest ProxyGuard
Diffstat (limited to 'proxy')
-rw-r--r--proxy/proxy.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/proxy/proxy.go b/proxy/proxy.go
new file mode 100644
index 0000000..8df539a
--- /dev/null
+++ b/proxy/proxy.go
@@ -0,0 +1,60 @@
+// package proxy is a wrapper around proxyguard that integrates it with eduvpn-common settings
+// - leaves out some options not applicable to the common integration, e.g. fwmark
+// - integrates with eduvpn-common's logger
+// - integrates eduvpn-common's user agent
+package proxy
+
+import (
+ "context"
+
+ "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"
+)
+
+// Logger is defined here such that we can update the proxyguard logger
+type Logger struct{}
+
+// Logf logs a message with parameters
+func (l *Logger) Logf(msg string, params ...interface{}) {
+ log.Logger.Infof("[Proxyguard] "+msg, params...)
+}
+
+// Log logs a message
+func (l *Logger) Log(msg string) {
+ log.Logger.Infof("[Proxyguard] %s", msg)
+}
+
+type Proxy struct {
+ proxyguard.Client
+}
+
+// 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{
+ Peer: peer,
+ ListenPort: lp,
+ TCPSourcePort: tcpsp,
+ SetupSocket: setupSocket,
+ UserAgent: httpw.UserAgent,
+ },
+ }
+ err := proxy.Client.SetupDNS(ctx)
+ if err != nil {
+ return nil, i18nerr.WrapInternal(err, "The ProxyGuard DNS could not be resolved")
+ }
+
+ return &proxy, nil
+}
+
+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")
+ }
+ return nil
+}