forked from v2fly/v2ray-core
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dialer.go
34 lines (27 loc) · 805 Bytes
/
dialer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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 := NewConnection(rand.Uint32(), conn, conn.LocalAddr().(*net.UDPAddr), conn.RemoteAddr().(*net.UDPAddr), cpip)
session.FetchInputFrom(conn)
return session, nil
}
func init() {
internet.KCPDialer = DialKCP
}