func (w *tcpWorker) callback(conn internet.Connection) { ctx, cancel := context.WithCancel(w.ctx) if w.recvOrigDest { dest := tcp.GetOriginalDestination(conn) if dest.IsValid() { ctx = proxy.ContextWithOriginalDestination(ctx, dest) } } if len(w.tag) > 0 { ctx = proxy.ContextWithInboundTag(ctx, w.tag) } ctx = proxy.ContextWithAllowPassiveConnection(ctx, w.allowPassiveConn) ctx = proxy.ContextWithInboundDestination(ctx, v2net.TCPDestination(w.address, w.port)) w.proxy.Process(ctx, v2net.Network_TCP, conn) cancel() conn.Close() }
func (w *udpWorker) callback(b *buf.Buffer, source v2net.Destination, originalDest v2net.Destination) { conn, existing := w.getConnection(source) conn.input <- b.Bytes() if !existing { go func() { ctx := w.ctx ctx, cancel := context.WithCancel(ctx) conn.cancel = cancel if originalDest.IsValid() { ctx = proxy.ContextWithOriginalDestination(ctx, originalDest) } if len(w.tag) > 0 { ctx = proxy.ContextWithInboundTag(ctx, w.tag) } ctx = proxy.ContextWithSource(ctx, source) ctx = proxy.ContextWithInboundDestination(ctx, v2net.UDPDestination(w.address, w.port)) w.proxy.Process(ctx, v2net.Network_UDP, conn) w.removeConn(source) cancel() }() } }