1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
package client
import (
"codeberg.org/eduVPN/proxyguard"
"github.com/eduvpn/eduvpn-common/i18nerr"
"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.Debugf("[Proxyguard] "+msg, params...)
}
// Log logs a message
func (pl *ProxyLogger) Log(msg string) {
log.Logger.Debugf("[Proxyguard] %s", msg)
}
// StartProxyguard starts proxyguard for proxied WireGuard connections
func (c *Client) StartProxyguard(ck *cookie.Cookie, listen string, tcpsp int, peer string, gotFD func(fd int), ready func()) error {
var err error
proxyguard.UpdateLogger(&ProxyLogger{})
proxyc := proxyguard.Client{
Listen: listen,
TCPSourcePort: tcpsp,
SetupSocket: func(fd int, _ []string) {
if gotFD != nil {
gotFD(fd)
}
// TODO: support peerips
},
Ready: ready,
}
// we set peer IPs to nil here as proxyguard already does a DNS request for us
err = proxyc.Tunnel(ck.Context(), peer, nil)
if err != nil {
return i18nerr.Wrap(err, "The VPN proxy exited")
}
return err
}
|