1

The process of generating an enode id seems to be: "Generate private key -> Generate public key -> add the IP and port". If I restart the computer, the node id changes as well. How can I do if I want to fixed this node id (like the bootnode key), where is the implementation of this process?

1 Answer 1

0

I suggest to look at node/node.go

// Start create a live P2P node and starts running it.
func (n *Node) Start() error {
    n.lock.Lock()
    defer n.lock.Unlock()

    // Short circuit if the node's already running
    if n.server != nil {
        return ErrNodeRunning
    }
    if err := n.openDataDir(); err != nil {
        return err
    }

    // Initialize the p2p server. This creates the node key and
    // discovery databases.
    n.serverConfig = n.config.P2P
    n.serverConfig.PrivateKey = n.config.NodeKey()
    n.serverConfig.Name = n.config.NodeName()
    n.serverConfig.Logger = n.log
    if n.serverConfig.StaticNodes == nil {
        n.serverConfig.StaticNodes = n.config.StaticNodes()
    }
    if n.serverConfig.TrustedNodes == nil {
        n.serverConfig.TrustedNodes = n.config.TrustedNodes()
    }
    if n.serverConfig.NodeDatabase == "" {
        n.serverConfig.NodeDatabase = n.config.NodeDB()
    }
    running := &p2p.Server{Config: n.serverConfig}
    n.log.Info("Starting peer-to-peer node", "instance", n.serverConfig.Name)

There is also cmd/bootnode/main.go :

case *genKey != "":
    nodeKey, err = crypto.GenerateKey()
    if err != nil {
        utils.Fatalf("could not generate key: %v", err)
    }
    if err = crypto.SaveECDSA(*genKey, nodeKey); err != nil {
        utils.Fatalf("%v", err)
    }
    return

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.