forked from ccsexyz/shadowsocks-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssproxy.go
50 lines (46 loc) · 1.03 KB
/
ssproxy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"net"
ss "github.com/ccsexyz/shadowsocks-go/shadowsocks"
)
func RunSSProxyServer(c *ss.Config) {
RunTCPServer(c.Localaddr, c, ss.ListenSS, ssproxyHandler)
}
func ssproxyHandler(conn net.Conn, c *ss.Config) {
defer conn.Close()
C, err := ss.GetSsConn(conn)
if err != nil {
return
}
dst, err := ss.GetDstConn(conn)
if err != nil {
return
}
target := dst.GetDst()
if len(target) == 0 {
c.LogD("target length is 0")
return
}
rconn, err := ss.DialMultiSS(target, c.Backends)
if err != nil {
return
}
defer rconn.Close()
C.Xu0s() // FIXME
c.Log("proxy", target, "to", rconn.RemoteAddr().String(), "from", conn.RemoteAddr().String())
// lim, err := ss.GetLimitConn(conn)
// if err == nil {
// defer func() {
// for _, v := range lim.Rlimiters {
// c.Log("read", v.GetTotalBytes(), "bytes")
// }
// for _, v := range lim.Wlimiters {
// c.Log("write", v.GetTotalBytes(), "bytes")
// }
// }()
// }
if c.LogHTTP {
conn = ss.NewHttpLogConn(conn, c)
}
ss.Pipe(conn, rconn, c)
}