Announce Architecture
The announce command manages a long-running swarm session, coordinating DHT presence and optionally handling incoming connections.
Initialization Flow
- Identity Generation: A
KeyPairis either generated randomly or derived from a seed. - Swarm Setup: A
SwarmConfigis constructed with the identity and DHT configuration. Firewall settings are determined by the global config (Open ifpublic=true, Consistent otherwise). - Joining Topic: The node joins the topic using
JoinOpts { client: false }. This instructs the DHT to act as a server for this topic, making the node discoverable to lookup queries. - Flushing: The node waits for the join operation to flush, ensuring at least one announcement has reached the DHT.
Metadata Persistence
If the --data flag is provided, the node performs an initial mutable_put to the DHT.
- Storage: The data is signed by the node’s private key and stored at the node’s public key address on the DHT.
- Sequence: The
seqfield is set to the current Unix epoch in seconds. - Lifecycle: A background task triggers every 600 seconds to re-put the data, preventing expiration and keeping the DHT record fresh.
Connection Management
When a peer discovers this node via lookup, they may attempt to open a direct UDX connection.
- Accepting: The
announceloop listens on theconn_rxchannel for incoming connections. - Modes:
- Default: Incoming connections are immediately dropped to minimize resource usage.
- Echo Mode (
--ping): Connections are accepted and passed to the Echo Protocol handler.
Shutdown Sequence
The command remains active until it receives a termination signal (SIGINT or SIGTERM) or the --duration timer expires.
- Unannounce: The node sends a
leaverequest to the DHT for the active topic. - Cleanup: The background refresh task is aborted, and the swarm handle is destroyed.
- Exit: The process exits with code 0.