You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
v2ray-core/transport/internet/dialer.go

62 lines
1.4 KiB

package internet
import (
"net"
8 years ago
"v2ray.com/core/common/errors"
8 years ago
"v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net"
)
var (
ErrUnsupportedStreamType = errors.New("Unsupported stream type.")
)
type DialerOptions struct {
Stream *StreamConfig
Proxy *ProxyConfig
}
type Dialer func(src v2net.Address, dest v2net.Destination, options DialerOptions) (Connection, error)
var (
8 years ago
TCPDialer Dialer
KCPDialer Dialer
UDPDialer Dialer
WSDialer Dialer
ProxyDialer Dialer
)
8 years ago
func Dial(src v2net.Address, dest v2net.Destination, options DialerOptions) (Connection, error) {
if options.Proxy.HasTag() && ProxyDialer != nil {
8 years ago
log.Info("Internet: Proxying outbound connection through: ", options.Proxy.Tag)
8 years ago
return ProxyDialer(src, dest, options)
}
8 years ago
var connection Connection
var err error
if dest.Network == v2net.Network_TCP {
8 years ago
switch options.Stream.Network {
case v2net.Network_TCP:
8 years ago
connection, err = TCPDialer(src, dest, options)
case v2net.Network_KCP:
8 years ago
connection, err = KCPDialer(src, dest, options)
case v2net.Network_WebSocket:
8 years ago
connection, err = WSDialer(src, dest, options)
8 years ago
default:
return nil, ErrUnsupportedStreamType
}
8 years ago
if err != nil {
return nil, err
}
return connection, nil
}
8 years ago
return UDPDialer(src, dest, options)
}
func DialToDest(src v2net.Address, dest v2net.Destination) (net.Conn, error) {
return effectiveSystemDialer.Dial(src, dest)
}