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 peer-to-peer connections to other iroh
endpoints, while still remaining independent connections. This will result in
more optimal network behaviour.
Connections
Because we’re in a peer-to-peer context, 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!
Don’t store relay_url & direct_addresses values
If you’re persisting the contents ofEndpointAddrs in your app, it’s probably
not worth keeping the relay_url and direct_address fields, unless you know
these details are unlikely to change. Providing stale details to the endpoint
can slow down connection construction.