KCP: Added Dial func

pull/170/head
Shelikhoo 2016-06-12 12:25:51 +08:00
parent e84d52263d
commit 2fd963801c
No known key found for this signature in database
GPG Key ID: 7791BDB0709ABD21
1 changed files with 17 additions and 0 deletions

View File

@ -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
}