mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-20 05:16:35 +00:00
Full support for multiple connections per peer in libp2p-swarm. (#1519)
* [libp2p-swarm] Make the multiple connections per peer first-class. This commit makes the notion of multiple connections per peer first-class in the API of libp2p-swarm, introducing the new callbacks `inject_connection_established` and `inject_connection_closed`. The `endpoint` parameter from `inject_connected` and `inject_disconnected` is removed, since the first connection to open may not be the last connection to close, i.e. it cannot be guaranteed, as was previously the case, that the endpoints passed to these callbacks match up. * Have identify track all addresses. So that identify requests can be answered with the correct observed address of the connection on which the request arrives. * Cleanup * Cleanup * Improve the `Peer` state API. * Remove connection ID from `SwarmEvent::Dialing`. * Mark `DialPeerCondition` non-exhaustive. * Re-encapsulate `NetworkConfig`. To retain the possibility of not re-exposing all network configuration choices, thereby providing a more convenient API on the \`SwarmBuilder\`. * Rework Swarm::dial API. * Update CHANGELOG. * Doc formatting tweaks.
This commit is contained in:
@ -27,7 +27,7 @@ use crate::protocol::{
|
||||
};
|
||||
use crate::topic::{Topic, TopicHash};
|
||||
use futures::prelude::*;
|
||||
use libp2p_core::{ConnectedPoint, Multiaddr, PeerId, connection::ConnectionId};
|
||||
use libp2p_core::{Multiaddr, PeerId, connection::ConnectionId};
|
||||
use libp2p_swarm::{
|
||||
NetworkBehaviour,
|
||||
NetworkBehaviourAction,
|
||||
@ -1012,7 +1012,7 @@ impl NetworkBehaviour for Gossipsub {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
fn inject_connected(&mut self, id: PeerId, _: ConnectedPoint) {
|
||||
fn inject_connected(&mut self, id: &PeerId) {
|
||||
info!("New peer connected: {:?}", id);
|
||||
// We need to send our subscriptions to the newly-connected node.
|
||||
let mut subscriptions = vec![];
|
||||
@ -1040,7 +1040,7 @@ impl NetworkBehaviour for Gossipsub {
|
||||
self.peer_topics.insert(id.clone(), Vec::new());
|
||||
}
|
||||
|
||||
fn inject_disconnected(&mut self, id: &PeerId, _: ConnectedPoint) {
|
||||
fn inject_disconnected(&mut self, id: &PeerId) {
|
||||
// remove from mesh, topic_peers, peer_topic and fanout
|
||||
debug!("Peer disconnected: {:?}", id);
|
||||
{
|
||||
@ -1164,8 +1164,8 @@ impl NetworkBehaviour for Gossipsub {
|
||||
NetworkBehaviourAction::DialAddress { address } => {
|
||||
return Poll::Ready(NetworkBehaviourAction::DialAddress { address });
|
||||
}
|
||||
NetworkBehaviourAction::DialPeer { peer_id } => {
|
||||
return Poll::Ready(NetworkBehaviourAction::DialPeer { peer_id });
|
||||
NetworkBehaviourAction::DialPeer { peer_id, condition } => {
|
||||
return Poll::Ready(NetworkBehaviourAction::DialPeer { peer_id, condition });
|
||||
}
|
||||
NetworkBehaviourAction::ReportObservedAddr { address } => {
|
||||
return Poll::Ready(NetworkBehaviourAction::ReportObservedAddr { address });
|
||||
|
Reference in New Issue
Block a user