fix(peer): allow empty peer names
All checks were successful
Security Scan / security (push) Successful in 10s
Test / test (push) Successful in 1m23s

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-01 06:35:43 +00:00
parent 572970d255
commit d5a962996b
3 changed files with 9 additions and 9 deletions

View file

@ -98,7 +98,7 @@ The `Transport` manages a WebSocket server (gorilla/websocket) and outbound conn
| Timeout | 3.0 (floored at 0) | | Timeout | 3.0 (floored at 0) |
| Default (new peer) | 50.0 | | Default (new peer) | 50.0 |
**Peer name validation**: Names must be 164 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 164 characters, start and end with an alphanumeric character, and contain only alphanumeric, hyphen, underscore, or space characters.
### message.go — Protocol Messages ### message.go — Protocol Messages

View file

@ -51,9 +51,8 @@ const (
PeerAuthAllowlist PeerAuthAllowlist
) )
// Peer name validation constants // Peer name validation constants.
const ( const (
PeerNameMinLength = 1
PeerNameMaxLength = 64 PeerNameMaxLength = 64
) )
@ -72,11 +71,12 @@ func safeKeyPrefix(key string) string {
} }
// validatePeerName checks if a peer name is valid. // validatePeerName checks if a peer name is valid.
// Peer names must be 1-64 characters, start and end with alphanumeric, // Empty names are permitted. Non-empty names must be 1-64 characters,
// and contain only alphanumeric, hyphens, underscores, and spaces. // start and end with alphanumeric, and contain only alphanumeric,
// hyphens, underscores, and spaces.
func validatePeerName(name string) error { func validatePeerName(name string) error {
if len(name) < PeerNameMinLength { if name == "" {
return coreerr.E("validatePeerName", "peer name too short", nil) return nil
} }
if len(name) > PeerNameMaxLength { if len(name) > PeerNameMaxLength {
return coreerr.E("validatePeerName", "peer name too long", nil) return coreerr.E("validatePeerName", "peer name too long", nil)

View file

@ -543,7 +543,7 @@ func TestPeerRegistry_PeerNameValidation(t *testing.T) {
peerName string peerName string
shouldErr bool shouldErr bool
}{ }{
{"empty name rejected", "", true}, {"empty name allowed", "", false},
{"single char", "A", false}, {"single char", "A", false},
{"simple name", "MyPeer", false}, {"simple name", "MyPeer", false},
{"name with hyphen", "my-peer", false}, {"name with hyphen", "my-peer", false},
@ -697,7 +697,7 @@ func TestValidatePeerName(t *testing.T) {
peerName string peerName string
shouldErr bool shouldErr bool
}{ }{
{"empty rejected", "", true}, {"empty allowed", "", false},
{"single alphanumeric", "A", false}, {"single alphanumeric", "A", false},
{"simple alphanumeric", "TestPeer", false}, {"simple alphanumeric", "TestPeer", false},
{"with hyphens", "test-peer", false}, {"with hyphens", "test-peer", false},