Example #1
0
func BuildUpstream(upstream azber.Upstream, forward proxy.Dialer) (proxy.Dialer, error) {
	cipherDecorator := azber.NewCipherConnDecorator(upstream.Crypto, upstream.Password)
	forward = azber.NewDecorateClient(forward, cipherDecorator)

	switch strings.ToLower(upstream.Type) {
	case "socks5":
		{
			return azber.NewSocks5Client("tcp", upstream.Address, "", "", forward)
		}
	case "shadowsocks":
		{
			return azber.NewShadowsocksClient("tcp", upstream.Address, forward)
		}
	}
	return nil, errors.New("unknown upstream type" + upstream.Type)
}
Example #2
0
func runSOCKS5Server(forward proxy.Dialer) {
	listener, err := net.Listen("tcp", ":7777")
	if err != nil {
		log.Println("net.Listen failed, err:", err, ":7777")
		return
	}
	cipherDecorator := azber.NewCipherConnDecorator("aes-256-cfb", "1234567890")
	listener = azber.NewDecorateListener(listener, cipherDecorator)
	socks5Svr, err := azber.NewSocks5Server(forward)
	if err != nil {
		listener.Close()
		log.Println("socks.NewSocks5Server failed, err:", err)
		return
	}
	go func() {
		defer listener.Close()
		socks5Svr.Serve(listener)
	}()
}