v2fly/transport/internet/kcp/dialer.go

30 lines
757 B
Go
Raw Normal View History

2016-06-14 20:54:08 +00:00
package kcp
import (
2016-06-14 22:30:11 +00:00
"net"
2016-06-29 21:53:50 +00:00
"github.com/v2ray/v2ray-core/common/dice"
2016-06-17 14:51:41 +00:00
"github.com/v2ray/v2ray-core/common/log"
2016-06-14 20:54:08 +00:00
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/transport/internet"
)
func DialKCP(src v2net.Address, dest v2net.Destination) (internet.Connection, error) {
2016-06-17 14:51:41 +00:00
udpDest := v2net.UDPDestination(dest.Address(), dest.Port())
2016-06-27 06:38:02 +00:00
log.Info("Dialling KCP to ", udpDest)
2016-06-17 14:51:41 +00:00
conn, err := internet.DialToDest(src, udpDest)
2016-06-14 20:54:08 +00:00
if err != nil {
return nil, err
}
2016-06-14 22:30:11 +00:00
2016-06-17 14:51:41 +00:00
cpip := NewSimpleAuthenticator()
2016-06-29 21:53:50 +00:00
session := NewConnection(uint16(dice.Roll(65536)), conn, conn.LocalAddr().(*net.UDPAddr), conn.RemoteAddr().(*net.UDPAddr), cpip)
2016-06-17 14:51:41 +00:00
session.FetchInputFrom(conn)
return session, nil
2016-06-14 20:54:08 +00:00
}
func init() {
internet.KCPDialer = DialKCP
}