Skip to content

Commit fb8548b

Browse files
committed
Apply review comments
1 parent da2bafd commit fb8548b

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

mithril-relay/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
//! Mithril relay modules
44
55
mod commands;
6-
mod p2p;
6+
/// Peer to peer module
7+
pub mod p2p;
78
mod relay;
89

910
pub use commands::RelayCommands;
10-
pub use p2p::*;
1111
pub use relay::AggregatorRelay;
1212
pub use relay::PassiveRelay;
1313
pub use relay::SignerRelay;

mithril-relay/src/p2p/peer.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![allow(missing_docs)]
2-
use anyhow::Context;
2+
use anyhow::{anyhow, Context};
33
use libp2p::{
44
core::upgrade::Version,
55
futures::StreamExt,
@@ -12,7 +12,7 @@ use mithril_common::{messages::RegisterSignatureMessage, StdResult};
1212
use slog_scope::{debug, info};
1313
use std::{collections::HashMap, time::Duration};
1414

15-
use crate::{PeerError, MITHRIL_SIGNATURES_TOPIC_NAME};
15+
use crate::{p2p::PeerError, MITHRIL_SIGNATURES_TOPIC_NAME};
1616

1717
/// Custom network behaviour
1818
#[derive(NetworkBehaviour)]
@@ -177,7 +177,11 @@ impl Peer {
177177
.topics
178178
.get(MITHRIL_SIGNATURES_TOPIC_NAME)
179179
.ok_or(PeerError::MissingTopic())
180-
.with_context(|| "Can not publish signature on invalid topic")?
180+
.with_context(|| {
181+
format!(
182+
"Can not publish signature on invalid topic: {MITHRIL_SIGNATURES_TOPIC_NAME}"
183+
)
184+
})?
181185
.to_owned();
182186
let data = serde_json::to_vec(message)
183187
.with_context(|| "Can not publish signature with invalid format")?;
@@ -196,9 +200,12 @@ impl Peer {
196200
/// Connect to a remote peer
197201
pub fn dial(&mut self, addr: Multiaddr) -> StdResult<()> {
198202
debug!("Peer: dialing to"; "address" => format!("{addr:?}"), "local_peer_id" => format!("{:?}", self.local_peer_id()));
199-
self.swarm.as_mut().unwrap().dial(addr)?;
200-
201-
Ok(())
203+
self.swarm
204+
.as_mut()
205+
.ok_or(PeerError::UnavailableSwarm())
206+
.with_context(|| "Can not dial without swarm")?
207+
.dial(addr)
208+
.map_err(|e| anyhow!(e))
202209
}
203210

204211
/// Get the local peer id (if any)

mithril-relay/tests/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::sync::Arc;
22

33
use libp2p::{gossipsub, Multiaddr};
44
use mithril_common::messages::RegisterSignatureMessage;
5-
use mithril_relay::{PassiveRelay, PeerBehaviourEvent, PeerEvent, SignerRelay};
5+
use mithril_relay::{p2p::PeerBehaviourEvent, p2p::PeerEvent, PassiveRelay, SignerRelay};
66
use reqwest::StatusCode;
77
use slog::{Drain, Level, Logger};
88
use slog_scope::info;

0 commit comments

Comments
 (0)