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) |
| 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

View file

@ -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)

View file

@ -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},