Ejemplo n.º 1
0
func init() {
	internet.UDPDialer = func(src v2net.Address, dest v2net.Destination) (internet.Connection, error) {
		conn, err := internet.DialToDest(src, dest)
		if err != nil {
			return nil, err
		}
		return &Connection{
			UDPConn: *(conn.(*net.UDPConn)),
		}, nil
	}
}
Ejemplo n.º 2
0
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()
	conv := uint16(atomic.AddUint32(&globalConv, 1))
	session := NewConnection(conv, conn, conn.LocalAddr().(*net.UDPAddr), conn.RemoteAddr().(*net.UDPAddr), cpip)
	session.FetchInputFrom(conn)

	return session, nil
}