mirror of https://github.com/v2ray/v2ray-core
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.
30 lines
757 B
30 lines
757 B
package kcp
|
|
|
|
import (
|
|
"net"
|
|
|
|
"github.com/v2ray/v2ray-core/common/dice"
|
|
"github.com/v2ray/v2ray-core/common/log"
|
|
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) {
|
|
udpDest := v2net.UDPDestination(dest.Address(), dest.Port())
|
|
log.Info("Dialling KCP to ", udpDest)
|
|
conn, err := internet.DialToDest(src, udpDest)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
cpip := NewSimpleAuthenticator()
|
|
session := NewConnection(uint16(dice.Roll(65536)), conn, conn.LocalAddr().(*net.UDPAddr), conn.RemoteAddr().(*net.UDPAddr), cpip)
|
|
session.FetchInputFrom(conn)
|
|
|
|
return session, nil
|
|
}
|
|
|
|
func init() {
|
|
internet.KCPDialer = DialKCP
|
|
}
|