Exemplo n.º 1
0
func (sp *shadowsocksParent) connect(url *URL) (conn, error) {
	c, err := ss.Dial(url.HostPort, sp.server, sp.cipher.Copy())
	if err != nil {
		errl.Printf("can't create shadowsocks connection for: %s %v\n", url.HostPort, err)
		return zeroConn, err
	}
	debug.Println("connected to:", url.HostPort, "via shadowsocks:", sp.server)
	return conn{ctShadowctSocksConn, c, sp}, nil
}
Exemplo n.º 2
0
func init() {

	proxyTransports["http"] = func(proxyURL *url.URL) (*http.Transport, error) {
		return &http.Transport{
			Proxy: func(req *http.Request) (*url.URL, error) {
				return proxyURL, nil
			},
		}, nil
	}

	proxyTransports["socks5"] = func(proxyURL *url.URL) (*http.Transport, error) {
		ph, err := proxy.FromURL(proxyURL, proxy.Direct)
		if err != nil {
			return nil, err
		}
		return &http.Transport{
			Dial: ph.Dial,
		}, nil
	}

	proxyTransports["socks4"] = func(proxyURL *url.URL) (*http.Transport, error) {
		dialSocksProxy := socks.DialSocksProxy(socks.SOCKS4A, proxyURL.Host)
		return &http.Transport{
			Dial: dialSocksProxy,
		}, nil
	}

	proxyTransports["socks4a"] = func(proxyURL *url.URL) (*http.Transport, error) {
		dialSocksProxy := socks.DialSocksProxy(socks.SOCKS4A, proxyURL.Host)
		return &http.Transport{
			Dial: dialSocksProxy,
		}, nil
	}

	//shadowsocks
	proxyTransports["ss"] = func(proxyURL *url.URL) (*http.Transport, error) {
		if proxyURL.User == nil {
			return nil, fmt.Errorf("wrong shadowsocks uri,need method and passwd")
		}
		psw, _ := proxyURL.User.Password()
		cipher, err := ss.NewCipher(proxyURL.User.Username(), psw)
		if err != nil {
			return nil, err
		}
		serverAddr := proxyURL.Host
		return &http.Transport{
			Dial: func(_, addr string) (net.Conn, error) {
				return ss.Dial(addr, serverAddr, cipher.Copy())
			},
			//			DialTLS:func(_, addr string) (net.Conn, error) {
			//				return ss.Dial(addr, serverAddr, cipher.Copy())
			//			},
		}, nil
	}

}
Exemplo n.º 3
0
func (sp *shadowsocksParent) connect(url *URL) (net.Conn, error) {
	c, err := ss.Dial(url.HostPort, sp.server, sp.cipher.Copy())
	if err != nil {
		errl.Printf("create shadowsocks connection to %s through server %s failed %v\n",
			url.HostPort, sp.server, err)
		return nil, err
	}
	debug.Println("connected to:", url.HostPort, "via shadowsocks:", sp.server)
	return shadowsocksConn{c, sp}, nil
}
Exemplo n.º 4
0
func (sp *shadowsocksParent) connect(url *URL) (net.Conn, error) {
	c, err := ss.Dial(url.HostPort, sp.server, sp.cipher.Copy())
	if err != nil {
		errl.Printf("can't connect to shadowsocks parent %s for %s: %v\n",
			sp.server, url.HostPort, err)
		return nil, err
	}
	debug.Println("connected to:", url.HostPort, "via shadowsocks:", sp.server)
	return shadowsocksConn{c, sp}, nil
}
Exemplo n.º 5
0
func (s *SSDialer) Dial(network, addr string) (c net.Conn, err error) {
	cipher, err := ss.NewCipher(s.Method, s.Password)
	if err != nil {
		return nil, err
	}
	ssConn, err := ss.Dial(addr, s.Host, cipher)
	if err != nil {
		return nil, err
	}
	return ssConn, nil
}
Exemplo n.º 6
0
func createShadowSocksConnection(url *URL) (cn conn, err error) {
	if len(config.ShadowSocks) == 0 {
		return zeroConn, noShadowSocksErr
	}
	c, err := ss.Dial(url.HostPort, config.ShadowSocks, cipher.Copy())
	if err != nil {
		errl.Printf("Can't create shadowsocks connection for: %s %v\n", url.HostPort, err)
		return zeroConn, err
	}
	// debug.Println("shadowsocks connection created to:", hostFull)
	return conn{c, ctShadowctSocksConn}, nil
}
Exemplo n.º 7
0
// Create shadowsocks connection function which uses the ith shadowsocks server
func createShadowSocksConnecter(i int) parentProxyConnectionFunc {
	f := func(url *URL) (cn conn, err error) {
		c, err := ss.Dial(url.HostPort, config.ShadowSocks[i], cipher[i].Copy())
		if err != nil {
			errl.Printf("Can't create shadowsocks connection for: %s %v\n", url.HostPort, err)
			return zeroConn, err
		}
		debug.Println("shadowsocks connection created to:", url.HostPort)
		return conn{c, ctShadowctSocksConn}, nil
	}
	return f
}
Exemplo n.º 8
0
func createShadowSocksConnection(hostFull string) (cn conn, err error) {
	if !hasShadowSocksServer {
		return zeroConn, noShadowSocksErr
	}
	c, err := ss.Dial(hostFull, config.ShadowSocks, encTbl)
	if err != nil {
		debug.Printf("Can't create shadowsocks connection for: %s %v\n", hostFull, err)
		return zeroConn, err
	}
	// debug.Println("shadowsocks connection created to:", hostFull)
	return conn{c, ctShadowctSocksConn}, nil
}