mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-03 11:57:39 +03:00
Add HandshakeSuccess interface
This commit is contained in:
parent
03c21c0a12
commit
b0849c43a6
3 changed files with 22 additions and 11 deletions
|
@ -98,7 +98,7 @@ func CopyExtendedBuffer(originSource io.Writer, destination N.ExtendedWriter, so
|
|||
err = destination.WriteBuffer(buffer)
|
||||
if err != nil {
|
||||
if !notFirstTime {
|
||||
err = N.HandshakeFailure(originSource, err)
|
||||
err = N.ReportHandshakeFailure(originSource, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ func CopyExtendedWithSrcBuffer(originSource io.Reader, destination N.ExtendedWri
|
|||
if err != nil {
|
||||
buffer.Release()
|
||||
if !notFirstTime {
|
||||
err = N.HandshakeFailure(originSource, err)
|
||||
err = N.ReportHandshakeFailure(originSource, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ func CopyExtendedWithPool(originSource io.Reader, destination N.ExtendedWriter,
|
|||
if err != nil {
|
||||
buffer.Release()
|
||||
if !notFirstTime {
|
||||
err = N.HandshakeFailure(originSource, err)
|
||||
err = N.ReportHandshakeFailure(originSource, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -304,7 +304,7 @@ func CopyPacketWithSrcBuffer(originSource N.PacketReader, destinationConn N.Pack
|
|||
if err != nil {
|
||||
buffer.Release()
|
||||
if !notFirstTime {
|
||||
err = N.HandshakeFailure(originSource, err)
|
||||
err = N.ReportHandshakeFailure(originSource, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -345,7 +345,7 @@ func CopyPacketWithPool(originSource N.PacketReader, destinationConn N.PacketWri
|
|||
if err != nil {
|
||||
buffer.Release()
|
||||
if !notFirstTime {
|
||||
err = N.HandshakeFailure(originSource, err)
|
||||
err = N.ReportHandshakeFailure(originSource, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -381,7 +381,7 @@ func WritePacketWithPool(originSource N.PacketReader, destinationConn N.PacketWr
|
|||
if err != nil {
|
||||
buffer.Release()
|
||||
if !notFirstTime {
|
||||
err = N.HandshakeFailure(originSource, err)
|
||||
err = N.ReportHandshakeFailure(originSource, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ func copyWaitWithPool(originSource io.Reader, destination N.ExtendedWriter, sour
|
|||
if err != nil {
|
||||
buffer.Release()
|
||||
if !notFirstTime {
|
||||
err = N.HandshakeFailure(originSource, err)
|
||||
err = N.ReportHandshakeFailure(originSource, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ func copyPacketWaitWithPool(originSource N.PacketReader, destinationConn N.Packe
|
|||
if err != nil {
|
||||
buffer.Release()
|
||||
if !notFirstTime {
|
||||
err = N.HandshakeFailure(originSource, err)
|
||||
err = N.ReportHandshakeFailure(originSource, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -5,15 +5,26 @@ import (
|
|||
E "github.com/sagernet/sing/common/exceptions"
|
||||
)
|
||||
|
||||
type HandshakeConn interface {
|
||||
type HandshakeFailure interface {
|
||||
HandshakeFailure(err error) error
|
||||
}
|
||||
|
||||
func HandshakeFailure(conn any, err error) error {
|
||||
if handshakeConn, isHandshakeConn := common.Cast[HandshakeConn](conn); isHandshakeConn {
|
||||
type HandshakeSuccess interface {
|
||||
HandshakeSuccess() error
|
||||
}
|
||||
|
||||
func ReportHandshakeFailure(conn any, err error) error {
|
||||
if handshakeConn, isHandshakeConn := common.Cast[HandshakeFailure](conn); isHandshakeConn {
|
||||
return E.Append(err, handshakeConn.HandshakeFailure(err), func(err error) error {
|
||||
return E.Cause(err, "write handshake failure")
|
||||
})
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func ReportHandshakeSuccess(conn any) error {
|
||||
if handshakeConn, isHandshakeConn := common.Cast[HandshakeSuccess](conn); isHandshakeConn {
|
||||
return handshakeConn.HandshakeSuccess()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue