Skip to content

Commit

Permalink
Send shadowsocks handshake with payload if available (#1292)
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai authored and xiaokangwang committed Sep 27, 2021
1 parent 8cc6fbc commit 7d78683
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions proxy/shadowsocks/client.go
Expand Up @@ -2,6 +2,7 @@ package shadowsocks

import (
"context"
"time"

core "github.com/v2fly/v2ray-core/v4"
"github.com/v2fly/v2ray-core/v4/common"
Expand Down Expand Up @@ -99,18 +100,22 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
timer := signal.CancelAfterInactivity(ctx, cancel, sessionPolicy.Timeouts.ConnectionIdle)

if request.Command == protocol.RequestCommandTCP {
bufferedWriter := buf.NewBufferedWriter(buf.NewWriter(conn))
bodyWriter, err := WriteTCPRequest(request, bufferedWriter)
if err != nil {
return newError("failed to write request").Base(err)
}

if err := bufferedWriter.SetBuffered(false); err != nil {
return err
}

requestDone := func() error {
defer timer.SetTimeout(sessionPolicy.Timeouts.DownlinkOnly)
bufferedWriter := buf.NewBufferedWriter(buf.NewWriter(conn))
bodyWriter, err := WriteTCPRequest(request, bufferedWriter)
if err != nil {
return newError("failed to write request").Base(err)
}

if err = buf.CopyOnceTimeout(link.Reader, bodyWriter, time.Millisecond*100); err != nil && err != buf.ErrNotTimeoutReader && err != buf.ErrReadTimeout {
return newError("failed to write A request payload").Base(err).AtWarning()
}

if err := bufferedWriter.SetBuffered(false); err != nil {
return err
}

return buf.Copy(link.Reader, bodyWriter, buf.UpdateActivity(timer))
}

Expand Down

0 comments on commit 7d78683

Please sign in to comment.