The connection manager keeps the number of active peer connections within bounds:
Setting
Value
Low watermark
100 peers
High watermark
400 peers
Grace period
1 minute
When the number of connections exceeds the high watermark, the connection manager begins pruning connections down toward the low watermark. New connections are not pruned within the grace period.
cm, err := connmgr.NewConnManager(100, 400, connmgr.WithGracePeriod(time.Minute))
When dataDir is provided, the host generates an Ed25519 keypair on first run and persists it to {dataDir}/host.key. On subsequent starts, the key is loaded from disk, giving the node a stable peer ID across restarts.
{dataDir}/host.key # Ed25519 private key (libp2p marshaled format, mode 0600)
[!WARNING] Key Protection
The host key file is written with mode 0600 (owner read/write only). The data directory is created with mode 0700. Losing this key means the node gets a new peer ID on next start.
If dataDir is empty (e.g., in tests), a new ephemeral identity is generated each time.
The node dials each address on startup with a 10-second timeout per peer. If any connections fail, a background goroutine retries every 10 seconds until all bootstrap peers are connected.
Startup │ ├─ Dial peer A ─── success ├─ Dial peer B ─── fail │ └─ Start retry loop (every 10s) ├─ Check: A connected? yes, skip ├─ Check: B connected? no, dial again └─ All connected? → stop loop
[!TIP] Multiaddr Format
A full multiaddr includes the transport and peer ID:
func SetupDHT(ctx context.Context, h host.Host) (*dht.IpfsDHT, error)
The DHT is configured with:
Setting
Value
Mode
Server (participates in routing)
Protocol prefix
/xe
The /xe protocol prefix ensures XE nodes form their own DHT, isolated from the public IPFS DHT. Server mode means the node stores and serves routing records, not just queries them.
After creation, Bootstrap() is called to populate the routing table from the existing peerstore.
The DHT is used by the Messenger to resolve peer IDs to addresses via FindPeer() when a target peer is not already known.