mirror of
https://github.com/netbirdio/netbird.git
synced 2025-08-14 01:08:46 +02:00
Add close message type
This commit is contained in:
@ -10,6 +10,7 @@ const (
|
||||
MsgTypeHello MsgType = 0
|
||||
MsgTypeHelloResponse MsgType = 1
|
||||
MsgTypeTransport MsgType = 2
|
||||
MsgClose MsgType = 3
|
||||
)
|
||||
|
||||
var (
|
||||
@ -26,6 +27,8 @@ func (m MsgType) String() string {
|
||||
return "hello response"
|
||||
case MsgTypeTransport:
|
||||
return "transport"
|
||||
case MsgClose:
|
||||
return "close"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
@ -39,6 +42,8 @@ func DetermineClientMsgType(msg []byte) (MsgType, error) {
|
||||
return msgType, nil
|
||||
case MsgTypeTransport:
|
||||
return msgType, nil
|
||||
case MsgClose:
|
||||
return msgType, nil
|
||||
default:
|
||||
return 0, fmt.Errorf("invalid msg type, len: %d", len(msg))
|
||||
}
|
||||
@ -52,6 +57,8 @@ func DetermineServerMsgType(msg []byte) (MsgType, error) {
|
||||
return msgType, nil
|
||||
case MsgTypeTransport:
|
||||
return msgType, nil
|
||||
case MsgClose:
|
||||
return msgType, nil
|
||||
default:
|
||||
return 0, fmt.Errorf("invalid msg type (len: %d)", len(msg))
|
||||
}
|
||||
@ -81,6 +88,14 @@ func MarshalHelloResponse() []byte {
|
||||
return msg
|
||||
}
|
||||
|
||||
// Close message
|
||||
|
||||
func MarshalCloseMsg() []byte {
|
||||
msg := make([]byte, 1)
|
||||
msg[0] = byte(MsgClose)
|
||||
return msg
|
||||
}
|
||||
|
||||
// Transport message
|
||||
|
||||
func MarshalTransportMsg(peerID []byte, payload []byte) []byte {
|
||||
|
Reference in New Issue
Block a user