mirror of
https://github.com/wweir/sower.git
synced 2024-04-21 12:42:15 +00:00
35 lines
688 B
Go
35 lines
688 B
Go
package transport
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"net"
|
|
"strconv"
|
|
)
|
|
|
|
func Dial(address, target string, password []byte) (net.Conn, error) {
|
|
if addr, ok := IsSocks5Schema(address); ok {
|
|
conn, err := net.Dial("tcp", addr)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if conn, err = ToSocks5(conn, target); err != nil {
|
|
conn.Close()
|
|
return nil, err
|
|
}
|
|
return conn, nil
|
|
}
|
|
|
|
host, port, err := net.SplitHostPort(target)
|
|
if err != nil {
|
|
port = "443"
|
|
}
|
|
p, err := strconv.Atoi(port)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// tls.Config is same as golang http pkg default behavior
|
|
return DialTlsProxyConn(net.JoinHostPort(address, "443"),
|
|
host, uint16(p), &tls.Config{}, password)
|
|
}
|