Skip to content

Commit

Permalink
Fix HandshakeFailure usages
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Nov 15, 2024
1 parent 7f621fd commit 07f7dca
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion common/network/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net"
"net/netip"

"github.com/sagernet/sing/common/buf"
M "github.com/sagernet/sing/common/metadata"
)

Expand All @@ -14,7 +15,7 @@ type Dialer interface {
}

type PayloadDialer interface {
DialPayloadContext(ctx context.Context, network string, destination M.Socksaddr, payload [][]byte) (net.Conn, error)
DialPayloadContext(ctx context.Context, network string, destination M.Socksaddr, payloads []*buf.Buffer) (net.Conn, error)
}

type ParallelDialer interface {
Expand Down
8 changes: 7 additions & 1 deletion common/network/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ func ReportHandshakeFailure(reporter any, err error) error {
func CloseOnHandshakeFailure(reporter any, onClose CloseHandlerFunc, err error) error {
if err != nil {
if handshakeConn, isHandshakeConn := common.Cast[HandshakeFailure](reporter); isHandshakeConn {
err = E.Append(err, handshakeConn.HandshakeFailure(err), func(err error) error {
hErr := handshakeConn.HandshakeFailure(err)
err = E.Append(err, hErr, func(err error) error {
if closer, isCloser := reporter.(io.Closer); isCloser {
err = E.Append(err, closer.Close(), func(err error) error {
return E.Cause(err, "close")
})
}
return E.Cause(err, "write handshake failure")
})
} else {
Expand Down
5 changes: 3 additions & 2 deletions protocol/socks/lazy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package socks

import (
"net"
"os"

"github.com/sagernet/sing/common/buf"
"github.com/sagernet/sing/common/bufio"
Expand Down Expand Up @@ -48,7 +49,7 @@ func (c *LazyConn) ConnHandshakeSuccess(conn net.Conn) error {

func (c *LazyConn) HandshakeFailure(err error) error {
if c.responseWritten {
return nil
return os.ErrInvalid
}
defer func() {
c.responseWritten = true
Expand Down Expand Up @@ -130,7 +131,7 @@ func (c *LazyAssociatePacketConn) HandshakeSuccess() error {

func (c *LazyAssociatePacketConn) HandshakeFailure(err error) error {
if c.responseWritten {
return nil
return os.ErrInvalid
}
defer func() {
c.responseWritten = true
Expand Down

0 comments on commit 07f7dca

Please sign in to comment.