summaryrefslogtreecommitdiff
path: root/client/client.go
diff options
context:
space:
mode:
Diffstat (limited to 'client/client.go')
-rw-r--r--client/client.go29
1 files changed, 26 insertions, 3 deletions
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