Merge pull request #170 from xiaokangwang/kcptransport

Add KCP(UDPSession) as a transport for v2ray, reslove #162
This commit is contained in:
Darien Raymond
2016-06-13 16:35:57 +02:00
committed by GitHub
13 changed files with 450 additions and 8 deletions
+4
View File
@@ -18,11 +18,15 @@ type InboundHandlerMeta struct {
Tag string
Address v2net.Address
Port v2net.Port
//Whether this proxy support KCP connections
KcpSupported bool
}
type OutboundHandlerMeta struct {
Tag string
Address v2net.Address
//Whether this proxy support KCP connections
KcpSupported bool
}
// An InboundHandler handles inbound network connections to V2Ray.
+6 -2
View File
@@ -106,7 +106,7 @@ func (this *VMessInboundHandler) Start() error {
return nil
}
tcpListener, err := hub.ListenTCP(this.meta.Address, this.meta.Port, this.HandleConnection, nil)
tcpListener, err := hub.ListenTCP6(this.meta.Address, this.meta.Port, this.HandleConnection, this.meta, nil)
if err != nil {
log.Error("Unable to listen tcp ", this.meta.Address, ":", this.meta.Port, ": ", err)
return err
@@ -220,7 +220,9 @@ func (this *VMessInboundHandler) HandleConnection(connection *hub.Connection) {
readFinish.Lock()
}
func (this *VMessInboundHandler) setProxyCap() {
this.meta.KcpSupported = true
}
func init() {
internal.MustRegisterInboundHandlerCreator("vmess",
func(space app.Space, rawConfig interface{}, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error) {
@@ -246,6 +248,8 @@ func init() {
handler.inboundHandlerManager = space.GetApp(proxyman.APP_ID_INBOUND_MANAGER).(proxyman.InboundHandlerManager)
}
handler.setProxyCap()
return handler, nil
})
}
+11 -4
View File
@@ -34,7 +34,7 @@ func (this *VMessOutboundHandler) Dispatch(target v2net.Destination, payload *al
err := retry.Timed(5, 100).On(func() error {
rec = this.receiverManager.PickReceiver()
rawConn, err := hub.Dial(this.meta.Address, rec.Destination)
rawConn, err := hub.Dial3(this.meta.Address, rec.Destination, this.meta)
if err != nil {
return err
}
@@ -154,14 +154,21 @@ func (this *VMessOutboundHandler) handleResponse(session *raw.ClientSession, con
return
}
func (this *VMessOutboundHandler) setProxyCap() {
this.meta.KcpSupported = true
}
func init() {
internal.MustRegisterOutboundHandlerCreator("vmess",
func(space app.Space, rawConfig interface{}, meta *proxy.OutboundHandlerMeta) (proxy.OutboundHandler, error) {
vOutConfig := rawConfig.(*Config)
return &VMessOutboundHandler{
handler := &VMessOutboundHandler{
receiverManager: NewReceiverManager(vOutConfig.Receivers),
meta: meta,
}, nil
}
handler.setProxyCap()
return handler, nil
})
}