mirror of
https://github.com/netbirdio/netbird.git
synced 2026-03-31 06:24:18 -04:00
Health-check connections now send a properly formatted auth message with a well-known peer ID instead of immediately closing. The server recognizes this peer ID and handles the connection gracefully with a debug log instead of error logs.
32 lines
887 B
Go
32 lines
887 B
Go
package peerid
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
|
|
v2 "github.com/netbirdio/netbird/shared/relay/auth/hmac/v2"
|
|
"github.com/netbirdio/netbird/shared/relay/messages"
|
|
)
|
|
|
|
var (
|
|
// HealthCheckPeerID is the hashed peer ID for health check connections
|
|
HealthCheckPeerID = messages.HashID("healthcheck-agent")
|
|
|
|
// DummyAuthToken is a structurally valid auth token for health check.
|
|
// The signature is not valid but the format is correct (1 byte algo + 32 bytes signature + payload).
|
|
DummyAuthToken = createDummyToken()
|
|
)
|
|
|
|
func createDummyToken() []byte {
|
|
token := v2.Token{
|
|
AuthAlgo: v2.AuthAlgoHMACSHA256,
|
|
Signature: make([]byte, sha256.Size),
|
|
Payload: []byte("healthcheck"),
|
|
}
|
|
return token.Marshal()
|
|
}
|
|
|
|
// IsHealthCheck checks if the given peer ID is the health check agent
|
|
func IsHealthCheck(peerID *messages.PeerID) bool {
|
|
return peerID != nil && *peerID == HealthCheckPeerID
|
|
}
|