forked from mellow-io/go-tun2socks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_shadowsocks.go
39 lines (31 loc) · 1.34 KB
/
main_shadowsocks.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
// +build shadowsocks
package main
import (
"flag"
"net"
"strings"
sscore "github.com/shadowsocks/go-shadowsocks2/core"
"github.com/eycorsican/go-tun2socks/common/log"
"github.com/eycorsican/go-tun2socks/core"
"github.com/eycorsican/go-tun2socks/proxy/shadowsocks"
)
func init() {
args.addFlag(fProxyServer)
args.addFlag(fUdpTimeout)
args.ProxyCipher = flag.String("proxyCipher", "AEAD_CHACHA20_POLY1305", "Cipher used for Shadowsocks proxy, available ciphers: "+strings.Join(sscore.ListCipher(), " "))
args.ProxyPassword = flag.String("proxyPassword", "", "Password used for Shadowsocks proxy")
registerHandlerCreater("shadowsocks", func() {
// Verify proxy server address.
proxyAddr, err := net.ResolveTCPAddr("tcp", *args.ProxyServer)
if err != nil {
log.Fatalf("invalid proxy server address: %v", err)
}
proxyHost := proxyAddr.IP.String()
proxyPort := uint16(proxyAddr.Port)
if *args.ProxyCipher == "" || *args.ProxyPassword == "" {
log.Fatalf("invalid cipher or password")
}
core.RegisterTCPConnHandler(shadowsocks.NewTCPHandler(core.ParseTCPAddr(proxyHost, proxyPort).String(), *args.ProxyCipher, *args.ProxyPassword, fakeDns))
core.RegisterUDPConnHandler(shadowsocks.NewUDPHandler(core.ParseUDPAddr(proxyHost, proxyPort).String(), *args.ProxyCipher, *args.ProxyPassword, *args.UdpTimeout, dnsCache, fakeDns))
})
}