diff options
author | atanarjuat <atanarjuat@example.com> | 2022-05-29 22:18:12 +0200 |
---|---|---|
committer | atanarjuat <atanarjuat@example.com> | 2022-05-29 22:18:12 +0200 |
commit | 60eda76d073ad9c0eaef63c6eb31d47e5ca86ff7 (patch) | |
tree | e757b95a836e6c1e788fa030a165cc8bf8c687f6 /client/client.go | |
parent | 6f2d28e19a41e9aa777071f63eebec89ca80ade4 (diff) |
attempt at android bindings
Diffstat (limited to 'client/client.go')
-rw-r--r-- | client/client.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/client/client.go b/client/client.go new file mode 100644 index 0000000..c0a42e0 --- /dev/null +++ b/client/client.go @@ -0,0 +1,55 @@ +package client + +import ( + "fmt" + "log" + "net" + + "0xacab.org/leap/obfsvpn" + + "github.com/kalikaneko/socks5" + "github.com/xtaci/kcp-go" +) + +type Client struct { + kcp bool + socksAddr string + obfs4Cert string +} + +func NewClient(kcp bool, socksAddr, obfs4Cert string) *Client { + return &Client{ + kcp: kcp, + socksAddr: socksAddr, + obfs4Cert: obfs4Cert, + } +} + +func (c *Client) Start() bool { + server := &socks5.Server{ + Addr: c.socksAddr, + BindIP: "127.0.0.1", + } + + dialer, err := obfsvpn.NewDialerFromCert(c.obfs4Cert) + if err != nil { + log.Printf("Error getting dialer: %v\n", err) + return false + } + + if c.kcp { + dialer.DialFunc = func(network, address string) (net.Conn, error) { + log.Printf("Dialing kcp://%s\n", address) + return kcp.Dial(address) + } + } + + server.Dial = dialer.Dial + + fmt.Printf("[+] Starting socks5 proxy at %s\n", c.socksAddr) + if err := server.ListenAndServe(); err != nil { + log.Printf("error while listening: %v\n", err) + return false + } + return true +} |