From 823cb0ae2393db4186905226145e9791b202f0eb Mon Sep 17 00:00:00 2001 From: cyBerta Date: Mon, 30 May 2022 15:51:49 +0200 Subject: draft stop method --- client/client.go | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'client') diff --git a/client/client.go b/client/client.go index d9cfb2a..2de8076 100644 --- a/client/client.go +++ b/client/client.go @@ -18,6 +18,7 @@ type Client struct { kcp bool socksAddr string obfs4Cert string + server *socks5.Server } func NewClient(kcp bool, socksAddr, obfs4Cert string) *Client { @@ -29,7 +30,12 @@ func NewClient(kcp bool, socksAddr, obfs4Cert string) *Client { } func (c *Client) Start() bool { - server := &socks5.Server{ + 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", } @@ -47,12 +53,29 @@ func (c *Client) Start() bool { } } - server.Dial = dialer.Dial + c.server.Dial = dialer.Dial fmt.Printf("[+] Starting socks5 proxy at %s\n", c.socksAddr) - if err := server.ListenAndServe(); err != nil { + 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 +} \ No newline at end of file -- cgit v1.2.3