Skip to content

refactor: improve module structure after irpc port #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: Frando/irpc
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use ed25519_dalek::Signature;
use futures_lite::StreamExt;
use iroh::{Endpoint, NodeAddr, PublicKey, RelayMode, RelayUrl, SecretKey};
use iroh_gossip::{
net::{Event, Gossip, GossipEvent, GossipReceiver, GOSSIP_ALPN},
api::{Event, GossipEvent, GossipReceiver},
net::{Gossip, GOSSIP_ALPN},
proto::TopicId,
};
use n0_future::task;
Expand Down
3 changes: 2 additions & 1 deletion src/net/handles.rs → src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ mod tests {
use rand::SeedableRng;

use crate::{
net::{test::create_endpoint, Event, Gossip, GossipApi, GossipEvent},
api::{Event, GossipApi, GossipEvent},
net::{test::create_endpoint, Gossip},
proto::TopicId,
ALPN,
};
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#[doc(inline)]
pub use net::GOSSIP_ALPN as ALPN;

#[cfg(any(feature = "net", feature = "rpc"))]
pub mod api;
pub mod metrics;
#[cfg(feature = "net")]
pub mod net;
Expand Down
15 changes: 7 additions & 8 deletions src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use anyhow::Context as _;
use bytes::BytesMut;
use futures_concurrency::stream::{stream_group, StreamGroup};
use futures_util::FutureExt as _;
use handles::RpcMessage;
use iroh::{
endpoint::{Connection, DirectAddr},
protocol::ProtocolHandler,
Expand All @@ -32,16 +31,16 @@ use tokio::sync::{broadcast, mpsc, oneshot};
use tokio_util::sync::CancellationToken;
use tracing::{debug, error, error_span, trace, warn, Instrument};

pub use self::handles::{Command, Event, GossipApi, GossipEvent, GossipReceiver, GossipSender};
use self::util::{read_message, write_message, Timers};
use crate::{
metrics::Metrics,
proto::{self, HyparviewConfig, PeerData, PlumtreeConfig, Scope, TopicId},
};

pub mod handles;
pub mod util;

use crate::api::{self, Command, Event, GossipApi, GossipEvent};

/// ALPN protocol name
pub const GOSSIP_ALPN: &[u8] = b"/iroh-gossip/0";

Expand Down Expand Up @@ -327,7 +326,7 @@ struct Actor {
/// Dial machine to connect to peers
dialer: Dialer,
/// Input messages to the actor
rpc_rx: mpsc::Receiver<RpcMessage>,
rpc_rx: mpsc::Receiver<api::RpcMessage>,
local_rx: mpsc::Receiver<LocalActorMessage>,
/// Sender for the state input (cloned into the connection loops)
in_event_tx: mpsc::Sender<InEvent>,
Expand Down Expand Up @@ -357,7 +356,7 @@ impl Actor {
my_addr: &AddrInfo,
) -> (
Self,
mpsc::Sender<RpcMessage>,
mpsc::Sender<api::RpcMessage>,
mpsc::Sender<LocalActorMessage>,
) {
let peer_id = endpoint.node_id();
Expand Down Expand Up @@ -675,18 +674,18 @@ impl Actor {
Ok(())
}

async fn handle_rpc_msg(&mut self, msg: RpcMessage, now: Instant) -> Result<(), Error> {
async fn handle_rpc_msg(&mut self, msg: api::RpcMessage, now: Instant) -> Result<(), Error> {
trace!("handle to_actor {msg:?}");
match msg {
RpcMessage::Join(msg) => {
api::RpcMessage::Join(msg) => {
let WithChannels {
inner,
rx,
mut tx,
// TODO(frando): make use of span?
span: _,
} = msg;
let handles::JoinRequest {
let api::JoinRequest {
topic_id,
bootstrap,
} = inner;
Expand Down
Loading