mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-04 20:37:40 +03:00
30 lines
752 B
Go
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
|
|
}
|