ax(node): rename mu to mutex in NodeManager for AX Principle 1 compliance
Short name `mu` requires context to decode; `mutex` is self-describing. Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
parent
b0a39b9c71
commit
33db5f2dc6
1 changed files with 11 additions and 11 deletions
|
|
@ -76,7 +76,7 @@ type NodeManager struct {
|
|||
keyPair *stmf.KeyPair
|
||||
keyPath string // ~/.local/share/lethean-desktop/node/private.key
|
||||
configPath string // ~/.config/lethean-desktop/node.json
|
||||
mu sync.RWMutex
|
||||
mutex sync.RWMutex
|
||||
}
|
||||
|
||||
// NewNodeManager creates a new NodeManager, loading existing identity if available.
|
||||
|
|
@ -113,16 +113,16 @@ func NewNodeManagerWithPaths(keyPath, configPath string) (*NodeManager, error) {
|
|||
|
||||
// if nm.HasIdentity() { return nm.GetIdentity() }
|
||||
func (n *NodeManager) HasIdentity() bool {
|
||||
n.mu.RLock()
|
||||
defer n.mu.RUnlock()
|
||||
n.mutex.RLock()
|
||||
defer n.mutex.RUnlock()
|
||||
return n.identity != nil
|
||||
}
|
||||
|
||||
// identity := nm.GetIdentity()
|
||||
// if identity == nil { return core.E("node", "identity not initialised", nil) }
|
||||
func (n *NodeManager) GetIdentity() *NodeIdentity {
|
||||
n.mu.RLock()
|
||||
defer n.mu.RUnlock()
|
||||
n.mutex.RLock()
|
||||
defer n.mutex.RUnlock()
|
||||
if n.identity == nil {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -133,8 +133,8 @@ func (n *NodeManager) GetIdentity() *NodeIdentity {
|
|||
|
||||
// if err := nm.GenerateIdentity("my-worker", RoleWorker); err != nil { return err }
|
||||
func (n *NodeManager) GenerateIdentity(name string, role NodeRole) error {
|
||||
n.mu.Lock()
|
||||
defer n.mu.Unlock()
|
||||
n.mutex.Lock()
|
||||
defer n.mutex.Unlock()
|
||||
|
||||
// Generate X25519 keypair using STMF
|
||||
keyPair, err := stmf.GenerateKeyPair()
|
||||
|
|
@ -174,8 +174,8 @@ func (n *NodeManager) GenerateIdentity(name string, role NodeRole) error {
|
|||
// secret, err := nm.DeriveSharedSecret(peer.PublicKey)
|
||||
// smsg.Encrypt(msg, base64.StdEncoding.EncodeToString(secret))
|
||||
func (n *NodeManager) DeriveSharedSecret(peerPubKeyBase64 string) ([]byte, error) {
|
||||
n.mu.RLock()
|
||||
defer n.mu.RUnlock()
|
||||
n.mutex.RLock()
|
||||
defer n.mutex.RUnlock()
|
||||
|
||||
if n.privateKey == nil {
|
||||
return nil, fmt.Errorf("node identity not initialized")
|
||||
|
|
@ -274,8 +274,8 @@ func (n *NodeManager) loadIdentity() error {
|
|||
|
||||
// Delete removes the node identity and keys from disk.
|
||||
func (n *NodeManager) Delete() error {
|
||||
n.mu.Lock()
|
||||
defer n.mu.Unlock()
|
||||
n.mutex.Lock()
|
||||
defer n.mutex.Unlock()
|
||||
|
||||
// Remove private key
|
||||
if err := os.Remove(n.keyPath); err != nil && !os.IsNotExist(err) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue