mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-07-02 11:11:36 +00:00
feat(swarm): rename NetworkBehaviourAction
to ToSwarm
Resolves #3123. Pull-Request: #3658.
This commit is contained in:
@ -26,8 +26,8 @@ use libp2p_identity::PublicKey;
|
||||
use libp2p_swarm::behaviour::{ConnectionClosed, ConnectionEstablished, DialFailure, FromSwarm};
|
||||
use libp2p_swarm::{
|
||||
dial_opts::DialOpts, AddressScore, ConnectionDenied, ConnectionHandlerUpgrErr, DialError,
|
||||
ExternalAddresses, ListenAddresses, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler,
|
||||
PollParameters, THandlerInEvent,
|
||||
ExternalAddresses, ListenAddresses, NetworkBehaviour, NotifyHandler, PollParameters,
|
||||
THandlerInEvent, ToSwarm,
|
||||
};
|
||||
use libp2p_swarm::{ConnectionId, THandler, THandlerOutEvent};
|
||||
use lru::LruCache;
|
||||
@ -44,7 +44,7 @@ use std::{
|
||||
/// about them, and answers identify queries from other nodes.
|
||||
///
|
||||
/// All external addresses of the local node supposedly observed by remotes
|
||||
/// are reported via [`NetworkBehaviourAction::ReportObservedAddr`] with a
|
||||
/// are reported via [`ToSwarm::ReportObservedAddr`] with a
|
||||
/// [score](AddressScore) of `1`.
|
||||
pub struct Behaviour {
|
||||
config: Config,
|
||||
@ -55,7 +55,7 @@ pub struct Behaviour {
|
||||
/// with current information about the local peer.
|
||||
requests: Vec<Request>,
|
||||
/// Pending events to be emitted when polled.
|
||||
events: VecDeque<NetworkBehaviourAction<Event, InEvent>>,
|
||||
events: VecDeque<ToSwarm<Event, InEvent>>,
|
||||
/// The addresses of all peers that we have discovered.
|
||||
discovered_peers: PeerCache,
|
||||
|
||||
@ -200,7 +200,7 @@ impl Behaviour {
|
||||
if !self.requests.contains(&request) {
|
||||
self.requests.push(request);
|
||||
|
||||
self.events.push_back(NetworkBehaviourAction::Dial {
|
||||
self.events.push_back(ToSwarm::Dial {
|
||||
opts: DialOpts::peer_id(p).build(),
|
||||
});
|
||||
}
|
||||
@ -293,27 +293,19 @@ impl NetworkBehaviour for Behaviour {
|
||||
|
||||
let observed = info.observed_addr.clone();
|
||||
self.events
|
||||
.push_back(NetworkBehaviourAction::GenerateEvent(Event::Received {
|
||||
peer_id,
|
||||
info,
|
||||
}));
|
||||
self.events
|
||||
.push_back(NetworkBehaviourAction::ReportObservedAddr {
|
||||
address: observed,
|
||||
score: AddressScore::Finite(1),
|
||||
});
|
||||
.push_back(ToSwarm::GenerateEvent(Event::Received { peer_id, info }));
|
||||
self.events.push_back(ToSwarm::ReportObservedAddr {
|
||||
address: observed,
|
||||
score: AddressScore::Finite(1),
|
||||
});
|
||||
}
|
||||
handler::Event::Identification(peer) => {
|
||||
self.events
|
||||
.push_back(NetworkBehaviourAction::GenerateEvent(Event::Sent {
|
||||
peer_id: peer,
|
||||
}));
|
||||
.push_back(ToSwarm::GenerateEvent(Event::Sent { peer_id: peer }));
|
||||
}
|
||||
handler::Event::IdentificationPushed => {
|
||||
self.events
|
||||
.push_back(NetworkBehaviourAction::GenerateEvent(Event::Pushed {
|
||||
peer_id,
|
||||
}));
|
||||
.push_back(ToSwarm::GenerateEvent(Event::Pushed { peer_id }));
|
||||
}
|
||||
handler::Event::Identify => {
|
||||
self.requests.push(Request {
|
||||
@ -323,10 +315,7 @@ impl NetworkBehaviour for Behaviour {
|
||||
}
|
||||
handler::Event::IdentificationError(error) => {
|
||||
self.events
|
||||
.push_back(NetworkBehaviourAction::GenerateEvent(Event::Error {
|
||||
peer_id,
|
||||
error,
|
||||
}));
|
||||
.push_back(ToSwarm::GenerateEvent(Event::Error { peer_id, error }));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -335,7 +324,7 @@ impl NetworkBehaviour for Behaviour {
|
||||
&mut self,
|
||||
_cx: &mut Context<'_>,
|
||||
params: &mut impl PollParameters,
|
||||
) -> Poll<NetworkBehaviourAction<Self::OutEvent, THandlerInEvent<Self>>> {
|
||||
) -> Poll<ToSwarm<Self::OutEvent, THandlerInEvent<Self>>> {
|
||||
if let Some(event) = self.events.pop_front() {
|
||||
return Poll::Ready(event);
|
||||
}
|
||||
@ -345,7 +334,7 @@ impl NetworkBehaviour for Behaviour {
|
||||
Some(Request {
|
||||
peer_id,
|
||||
protocol: Protocol::Push,
|
||||
}) => Poll::Ready(NetworkBehaviourAction::NotifyHandler {
|
||||
}) => Poll::Ready(ToSwarm::NotifyHandler {
|
||||
peer_id,
|
||||
handler: NotifyHandler::Any,
|
||||
event: InEvent {
|
||||
@ -362,7 +351,7 @@ impl NetworkBehaviour for Behaviour {
|
||||
Some(Request {
|
||||
peer_id,
|
||||
protocol: Protocol::Identify(connection_id),
|
||||
}) => Poll::Ready(NetworkBehaviourAction::NotifyHandler {
|
||||
}) => Poll::Ready(ToSwarm::NotifyHandler {
|
||||
peer_id,
|
||||
handler: NotifyHandler::One(connection_id),
|
||||
event: InEvent {
|
||||
|
Reference in New Issue
Block a user