github.com/sagernet/sing@v0.4.0-beta.19.0.20240518125136-f67a0988a636/common/network/handshake.go (about) 1 package network 2 3 import ( 4 "github.com/sagernet/sing/common" 5 E "github.com/sagernet/sing/common/exceptions" 6 ) 7 8 type HandshakeFailure interface { 9 HandshakeFailure(err error) error 10 } 11 12 type HandshakeSuccess interface { 13 HandshakeSuccess() error 14 } 15 16 func ReportHandshakeFailure(conn any, err error) error { 17 if handshakeConn, isHandshakeConn := common.Cast[HandshakeFailure](conn); isHandshakeConn { 18 return E.Append(err, handshakeConn.HandshakeFailure(err), func(err error) error { 19 return E.Cause(err, "write handshake failure") 20 }) 21 } 22 return err 23 } 24 25 func ReportHandshakeSuccess(conn any) error { 26 if handshakeConn, isHandshakeConn := common.Cast[HandshakeSuccess](conn); isHandshakeConn { 27 return handshakeConn.HandshakeSuccess() 28 } 29 return nil 30 }