diff --git a/docs/architecture.md b/docs/architecture.md index 2915608..6e75d4a 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -98,7 +98,7 @@ The `Transport` manages a WebSocket server (gorilla/websocket) and outbound conn | Timeout | −3.0 (floored at 0) | | Default (new peer) | 50.0 | -**Peer name validation**: Names must be 1–64 characters, start and end with an alphanumeric character, and contain only alphanumeric, hyphen, underscore, or space characters. +**Peer name validation**: Empty names are permitted. Non-empty names must be 1–64 characters, start and end with an alphanumeric character, and contain only alphanumeric, hyphen, underscore, or space characters. ### message.go — Protocol Messages diff --git a/node/peer.go b/node/peer.go index 76f4ee3..2aa750c 100644 --- a/node/peer.go +++ b/node/peer.go @@ -51,9 +51,8 @@ const ( PeerAuthAllowlist ) -// Peer name validation constants +// Peer name validation constants. const ( - PeerNameMinLength = 1 PeerNameMaxLength = 64 ) @@ -72,11 +71,12 @@ func safeKeyPrefix(key string) string { } // validatePeerName checks if a peer name is valid. -// Peer names must be 1-64 characters, start and end with alphanumeric, -// and contain only alphanumeric, hyphens, underscores, and spaces. +// Empty names are permitted. Non-empty names must be 1-64 characters, +// start and end with alphanumeric, and contain only alphanumeric, +// hyphens, underscores, and spaces. func validatePeerName(name string) error { - if len(name) < PeerNameMinLength { - return coreerr.E("validatePeerName", "peer name too short", nil) + if name == "" { + return nil } if len(name) > PeerNameMaxLength { return coreerr.E("validatePeerName", "peer name too long", nil) diff --git a/node/peer_test.go b/node/peer_test.go index 393492b..7960f6f 100644 --- a/node/peer_test.go +++ b/node/peer_test.go @@ -543,7 +543,7 @@ func TestPeerRegistry_PeerNameValidation(t *testing.T) { peerName string shouldErr bool }{ - {"empty name rejected", "", true}, + {"empty name allowed", "", false}, {"single char", "A", false}, {"simple name", "MyPeer", false}, {"name with hyphen", "my-peer", false}, @@ -697,7 +697,7 @@ func TestValidatePeerName(t *testing.T) { peerName string shouldErr bool }{ - {"empty rejected", "", true}, + {"empty allowed", "", false}, {"single alphanumeric", "A", false}, {"simple alphanumeric", "TestPeer", false}, {"with hyphens", "test-peer", false},