-
Notifications
You must be signed in to change notification settings - Fork 163
Update libp2p to v0.43.0 #499
Changes from 1 commit
f601b8d
c3a48c9
4e5ff4d
918d4d8
c1a5bba
7e9da72
085be77
e4002d6
a996922
bdf977c
93b31b3
25c8d58
3b59193
31262b5
6c6fc3d
77291ee
888e6f1
72ff95d
1cee67d
897c16f
d4d3def
87a4114
82453e5
277954b
50ad10f
081a598
bf7a807
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -322,27 +322,6 @@ impl NetworkBehaviour for SwarmApi { | |||||||||
// we were not dialing to the peer, thus we cannot have a pending subscription to | ||||||||||
// finish. | ||||||||||
} | ||||||||||
|
||||||||||
trace!("inject_disconnected: {}", peer_id); | ||||||||||
assert!(!self.connected_peers.contains_key(peer_id)); | ||||||||||
self.roundtrip_times.remove(peer_id); | ||||||||||
|
||||||||||
let failed = self | ||||||||||
.pending_addresses | ||||||||||
.remove(peer_id) | ||||||||||
.unwrap_or_default() | ||||||||||
.into_iter() | ||||||||||
.chain( | ||||||||||
self.pending_connections | ||||||||||
.remove(peer_id) | ||||||||||
.unwrap_or_default() | ||||||||||
.into_iter(), | ||||||||||
); | ||||||||||
|
||||||||||
for addr in failed { | ||||||||||
self.connect_registry | ||||||||||
.finish_subscription(addr.into(), Err("disconnected".into())); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
fn inject_event(&mut self, _peer_id: PeerId, _connection: ConnectionId, _event: void::Void) {} | ||||||||||
|
@@ -353,33 +332,43 @@ impl NetworkBehaviour for SwarmApi { | |||||||||
_handler: Self::ConnectionHandler, | ||||||||||
error: &DialError, | ||||||||||
) { | ||||||||||
trace!("inject_dial_failure: {:?} ({})", peer_id, error); | ||||||||||
if let Some(peer_id) = peer_id { | ||||||||||
if self.pending_addresses.contains_key(&peer_id) { | ||||||||||
// it is possible that these addresses have not been tried yet; they will be asked | ||||||||||
// for soon. | ||||||||||
let handler = self.new_handler(); | ||||||||||
self.events.push_back(swarm::NetworkBehaviourAction::Dial { | ||||||||||
opts: DialOpts::peer_id(peer_id) | ||||||||||
.condition(PeerCondition::NotDialing) | ||||||||||
.build(), | ||||||||||
handler, | ||||||||||
}); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
if let Some(peer_id) = peer_id { | ||||||||||
match self.pending_connections.entry(peer_id) { | ||||||||||
Entry::Occupied(mut oe) => { | ||||||||||
let addresses = oe.get_mut(); | ||||||||||
let addr = MultiaddrWithPeerId::try_from(addr.clone()) | ||||||||||
.expect("dialed address contains peerid in libp2p 0.38"); | ||||||||||
let pos = addresses.iter().position(|a| *a == addr); | ||||||||||
|
||||||||||
if let Some(pos) = pos { | ||||||||||
addresses.swap_remove(pos); | ||||||||||
self.connect_registry | ||||||||||
.finish_subscription(addr.into(), Err(error.to_string())); | ||||||||||
match error { | ||||||||||
DialError::Transport(multiaddrs) => { | ||||||||||
for (addr, error) in multiaddrs { | ||||||||||
let addr = MultiaddrWithPeerId::try_from(addr.clone()) | ||||||||||
.expect("to recieve an MultiAddrWithPeerId from DialError"); | ||||||||||
self.connect_registry | ||||||||||
.finish_subscription(addr.into(), Err(error.to_string())); | ||||||||||
} | ||||||||||
|
||||||||||
let peer_ids = multiaddrs | ||||||||||
.into_iter() | ||||||||||
.map(|(addr, _err)| { | ||||||||||
MultiaddrWithPeerId::try_from(addr.clone()).unwrap() | ||||||||||
}) | ||||||||||
.collect::<Vec<_>>(); | ||||||||||
|
||||||||||
addresses.retain(|peer_id| peer_ids.iter().any(|id| peer_id == id)); | ||||||||||
rand0m-cloud marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
} | ||||||||||
DialError::WrongPeerId { | ||||||||||
obtained: _, | ||||||||||
endpoint: _, | ||||||||||
} => { | ||||||||||
rand0m-cloud marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
for addr in addresses.iter() { | ||||||||||
self.connect_registry.finish_subscription( | ||||||||||
addr.clone().into(), | ||||||||||
Err(error.to_string()), | ||||||||||
); | ||||||||||
} | ||||||||||
|
||||||||||
addresses.clear(); | ||||||||||
} | ||||||||||
err => trace!("unhandled DialError {}", err), | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we trace every DialError? Was thinking about the WrongPeerId failure above and I'm not sure if it would otherwise be reported to the user. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would probably go with
Suggested change
|
||||||||||
} | ||||||||||
|
||||||||||
if addresses.is_empty() { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should test this as well, wondering about the lack of new dial attempt. |
||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error is behind a borrow so cannot take ownership here. I was going to ask about the
addr.clone()
on line 352 but this explains it.However ... This vec building seems extra because we are already handling a failure to dial a specific peer, and we only allow connect's to
MultiaddrWithPeerId
on line 97 withpub fn connect(&mut self, addr: MultiaddrWithPeerId) -> ...
.So perhaps it would be better to remove from
addresses
with in thefinish_subscription
loop above. It will need to be position based swap remove.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I will update it with your suggestion of using
swap_remove
. My only hesitation come from reading the docs on it and seeing it moves elements to replace the gap. I have no idea what is actually better, my intuition said theretain
was better because it described what I wanted instead how I wanted it done.