Skip to content

Commit

Permalink
Expose endpoint (#1790)
Browse files Browse the repository at this point in the history
## Description

Expose the endpoint on the iroh node for some advanced use cases, as
discussed yesterday.

## Questions and remarks

Question: There are some fns on the node that just forward fields from
the endpoint. Should they be removed now that the endpoint is public, or
removed and moved into the NodeClient?

```rust

    /// Return the [`NodeAddr`] for this node.
    pub async fn my_addr(&self) -> Result<NodeAddr> {
        self.inner.endpoint.my_addr().await
    }

    /// Get the DERP region we are connected to.
    pub fn my_derp(&self) -> Option<u16> {
        self.inner.endpoint.my_derp()
    }
```

Remark: Also removed a type parameter bound that was not needed and
looked weird.

---------

Co-authored-by: Friedel Ziegelmayer <[email protected]>
  • Loading branch information
rklaehn and dignifiedquire authored Nov 10, 2023
1 parent 53f1b61 commit b68193a
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions iroh/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ impl iroh_bytes::provider::EventSender for Callbacks {
/// await the [`Node`] struct directly, it will complete when the task completes. If
/// this is dropped the node task is not stopped but keeps running.
#[derive(Debug, Clone)]
pub struct Node<D: Map> {
pub struct Node<D> {
inner: Arc<NodeInner<D>>,
task: Shared<BoxFuture<'static, Result<(), Arc<JoinError>>>>,
}
Expand Down Expand Up @@ -699,6 +699,15 @@ impl<D: ReadableStore> Node<D> {
Builder::with_db_and_store(bao_store, doc_store)
}

/// Returns the [`MagicEndpoint`] of the node.
///
/// This can be used to establish connections to other nodes under any
/// ALPNs other than the iroh internal ones. This is useful for some advanced
/// use cases.
pub fn magic_endpoint(&self) -> &MagicEndpoint {
&self.inner.endpoint
}

/// The address on which the node socket is bound.
///
/// Note that this could be an unspecified address, if you need an address on which you
Expand Down Expand Up @@ -781,7 +790,7 @@ impl<D: ReadableStore> Node<D> {
}
}

impl<D: Map> NodeInner<D> {
impl<D> NodeInner<D> {
async fn local_endpoints(&self) -> Result<Vec<Endpoint>> {
self.endpoint.local_endpoints().await
}
Expand All @@ -802,7 +811,7 @@ impl<D: Map> NodeInner<D> {
}

/// The future completes when the spawned tokio task finishes.
impl<D: Map> Future for Node<D> {
impl<D> Future for Node<D> {
type Output = Result<(), Arc<JoinError>>;

fn poll(mut self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll<Self::Output> {
Expand Down

0 comments on commit b68193a

Please sign in to comment.