EndpointID (the public half of an
Ed25519 keypair) and the private key used to sign and decrypt messages.
Generally, an application will have a single endpoint instance. This ensures all
the connections made share the same connections to other iroh
endpoints, while still remaining independent connections. This will result in
more optimal network behaviour.
Connections
Either endpoint might be operating as the “server”, so we useconnect and
accept to distinguish between the two. The connect method is used to create
a new connection to a remote endpoint, while accept is used to accept incoming
connections from a remote endpoint.
Connections are full-fledged QUIC connections, giving you access to most
features of QUIC / HTTP3, including bidirectional and unidirectional streams.
A Relay server can be used to make the connections reliable.
Due to the light-weight properties of QUIC streams a stream can only be accepted once the initiating peer has sent some data on it.
Endpoint Identifiers
Each endpoint in iroh has a unique identifier (EndpointID) created as a
cryptographic key. This can be used to globally identify an endpoint. Because
EndpointIDs are cryptographic keys, they are also the mechanism by which all
traffic is always encrypted for a specific endpoint only.
See the EndpointID documentation for more information.
Endpoint Addresses
Endpoint Addresses orEndpointAddrs are a common struct you’ll interact when working with iroh to tell iroh what & where to dial. In rust they look like this:
EndpointAddrs a fair amount when working with iroh. It’s also quite normal to construct addresses manually from, say, endpoint identifiers stored in your application database.
When we call connect on an Endpoint, we need to pass either a EndpointAddr, or something that can turn into a EndpointAddr. In iroh Endpoints will have different fields populated depending on where they came from, and the discovery services you’ve configured your endpoint with.
Interaction with discovery
From the above struct, the only required field is theid. And because of
this, there’s an implementation of From that can turn EndpointIDs directly
into EndpointAddrs. but this will only work if you have a discovery service
that can resolve EndpointIDs enabled. Thankfully, we enable discovery by
default:
When to provide full details
If you have full dialing details, it’s well worth providing them as part of aEndpointAddr passed to connect. Iroh can use this to skip the network
roundtrip required to either do initial address discovery, or update cached
addresses. So if you have a source of up to date home relay & dialing info,
provide it!
What to persist in your application
When storing endpoint information in your application database, what you should persist depends on whether you’re using discovery: If you’re using discovery (recommended): Store just theEndpointID. When you need to connect, construct an
EndpointAddr from the ID and let discovery resolve the current dialing
details. This is the most robust approach since relay URLs and direct addresses
can change frequently in P2P networks.
EndpointAddr information (including the addrs
field with relay and direct address information). Without discovery, iroh has no
way to resolve an EndpointID to dialing details.
Keep in mind that stored dialing details can become stale quickly. Providing
outdated information may slow down connection establishment as iroh tries
addresses that no longer work before falling back to other methods.