ax(node): replace prose comments with usage examples on PeerRegistry auth methods
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run

SetAuthMode, GetAuthMode, AllowPublicKey, and RevokePublicKey all had
comments that restated the function signature rather than showing concrete
usage. Replaced with call-site examples per AX Principle 2.

Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
Claude 2026-04-02 08:47:20 +01:00
parent caa887325d
commit 1ff90ba170
No known key found for this signature in database
GPG key ID: AF404715446AEB41

View file

@ -153,7 +153,8 @@ func NewPeerRegistryWithPath(peersPath string) (*PeerRegistry, error) {
return pr, nil
}
// SetAuthMode sets the authentication mode for peer connections.
// registry.SetAuthMode(PeerAuthAllowlist) // require pre-registration
// registry.SetAuthMode(PeerAuthOpen) // allow any peer (default)
func (r *PeerRegistry) SetAuthMode(mode PeerAuthMode) {
r.allowedPublicKeyMutex.Lock()
defer r.allowedPublicKeyMutex.Unlock()
@ -161,14 +162,14 @@ func (r *PeerRegistry) SetAuthMode(mode PeerAuthMode) {
logging.Info("peer auth mode changed", logging.Fields{"mode": mode})
}
// GetAuthMode returns the current authentication mode.
// if registry.GetAuthMode() == PeerAuthAllowlist { /* enforce allowlist */ }
func (r *PeerRegistry) GetAuthMode() PeerAuthMode {
r.allowedPublicKeyMutex.RLock()
defer r.allowedPublicKeyMutex.RUnlock()
return r.authMode
}
// AllowPublicKey adds a public key to the allowlist.
// registry.AllowPublicKey(peer.PublicKey) // permit this key without pre-registration
func (r *PeerRegistry) AllowPublicKey(publicKey string) {
r.allowedPublicKeyMutex.Lock()
defer r.allowedPublicKeyMutex.Unlock()
@ -176,7 +177,7 @@ func (r *PeerRegistry) AllowPublicKey(publicKey string) {
logging.Debug("public key added to allowlist", logging.Fields{"key": safeKeyPrefix(publicKey)})
}
// RevokePublicKey removes a public key from the allowlist.
// registry.RevokePublicKey(peer.PublicKey) // block this key on next connect attempt
func (r *PeerRegistry) RevokePublicKey(publicKey string) {
r.allowedPublicKeyMutex.Lock()
defer r.allowedPublicKeyMutex.Unlock()