From 557f411f85773f72af31b8ebb672150560f42cff Mon Sep 17 00:00:00 2001 From: V2Ray Date: Sun, 4 Oct 2015 00:58:07 +0200 Subject: [PATCH] Update freedom connection for UDP --- proxy/freedom/freedom.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/proxy/freedom/freedom.go b/proxy/freedom/freedom.go index 691510f27..cc64366fa 100644 --- a/proxy/freedom/freedom.go +++ b/proxy/freedom/freedom.go @@ -48,7 +48,7 @@ func (vconn *FreedomConnection) Start(ray core.OutboundRay) error { go dumpInput(conn, input, &writeMutex) } - go dumpOutput(conn, output, &readMutex) + go dumpOutput(conn, output, &readMutex, vconn.packet.Destination().IsUDP()) go func() { writeMutex.Lock() @@ -67,8 +67,20 @@ func dumpInput(conn net.Conn, input <-chan []byte, finish *sync.Mutex) { finish.Unlock() } -func dumpOutput(conn net.Conn, output chan<- []byte, finish *sync.Mutex) { +func dumpOutput(conn net.Conn, output chan<- []byte, finish *sync.Mutex, udp bool) { + defer finish.Unlock() + defer close(output) + + response, err := v2net.ReadFrom(conn) + if len(response) > 0 { + output <- response + } + if err != nil { + return + } + if udp { + return + } + v2net.ReaderToChan(output, conn) - finish.Unlock() - close(output) }