pub struct Endpoint { /* private fields */ }iroh_endpoint only.Expand description
Establish encrypted, direct connections over Internet Protocol with QUIC.
§Example
// Generate Ed25519 key which will be used to authenticate node.
let signing_key = p2panda_core::SigningKey::generate();
// Use this iroh relay as a "home relay".
let relay_url = "https://my.relay.org".parse().expect("valid relay url");
// Initialise endpoint with custom network identifier.
let endpoint = Endpoint::builder(address_book)
.network_id([1; 32])
.signing_key(signing_key)
.relay_url(relay_url)
.spawn()
.await?;
// Other nodes can use this id now to establish a direct connection.
println!("my node id: {}", endpoint.node_id());§iroh
Most of the lower-level Internet Protocol networking is made possible by the work of iroh utilising well-established and known standards, like QUIC for transport, (self-certified) TLS 1.3 for transport encryption, QUIC Address Discovery (QAD) for STUN, TURN servers for relayed fallbacks.
§Network identifier
Use NetworkId to actively partition the network. The identifier serves as
a shared secret; nodes will not be able to establish connections if their identifiers differ.
§Custom Protocol Handlers
Register your own custom protocols using the Endpoint::accept method.
§Relays
Use Builder::relay_url to register one or more iroh relay urls which are required to aid
in establishing a direct connection.
§Resolving transport infos
To connect to any endpoint by it’s node id / public key we first need to resolve it to the associated addressing information (relay url, IPv4 and IPv6 addresses) before attempting to establish a direct connection.
Endpoint takes the AddressBook as a dependency which provides it with
the resolved transport information.
The address book itself is populated with resolved transport information by two services:
MdnsDiscovery: Resolve addresses of nearby devices on the local-area network.Discovery: Resolve addresses using random-walk strategy, exploring the network.
Implementations§
Source§impl Endpoint
impl Endpoint
pub fn builder(address_book: AddressBook) -> Builder
Sourcepub async fn endpoint(&self) -> Result<Endpoint, EndpointError>
pub async fn endpoint(&self) -> Result<Endpoint, EndpointError>
Return the internal iroh endpoint instance.
pub fn network_id(&self) -> NetworkId
pub fn node_id(&self) -> NodeId
Sourcepub async fn accept<P: ProtocolHandler>(
&self,
protocol_id: impl AsRef<[u8]>,
protocol_handler: P,
) -> Result<(), EndpointError>
pub async fn accept<P: ProtocolHandler>( &self, protocol_id: impl AsRef<[u8]>, protocol_handler: P, ) -> Result<(), EndpointError>
Register protocol handler for a given ALPN (protocol identifier).
Sourcepub async fn connect(
&self,
node_id: NodeId,
protocol_id: impl AsRef<[u8]>,
) -> Result<Connection, EndpointError>
pub async fn connect( &self, node_id: NodeId, protocol_id: impl AsRef<[u8]>, ) -> Result<Connection, EndpointError>
Starts a connection attempt to a remote iroh endpoint and returns a future which can be awaited for establishing the final connection.
The ALPN byte string, or application-level protocol identifier, is also required. The remote endpoint must support this alpn, otherwise the connection attempt will fail with an error.
pub async fn connect_with_config( &self, node_id: NodeId, protocol_id: impl AsRef<[u8]>, quic_transport_config: QuicTransportConfig, ) -> Result<Connection, EndpointError>
Trait Implementations§
Source§impl ChildActor for Endpoint
Available on crate feature supervisor only.
impl ChildActor for Endpoint
supervisor only.fn on_start( &self, supervisor: ActorCell, thread_pool: ThreadLocalActorSpawner, ) -> ChildActorFut<'_>
Auto Trait Implementations§
impl !RefUnwindSafe for Endpoint
impl !UnwindSafe for Endpoint
impl Freeze for Endpoint
impl Send for Endpoint
impl Sync for Endpoint
impl Unpin for Endpoint
impl UnsafeUnpin for Endpoint
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Message for T
impl<T> Message for T
Source§fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>
fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>
cluster only.Source§fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>
fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>
cluster only.