From 3e05a3529a09a78fff2d1d7bae054c013676e671 Mon Sep 17 00:00:00 2001 From: Shelikhoo Date: Sun, 18 Mar 2018 22:08:03 +0800 Subject: [PATCH] finish UnixInboundHandler --- app/proxyman/inbound/unix.go | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/app/proxyman/inbound/unix.go b/app/proxyman/inbound/unix.go index 2b38c484..291dadbf 100644 --- a/app/proxyman/inbound/unix.go +++ b/app/proxyman/inbound/unix.go @@ -26,7 +26,33 @@ func (uih *UnixInboundHandler) Start() { if err != nil { newError(err).AtError().WriteToLog() } - + err = uih.listenerHolder.LowerUP() + if err != nil { + newError(err).AtError().WriteToLog() + } + nchan := make(chan net.Conn, 2) + err = uih.listenerHolder.UP(nchan, false) + if err != nil { + newError(err).AtError().WriteToLog() + } + go uih.progressTraffic(nchan) + return +} +func (uih *UnixInboundHandler) progressTraffic(rece <-chan net.Conn) { + for { + conn := <-rece + go func(conn net.Conn) { + ctx, cancel := context.WithCancel(uih.ctx) + if len(uih.tag) > 0 { + ctx = proxy.ContextWithInboundTag(ctx, uih.tag) + } + if err := uih.proxy.Process(ctx, net.Network_TCP, conn, uih.mux); err != nil { + newError("connection ends").Base(err).WriteToLog() + } + cancel() + conn.Close() + }(conn) + } } func (uih *UnixInboundHandler) Close() { if uih.listenerHolder != nil {