mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-30 05:56:54 -05:00
revert reader creation based on per-connection buffer
This commit is contained in:
parent
2e11653694
commit
57966adf49
@ -92,13 +92,7 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
|
|||||||
requestDone := func() error {
|
requestDone := func() error {
|
||||||
defer timer.SetTimeout(plcy.Timeouts.DownlinkOnly)
|
defer timer.SetTimeout(plcy.Timeouts.DownlinkOnly)
|
||||||
|
|
||||||
var reader buf.Reader
|
reader := buf.NewReader(conn)
|
||||||
if plcy.Buffer.PerConnection == 0 {
|
|
||||||
reader = &buf.SingleReader{Reader: conn}
|
|
||||||
} else {
|
|
||||||
reader = buf.NewReader(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := buf.Copy(reader, link.Writer, buf.UpdateActivity(timer)); err != nil {
|
if err := buf.Copy(reader, link.Writer, buf.UpdateActivity(timer)); err != nil {
|
||||||
return newError("failed to transport request").Base(err)
|
return newError("failed to transport request").Base(err)
|
||||||
}
|
}
|
||||||
|
@ -141,13 +141,7 @@ func (h *Handler) Process(ctx context.Context, link *core.Link, dialer proxy.Dia
|
|||||||
responseDone := func() error {
|
responseDone := func() error {
|
||||||
defer timer.SetTimeout(plcy.Timeouts.UplinkOnly)
|
defer timer.SetTimeout(plcy.Timeouts.UplinkOnly)
|
||||||
|
|
||||||
var reader buf.Reader
|
if err := buf.Copy(buf.NewReader(conn), output, buf.UpdateActivity(timer)); err != nil {
|
||||||
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 {
|
|
||||||
return newError("failed to process response").Base(err)
|
return newError("failed to process response").Base(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,13 +196,7 @@ func (s *Server) handleConnect(ctx context.Context, request *http.Request, reade
|
|||||||
requestDone := func() error {
|
requestDone := func() error {
|
||||||
defer timer.SetTimeout(plcy.Timeouts.DownlinkOnly)
|
defer timer.SetTimeout(plcy.Timeouts.DownlinkOnly)
|
||||||
|
|
||||||
var reader buf.Reader
|
return buf.Copy(buf.NewReader(conn), link.Writer, buf.UpdateActivity(timer))
|
||||||
if plcy.Buffer.PerConnection == 0 {
|
|
||||||
reader = &buf.SingleReader{Reader: conn}
|
|
||||||
} else {
|
|
||||||
reader = buf.NewReader(conn)
|
|
||||||
}
|
|
||||||
return buf.Copy(reader, link.Writer, buf.UpdateActivity(timer))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
responseDone := func() error {
|
responseDone := func() error {
|
||||||
|
@ -149,16 +149,7 @@ func (s *Server) handleConnection(ctx context.Context, conn internet.Connection,
|
|||||||
sessionPolicy := s.v.PolicyManager().ForLevel(s.user.Level)
|
sessionPolicy := s.v.PolicyManager().ForLevel(s.user.Level)
|
||||||
conn.SetReadDeadline(time.Now().Add(sessionPolicy.Timeouts.Handshake))
|
conn.SetReadDeadline(time.Now().Add(sessionPolicy.Timeouts.Handshake))
|
||||||
|
|
||||||
var bufferedReader buf.BufferedReader
|
bufferedReader := buf.BufferedReader{Reader: buf.NewReader(conn)}
|
||||||
{
|
|
||||||
var reader buf.Reader
|
|
||||||
if sessionPolicy.Buffer.PerConnection == 0 {
|
|
||||||
reader = &buf.SingleReader{Reader: conn}
|
|
||||||
} else {
|
|
||||||
reader = buf.NewReader(conn)
|
|
||||||
}
|
|
||||||
bufferedReader = buf.BufferedReader{Reader: reader}
|
|
||||||
}
|
|
||||||
request, bodyReader, err := ReadTCPSession(s.user, &bufferedReader)
|
request, bodyReader, err := ReadTCPSession(s.user, &bufferedReader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Record(&log.AccessMessage{
|
log.Record(&log.AccessMessage{
|
||||||
|
@ -113,13 +113,7 @@ func (c *Client) Process(ctx context.Context, link *core.Link, dialer proxy.Dial
|
|||||||
}
|
}
|
||||||
responseFunc = func() error {
|
responseFunc = func() error {
|
||||||
defer timer.SetTimeout(p.Timeouts.UplinkOnly)
|
defer timer.SetTimeout(p.Timeouts.UplinkOnly)
|
||||||
var reader buf.Reader
|
return buf.Copy(buf.NewReader(conn), link.Writer, buf.UpdateActivity(timer))
|
||||||
if p.Buffer.PerConnection == 0 {
|
|
||||||
reader = &buf.SingleReader{Reader: conn}
|
|
||||||
} else {
|
|
||||||
reader = buf.NewReader(conn)
|
|
||||||
}
|
|
||||||
return buf.Copy(reader, link.Writer, buf.UpdateActivity(timer))
|
|
||||||
}
|
}
|
||||||
} else if request.Command == protocol.RequestCommandUDP {
|
} else if request.Command == protocol.RequestCommandUDP {
|
||||||
udpConn, err := dialer.Dial(ctx, udpRequest.Destination())
|
udpConn, err := dialer.Dial(ctx, udpRequest.Destination())
|
||||||
|
@ -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))
|
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)
|
inboundDest, ok := proxy.InboundEntryPointFromContext(ctx)
|
||||||
if !ok {
|
if !ok {
|
||||||
return newError("inbound entry point not specified")
|
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,
|
port: inboundDest.Port,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reader := &buf.BufferedReader{Reader: buf.NewReader(conn)}
|
||||||
request, err := svrSession.Handshake(reader, conn)
|
request, err := svrSession.Handshake(reader, conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if source, ok := proxy.SourceFromContext(ctx); ok {
|
if source, ok := proxy.SourceFromContext(ctx); ok {
|
||||||
|
@ -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()
|
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)
|
svrSession := encoding.NewServerSession(h.clients, h.sessionHistory)
|
||||||
request, err := svrSession.DecodeRequestHeader(reader)
|
request, err := svrSession.DecodeRequestHeader(reader)
|
||||||
|
|
||||||
@ -280,9 +280,6 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection i
|
|||||||
|
|
||||||
requestDone := func() error {
|
requestDone := func() error {
|
||||||
defer timer.SetTimeout(sessionPolicy.Timeouts.DownlinkOnly)
|
defer timer.SetTimeout(sessionPolicy.Timeouts.DownlinkOnly)
|
||||||
if sessionPolicy.Buffer.PerConnection > 0 {
|
|
||||||
reader.Reader = buf.NewReader(connection)
|
|
||||||
}
|
|
||||||
return transferRequest(timer, svrSession, request, reader, link.Writer)
|
return transferRequest(timer, svrSession, request, reader, link.Writer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,16 +144,7 @@ func (v *Handler) Process(ctx context.Context, link *core.Link, dialer proxy.Dia
|
|||||||
responseDone := func() error {
|
responseDone := func() error {
|
||||||
defer timer.SetTimeout(sessionPolicy.Timeouts.UplinkOnly)
|
defer timer.SetTimeout(sessionPolicy.Timeouts.UplinkOnly)
|
||||||
|
|
||||||
var reader *buf.BufferedReader
|
reader := &buf.BufferedReader{Reader: buf.NewReader(conn)}
|
||||||
{
|
|
||||||
var r buf.Reader
|
|
||||||
if sessionPolicy.Buffer.PerConnection == 0 {
|
|
||||||
r = &buf.SingleReader{Reader: conn}
|
|
||||||
} else {
|
|
||||||
r = buf.NewReader(conn)
|
|
||||||
}
|
|
||||||
reader = &buf.BufferedReader{Reader: r}
|
|
||||||
}
|
|
||||||
header, err := session.DecodeResponseHeader(reader)
|
header, err := session.DecodeResponseHeader(reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return newError("failed to read header").Base(err)
|
return newError("failed to read header").Base(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user