Return errors instead of panic in libp2p

This commit is contained in:
Paul Hauner 2019-06-10 21:37:41 -04:00
parent e550c0218f
commit 059699736b
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C

View File

@ -57,7 +57,10 @@ impl Service {
}; };
// listen on all addresses // listen on all addresses
for address in config.listen_addresses().expect("invalid listen multiaddr") { for address in config
.listen_addresses()
.map_err(|e| format!("Invalid listen multiaddr: {}", e))?
{
match Swarm::listen_on(&mut swarm, address.clone()) { match Swarm::listen_on(&mut swarm, address.clone()) {
Ok(mut listen_addr) => { Ok(mut listen_addr) => {
listen_addr.append(Protocol::P2p(local_peer_id.clone().into())); listen_addr.append(Protocol::P2p(local_peer_id.clone().into()));
@ -68,7 +71,10 @@ impl Service {
} }
// connect to boot nodes - these are currently stored as multiaddrs // connect to boot nodes - these are currently stored as multiaddrs
// Once we have discovery, can set to peerId // Once we have discovery, can set to peerId
for bootnode in config.boot_nodes().expect("invalid boot node multiaddr") { for bootnode in config
.boot_nodes()
.map_err(|e| format!("Invalid boot node multiaddr: {:?}", e))?
{
match Swarm::dial_addr(&mut swarm, bootnode.clone()) { match Swarm::dial_addr(&mut swarm, bootnode.clone()) {
Ok(()) => debug!(log, "Dialing bootnode: {}", bootnode), Ok(()) => debug!(log, "Dialing bootnode: {}", bootnode),
Err(err) => debug!( Err(err) => debug!(