Skip to content

Commit

Permalink
PR review:
Browse files Browse the repository at this point in the history
- make IrohServerEndpoint public
- use ..self in builder where possible and update comments
  • Loading branch information
rklaehn committed Jul 5, 2024
1 parent 2441393 commit 1b39332
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 33 deletions.
5 changes: 4 additions & 1 deletion iroh/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ pub use self::builder::{Builder, DiscoveryConfig, DocsStorage, GcPolicy, Storage
pub use self::rpc_status::RpcStatus;
pub use protocol::ProtocolHandler;

type IrohServerEndpoint = quic_rpc::transport::boxed::ServerEndpoint<
/// The quic-rpc server endpoint for the iroh node.
///
/// We use a boxed endpoint here to allow having a concrete type for the server endpoint.
pub type IrohServerEndpoint = quic_rpc::transport::boxed::ServerEndpoint<
crate::rpc_protocol::Request,
crate::rpc_protocol::Response,
>;
Expand Down
39 changes: 7 additions & 32 deletions iroh/src/node/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,53 +301,28 @@ where
})
}

/// Configure rpc endpoint, changing the type of the builder to the new endpoint type.
pub fn rpc_endpoint(self, value: IrohServerEndpoint, port: Option<u16>) -> Builder<D> {
// we can't use ..self here because the return type is different
Builder {
storage: self.storage,
bind_port: self.bind_port,
secret_key: self.secret_key,
blobs_store: self.blobs_store,
keylog: self.keylog,
/// Configure rpc endpoint.
pub fn rpc_endpoint(self, value: IrohServerEndpoint, port: Option<u16>) -> Self {
Self {
rpc_endpoint: value,
rpc_port: port,
relay_mode: self.relay_mode,
dns_resolver: self.dns_resolver,
gc_policy: self.gc_policy,
docs_storage: self.docs_storage,
node_discovery: self.node_discovery,
#[cfg(any(test, feature = "test-utils"))]
insecure_skip_relay_cert_verify: self.insecure_skip_relay_cert_verify,
gc_done_callback: self.gc_done_callback,
..self
}
}

/// Configure the default iroh rpc endpoint.
pub async fn enable_rpc(self) -> Result<Builder<D>> {
pub async fn enable_rpc(self) -> Result<Self> {
let (ep, actual_rpc_port) = make_rpc_endpoint(&self.secret_key, DEFAULT_RPC_PORT)?;
let ep = quic_rpc::transport::boxed::ServerEndpoint::new(ep);
if let StorageConfig::Persistent(ref root) = self.storage {
// store rpc endpoint
RpcStatus::store(root, actual_rpc_port).await?;
}

Ok(Builder {
storage: self.storage,
bind_port: self.bind_port,
secret_key: self.secret_key,
blobs_store: self.blobs_store,
keylog: self.keylog,
Ok(Self {
rpc_endpoint: ep,
rpc_port: Some(actual_rpc_port),
relay_mode: self.relay_mode,
dns_resolver: self.dns_resolver,
gc_policy: self.gc_policy,
docs_storage: self.docs_storage,
node_discovery: self.node_discovery,
#[cfg(any(test, feature = "test-utils"))]
insecure_skip_relay_cert_verify: self.insecure_skip_relay_cert_verify,
gc_done_callback: self.gc_done_callback,
..self
})
}

Expand Down

0 comments on commit 1b39332

Please sign in to comment.