1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-11-23 12:02:58 -05:00

support udp redirection

This commit is contained in:
v2ray
2016-08-15 17:44:46 +02:00
parent 956b47f6ae
commit 210a32dc12
9 changed files with 132 additions and 39 deletions

View File

@@ -90,7 +90,7 @@ func (this *DokodemoDoor) Start() error {
func (this *DokodemoDoor) ListenUDP() error {
this.udpServer = udp.NewUDPServer(this.meta, this.packetDispatcher)
udpHub, err := udp.ListenUDP(this.meta.Address, this.meta.Port, this.handleUDPPackets)
udpHub, err := udp.ListenUDP(this.meta.Address, this.meta.Port, udp.ListenOption{Callback: this.handleUDPPackets})
if err != nil {
log.Error("Dokodemo failed to listen on ", this.meta.Address, ":", this.meta.Port, ": ", err)
return err
@@ -101,9 +101,15 @@ func (this *DokodemoDoor) ListenUDP() error {
return nil
}
func (this *DokodemoDoor) handleUDPPackets(payload *alloc.Buffer, dest v2net.Destination) {
this.udpServer.Dispatch(
&proxy.SessionInfo{Source: dest, Destination: v2net.UDPDestination(this.address, this.port)}, payload, this.handleUDPResponse)
func (this *DokodemoDoor) handleUDPPackets(payload *alloc.Buffer, session *proxy.SessionInfo) {
if session.Destination == nil && this.address != nil && this.port > 0 {
session.Destination = v2net.UDPDestination(this.address, this.port)
}
if session.Destination == nil {
log.Info("Dokodemo: Unknown destination, stop forwarding...")
return
}
this.udpServer.Dispatch(session, payload, this.handleUDPResponse)
}
func (this *DokodemoDoor) handleUDPResponse(dest v2net.Destination, payload *alloc.Buffer) {