Is it possible to preassign the PeerId of a node?

So here is the scenario:

For a test environment I need to setup a private IPFS network where the nodes won’t be on the same LAN. Ie in my network emulation there would be routing hops.

In other to achieve this, I found out I could use a bootstrap peer and add it to the bootstrap list of the participating IPFS nodes.

But since the whole network simulation is being automated, I need to have the PeerId of the bootstrap node, so this can be set for the other IPFS nodes when the topology is started.

So the question now is. Is there a way to predetermine the PeerId a node will have. Specifically the hash of the public key a node will have, so I can construct its multi-address and then use it to configure the other nodes?

The other option is to first spin up the bootnode, ask it for its PeerId and use that to configure the other node, but I think having the multi-address of the PeerId before hand will simplify the setup.

I wonder if you can’t construct a libp2p node with a given private keys (known and always the same), then construct an ipfs node with the libp2p node. Or provide the key after init, I don’t know how this would work. https://godoc.org/github.com/libp2p/go-libp2p#Identity

1 Like