1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-10-29 15:27:32 -04:00
v2fly/transport/internet/kcp/dialer.go

35 lines
805 B
Go
Raw Normal View History

2016-06-14 16:54:08 -04:00
package kcp
import (
2016-06-14 18:30:11 -04:00
"errors"
"math/rand"
"net"
2016-06-17 10:51:41 -04:00
"github.com/v2ray/v2ray-core/common/log"
2016-06-14 16:54:08 -04:00
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/transport/internet"
)
2016-06-14 18:30:11 -04:00
var (
ErrUnknownDestination = errors.New("Destination IP can't be resolved.")
)
2016-06-14 16:54:08 -04:00
func DialKCP(src v2net.Address, dest v2net.Destination) (internet.Connection, error) {
2016-06-17 10:51:41 -04:00
log.Info("Dialling KCP to ", dest)
udpDest := v2net.UDPDestination(dest.Address(), dest.Port())
conn, err := internet.DialToDest(src, udpDest)
2016-06-14 16:54:08 -04:00
if err != nil {
return nil, err
}
2016-06-14 18:30:11 -04:00
2016-06-17 10:51:41 -04:00
cpip := NewSimpleAuthenticator()
2016-06-18 10:34:04 -04:00
session := NewConnection(rand.Uint32(), conn, conn.LocalAddr().(*net.UDPAddr), conn.RemoteAddr().(*net.UDPAddr), cpip)
2016-06-17 10:51:41 -04:00
session.FetchInputFrom(conn)
return session, nil
2016-06-14 16:54:08 -04:00
}
func init() {
internet.KCPDialer = DialKCP
}