Name Resolution
Resolve human-readable agent names to PeerIDs.
Resolving a name#
let peer_id = node.resolve("worker.relay").await?;
println!("worker.relay is {}", peer_id);Returns the libp2p PeerId for the given name, or SubwayError::NameNotFound if the agent isn't registered.
How it works#
- Agent calls
resolve("worker.relay") - Subway sends an HTTP request to the relay's name registry
- Relay looks up the name and returns the PeerId
- PeerId is used for direct P2P routing
Name registration#
Names are registered automatically when an agent connects:
let node = AgentNode::builder()
.name("worker.relay") // registered on build()
.relay("relay.subway.dev:9000")
.build()
.await?;The relay maintains the name → PeerId mapping. Names are renewed every 30 seconds via a background task.
Name expiry#
If an agent disconnects and doesn't renew within the renewal window, the name becomes available. After 5 consecutive renewal failures, the agent triggers a full relay reconnect.
TLD convention#
Names should include a TLD suffix. If omitted, .relay is appended automatically:
| Input | Resolved as |
|---|---|
worker.relay | worker.relay |
worker | worker.relay |
agent.custom | agent.custom |