summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoratanarjuat <atanarjuat@example.com>2022-05-29 21:40:51 +0200
committeratanarjuat <atanarjuat@example.com>2022-05-29 21:40:51 +0200
commit9c86df328f25472e27252b2a723ef43435a7cf57 (patch)
tree39b9c54d9e96a7ea008b2034f8873bca49bcd4aa
parent8fa1b47e4b4d51a4c8ef2d86dfd5b8677e748741 (diff)
refactor
-rw-r--r--client/main.go53
1 files changed, 40 insertions, 13 deletions
diff --git a/client/main.go b/client/main.go
index 1c866ae..b536a81 100644
--- a/client/main.go
+++ b/client/main.go
@@ -46,30 +46,57 @@ func main() {
debug.SetOutput(os.Stderr)
}
- dialer, err := obfsvpn.NewDialerFromCert(obfs4Cert)
- if err != nil {
- logger.Fatalf("cannot get dialer: %v", err)
- }
-
+ kcpTransport := false
// TODO make this configurable via a Config struct
// TODO make sure we're disabling all the crypto options for KCP
if os.Getenv("KCP") == "1" {
- dialer.DialFunc = func(network, address string) (net.Conn, error) {
- log.Printf("Dialing kcp://%s\n", address)
- return kcp.Dial(address)
- }
+ kcpTransport = true
}
socksAddr := net.JoinHostPort(socksHost, socksPort)
+ client := NewClient(kcpTransport, socksAddr, obfs4Cert)
+ client.Start()
+}
+
+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: socksAddr,
+ Addr: c.socksAddr,
BindIP: "127.0.0.1",
- Dial: dialer.Dial,
}
- fmt.Printf("[+] Starting socks5 proxy at %s\n", socksAddr)
+ 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 {
- panic(err)
+ log.Printf("error while listening: %v\n", err)
+ return false
}
+ return true
}