sing/common/network/handshake.go
2023-09-08 11:22:32 +08:00

30 lines
752 B
Go

package network
import (
"github.com/sagernet/sing/common"
E "github.com/sagernet/sing/common/exceptions"
)
type HandshakeFailure interface {
HandshakeFailure(err error) error
}
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
}