// Package client exposes an obfsvpn client that launches a local socks5 proxy, // with optional kcp wire transport. 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 server *socks5.Server } func NewClient(kcp bool, socksAddr, obfs4Cert string) *Client { return &Client{ kcp: kcp, socksAddr: socksAddr, obfs4Cert: obfs4Cert, } } func (c *Client) Start() bool { if c.server != nil { log.Printf("Cannot start proxy server if already initialzied") return false } c.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) } } c.server.Dial = dialer.Dial fmt.Printf("[+] Starting socks5 proxy at %s\n", c.socksAddr) if err := c.server.ListenAndServe(); err != nil { log.Printf("error while listening: %v\n", err) c.server = nil return false } return true } func (c *Client) Stop() bool { if c.server == nil { return false } defer func() { c.server = nil }() if err := c.server.Close(); err != nil { log.Printf("error while stopping: %v\n", err) return false } return true }