1
1
#![ allow( missing_docs) ]
2
- use anyhow:: Context ;
2
+ use anyhow:: { anyhow , Context } ;
3
3
use libp2p:: {
4
4
core:: upgrade:: Version ,
5
5
futures:: StreamExt ,
@@ -12,7 +12,7 @@ use mithril_common::{messages::RegisterSignatureMessage, StdResult};
12
12
use slog_scope:: { debug, info} ;
13
13
use std:: { collections:: HashMap , time:: Duration } ;
14
14
15
- use crate :: { PeerError , MITHRIL_SIGNATURES_TOPIC_NAME } ;
15
+ use crate :: { p2p :: PeerError , MITHRIL_SIGNATURES_TOPIC_NAME } ;
16
16
17
17
/// Custom network behaviour
18
18
#[ derive( NetworkBehaviour ) ]
@@ -177,7 +177,11 @@ impl Peer {
177
177
. topics
178
178
. get ( MITHRIL_SIGNATURES_TOPIC_NAME )
179
179
. 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
+ } ) ?
181
185
. to_owned ( ) ;
182
186
let data = serde_json:: to_vec ( message)
183
187
. with_context ( || "Can not publish signature with invalid format" ) ?;
@@ -196,9 +200,12 @@ impl Peer {
196
200
/// Connect to a remote peer
197
201
pub fn dial ( & mut self , addr : Multiaddr ) -> StdResult < ( ) > {
198
202
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) )
202
209
}
203
210
204
211
/// Get the local peer id (if any)
0 commit comments