diff --git a/proxy/dokodemo/dokodemo.go b/proxy/dokodemo/dokodemo.go index 609a453e..cf382fcf 100644 --- a/proxy/dokodemo/dokodemo.go +++ b/proxy/dokodemo/dokodemo.go @@ -92,13 +92,7 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in requestDone := func() error { defer timer.SetTimeout(plcy.Timeouts.DownlinkOnly) - var reader buf.Reader - if plcy.Buffer.PerConnection == 0 { - reader = &buf.SingleReader{Reader: conn} - } else { - reader = buf.NewReader(conn) - } - + reader := buf.NewReader(conn) if err := buf.Copy(reader, link.Writer, buf.UpdateActivity(timer)); err != nil { return newError("failed to transport request").Base(err) } diff --git a/proxy/freedom/freedom.go b/proxy/freedom/freedom.go index e5a44989..7f1044e9 100644 --- a/proxy/freedom/freedom.go +++ b/proxy/freedom/freedom.go @@ -141,13 +141,7 @@ func (h *Handler) Process(ctx context.Context, link *core.Link, dialer proxy.Dia responseDone := func() error { defer timer.SetTimeout(plcy.Timeouts.UplinkOnly) - var reader buf.Reader - if plcy.Buffer.PerConnection == 0 { - reader = &buf.SingleReader{Reader: conn} - } else { - reader = buf.NewReader(conn) - } - if err := buf.Copy(reader, output, buf.UpdateActivity(timer)); err != nil { + if err := buf.Copy(buf.NewReader(conn), output, buf.UpdateActivity(timer)); err != nil { return newError("failed to process response").Base(err) } diff --git a/proxy/http/server.go b/proxy/http/server.go index ad2938bf..a3e1e77d 100755 --- a/proxy/http/server.go +++ b/proxy/http/server.go @@ -196,13 +196,7 @@ func (s *Server) handleConnect(ctx context.Context, request *http.Request, reade requestDone := func() error { defer timer.SetTimeout(plcy.Timeouts.DownlinkOnly) - var reader buf.Reader - if plcy.Buffer.PerConnection == 0 { - reader = &buf.SingleReader{Reader: conn} - } else { - reader = buf.NewReader(conn) - } - return buf.Copy(reader, link.Writer, buf.UpdateActivity(timer)) + return buf.Copy(buf.NewReader(conn), link.Writer, buf.UpdateActivity(timer)) } responseDone := func() error { diff --git a/proxy/shadowsocks/server.go b/proxy/shadowsocks/server.go index 0c390b06..401f188e 100644 --- a/proxy/shadowsocks/server.go +++ b/proxy/shadowsocks/server.go @@ -149,16 +149,7 @@ func (s *Server) handleConnection(ctx context.Context, conn internet.Connection, sessionPolicy := s.v.PolicyManager().ForLevel(s.user.Level) conn.SetReadDeadline(time.Now().Add(sessionPolicy.Timeouts.Handshake)) - var bufferedReader buf.BufferedReader - { - var reader buf.Reader - if sessionPolicy.Buffer.PerConnection == 0 { - reader = &buf.SingleReader{Reader: conn} - } else { - reader = buf.NewReader(conn) - } - bufferedReader = buf.BufferedReader{Reader: reader} - } + bufferedReader := buf.BufferedReader{Reader: buf.NewReader(conn)} request, bodyReader, err := ReadTCPSession(s.user, &bufferedReader) if err != nil { log.Record(&log.AccessMessage{ diff --git a/proxy/socks/client.go b/proxy/socks/client.go index 97169a97..e837b53c 100644 --- a/proxy/socks/client.go +++ b/proxy/socks/client.go @@ -113,13 +113,7 @@ func (c *Client) Process(ctx context.Context, link *core.Link, dialer proxy.Dial } responseFunc = func() error { defer timer.SetTimeout(p.Timeouts.UplinkOnly) - var reader buf.Reader - if p.Buffer.PerConnection == 0 { - reader = &buf.SingleReader{Reader: conn} - } else { - reader = buf.NewReader(conn) - } - return buf.Copy(reader, link.Writer, buf.UpdateActivity(timer)) + return buf.Copy(buf.NewReader(conn), link.Writer, buf.UpdateActivity(timer)) } } else if request.Command == protocol.RequestCommandUDP { udpConn, err := dialer.Dial(ctx, udpRequest.Destination()) diff --git a/proxy/socks/server.go b/proxy/socks/server.go index 794c5fb3..bb5d1f66 100644 --- a/proxy/socks/server.go +++ b/proxy/socks/server.go @@ -73,17 +73,6 @@ func (s *Server) processTCP(ctx context.Context, conn internet.Connection, dispa newError("failed to set deadline").Base(err).WriteToLog(session.ExportIDToError(ctx)) } - var reader *buf.BufferedReader - { - var r buf.Reader - if plcy.Buffer.PerConnection == 0 { - r = &buf.SingleReader{Reader: conn} - } else { - r = buf.NewReader(conn) - } - reader = &buf.BufferedReader{Reader: r} - } - inboundDest, ok := proxy.InboundEntryPointFromContext(ctx) if !ok { return newError("inbound entry point not specified") @@ -93,6 +82,7 @@ func (s *Server) processTCP(ctx context.Context, conn internet.Connection, dispa port: inboundDest.Port, } + reader := &buf.BufferedReader{Reader: buf.NewReader(conn)} request, err := svrSession.Handshake(reader, conn) if err != nil { if source, ok := proxy.SourceFromContext(ctx); ok { diff --git a/proxy/vmess/inbound/inbound.go b/proxy/vmess/inbound/inbound.go index 0065219a..e3220f35 100644 --- a/proxy/vmess/inbound/inbound.go +++ b/proxy/vmess/inbound/inbound.go @@ -224,7 +224,7 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection i return newError("unable to set read deadline").Base(err).AtWarning() } - reader := &buf.BufferedReader{Reader: &buf.SingleReader{Reader: connection}} + reader := &buf.BufferedReader{Reader: buf.NewReader(connection)} svrSession := encoding.NewServerSession(h.clients, h.sessionHistory) request, err := svrSession.DecodeRequestHeader(reader) @@ -280,9 +280,6 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection i requestDone := func() error { defer timer.SetTimeout(sessionPolicy.Timeouts.DownlinkOnly) - if sessionPolicy.Buffer.PerConnection > 0 { - reader.Reader = buf.NewReader(connection) - } return transferRequest(timer, svrSession, request, reader, link.Writer) } diff --git a/proxy/vmess/outbound/outbound.go b/proxy/vmess/outbound/outbound.go index 1612f703..ce6bd773 100644 --- a/proxy/vmess/outbound/outbound.go +++ b/proxy/vmess/outbound/outbound.go @@ -144,16 +144,7 @@ func (v *Handler) Process(ctx context.Context, link *core.Link, dialer proxy.Dia responseDone := func() error { defer timer.SetTimeout(sessionPolicy.Timeouts.UplinkOnly) - var reader *buf.BufferedReader - { - var r buf.Reader - if sessionPolicy.Buffer.PerConnection == 0 { - r = &buf.SingleReader{Reader: conn} - } else { - r = buf.NewReader(conn) - } - reader = &buf.BufferedReader{Reader: r} - } + reader := &buf.BufferedReader{Reader: buf.NewReader(conn)} header, err := session.DecodeResponseHeader(reader) if err != nil { return newError("failed to read header").Base(err)