Update node.go

This commit is contained in:
anonpenguin 2025-08-12 22:48:09 +03:00
parent d3ebd759cd
commit 051babd8e3

View File

@ -403,7 +403,17 @@ func (n *Node) loadOrCreateIdentity() (crypto.PrivKey, error) {
if err != nil { if err != nil {
n.logger.Warn("Failed to unmarshal existing identity, creating new one", zap.Error(err)) n.logger.Warn("Failed to unmarshal existing identity, creating new one", zap.Error(err))
} else { } else {
n.logger.ComponentInfo(logging.ComponentNode, "Loaded existing identity", zap.String("file", identityFile)) // Extract peer ID from private key for logging
peerID, err := peer.IDFromPrivateKey(priv)
if err != nil {
n.logger.ComponentInfo(logging.ComponentNode, "Loaded existing identity",
zap.String("file", identityFile),
zap.String("peer_id", "unable_to_extract"))
} else {
n.logger.ComponentInfo(logging.ComponentNode, "Loaded existing identity",
zap.String("file", identityFile),
zap.String("peer_id", peerID.String()))
}
return priv, nil return priv, nil
} }
} }
@ -415,6 +425,16 @@ func (n *Node) loadOrCreateIdentity() (crypto.PrivKey, error) {
return nil, fmt.Errorf("failed to generate key pair: %w", err) return nil, fmt.Errorf("failed to generate key pair: %w", err)
} }
// Extract peer ID from private key for logging
peerID, err := peer.IDFromPrivateKey(priv)
if err != nil {
n.logger.Info("Identity created",
zap.String("peer_id", "unable_to_extract"))
} else {
n.logger.Info("Identity created",
zap.String("peer_id", peerID.String()))
}
// Save identity // Save identity
data, err := crypto.MarshalPrivateKey(priv) data, err := crypto.MarshalPrivateKey(priv)
if err != nil { if err != nil {
@ -472,9 +492,8 @@ func (n *Node) discoverPeers(ctx context.Context) {
initialCount := len(connectedPeers) initialCount := len(connectedPeers)
if initialCount == 0 { if initialCount == 0 {
// No peers connected, try bootstrap peers again // No peers connected - exponential backoff system handles bootstrap reconnection
n.logger.ComponentInfo(logging.ComponentNode, "No peers connected, retrying bootstrap peers") n.logger.ComponentDebug(logging.ComponentNode, "No peers connected, relying on exponential backoff for bootstrap")
n.connectToBootstrapPeers(ctx)
return return
} }