diff --git a/transport/hub/kcp.go b/transport/hub/kcp.go index aa5ed603b..8d0fc00aa 100644 --- a/transport/hub/kcp.go +++ b/transport/hub/kcp.go @@ -6,6 +6,7 @@ import ( "time" "github.com/v2ray/v2ray-core/common/log" + "github.com/v2ray/v2ray-core/transport" "github.com/v2ray/v2ray-core/transport/hub/kcpv" "github.com/xtaci/kcp-go" ) @@ -109,3 +110,19 @@ func (kcpvc *KCPVconn) SetReadDeadline(t time.Time) error { func (kcpvc *KCPVconn) SetWriteDeadline(t time.Time) error { return kcpvc.hc.SetWriteDeadline(t) } + +func DialKCP(dest v2net.Destination) (*KCPVconn, error) { + kcpconf := transport.KcpConfig + cpip, _ := kcpv.GetChipher(kcpconf.Key) + kcv, err := kcp.DialWithOptions(kcpconf.AdvancedConfigs.Fec, dest.NetAddr(), cpip) + if err != nil { + return nil, err + } + kcvn := &KCPVconn{hc: kcv} + kcvn.conf = kcpconf + err = kcvn.ApplyConf() + if err != nil { + return nil, err + } + return kcvn, nil +}