1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-20 03:16:24 -05:00
v2fly/transport/internet/kcp/dialer.go
2016-06-17 16:51:41 +02:00

35 lines
805 B
Go

package kcp
import (
"errors"
"math/rand"
"net"
"github.com/v2ray/v2ray-core/common/log"
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/transport/internet"
)
var (
ErrUnknownDestination = errors.New("Destination IP can't be resolved.")
)
func DialKCP(src v2net.Address, dest v2net.Destination) (internet.Connection, error) {
log.Info("Dialling KCP to ", dest)
udpDest := v2net.UDPDestination(dest.Address(), dest.Port())
conn, err := internet.DialToDest(src, udpDest)
if err != nil {
return nil, err
}
cpip := NewSimpleAuthenticator()
session := newUDPSession(rand.Uint32(), conn, conn.LocalAddr().(*net.UDPAddr), conn.RemoteAddr().(*net.UDPAddr), cpip)
session.FetchInputFrom(conn)
return session, nil
}
func init() {
internet.KCPDialer = DialKCP
}