Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(swarm): rename associated types for message passing #3848

Merged
merged 51 commits into from
May 14, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
3c90727
NetworkBehaviour OutEvent to ToSwarm
tcoratger Apr 28, 2023
1e48a41
ConnectionHandler InEvent to FromSwarm
tcoratger Apr 28, 2023
84120ad
changelog comment and update version in Cargo.toml
tcoratger Apr 28, 2023
9a83710
clean up
tcoratger Apr 28, 2023
978b422
typo fix
tcoratger Apr 28, 2023
13f1ef4
changelog revert
tcoratger Apr 28, 2023
11f0399
correcting typo in changelog
tcoratger Apr 28, 2023
cf429c0
remove spurious spaces in changelog
tcoratger Apr 28, 2023
944ad04
change ConnectionHandler FromSwarm to FromBehaviour
tcoratger Apr 28, 2023
7366138
clean up and merge
tcoratger May 2, 2023
4b9d1ad
Merge branch 'master' into swarm-behaviour-handler
tcoratger May 2, 2023
c77045c
add changelog in libp2p crate
tcoratger May 2, 2023
18c808a
update doc of FromBehaviour and ToBehaviour in ConnectionHandler
tcoratger May 2, 2023
3b53770
Rename out_event to to_swarm and deprecate out_event
tcoratger May 2, 2023
6487f6b
merge and clean
tcoratger May 2, 2023
cb13c2b
Merge branch 'master' into swarm-behaviour-handler
tcoratger May 2, 2023
5d1f63a
clean up waste
tcoratger May 2, 2023
736390a
fix rustdoc link in swarm behaviour
tcoratger May 2, 2023
9cdfc15
fix some ToBehaviour to ToSwarm in swarm_derive.rs
tcoratger May 2, 2023
65e6203
Merge branch 'master' into swarm-behaviour-handler
tcoratger May 2, 2023
dc3e1a2
Update swarm/src/handler.rs
tcoratger May 2, 2023
add36da
Update swarm/src/handler.rs
tcoratger May 2, 2023
7fe31ef
rename ConnectionHandlerEvent::Custom to ConnectionHandlerEvent::Noti…
tcoratger May 2, 2023
47ff802
modify doc ConnectionHandlerEvent::NotifyBehaviour
tcoratger May 2, 2023
4ac496c
add env_logger implementation for out_event deprecation warning
tcoratger May 2, 2023
cb5ca9d
Merge branch 'master' into swarm-behaviour-handler
tcoratger May 2, 2023
9886a30
rustdoc links fix for ConnectionHandler
tcoratger May 2, 2023
5fad024
swarm-derive initialize the logger only once
tcoratger May 2, 2023
ae44548
log::warn to println in swarm-derive
tcoratger May 2, 2023
f480080
clean up
tcoratger May 2, 2023
eafc2bc
clean up wrong type and change version position changelog
tcoratger May 2, 2023
a19c564
THandler::InEvent to THandler::FromBehaviour in swarm/src/test.rs
tcoratger May 2, 2023
0e28e52
fix clippy
tcoratger May 2, 2023
d88c599
deprecation warning out_event
tcoratger May 3, 2023
2e94018
Merge branch 'master' into swarm-behaviour-handler
tcoratger May 3, 2023
5d3ac92
try out_event deprecation with quote
tcoratger May 3, 2023
2964ca6
Merge branch 'master' into swarm-behaviour-handler
tcoratger May 4, 2023
a3c5e11
Remove deprecated out-event check
thomaseizinger May 4, 2023
8fde04f
Rename final event
thomaseizinger May 4, 2023
e0ddea6
merge with master
tcoratger May 11, 2023
a5c2598
fix break
tcoratger May 11, 2023
c27766a
params to _
tcoratger May 11, 2023
7e95c4b
try proc_macro_warning
tcoratger May 11, 2023
6f32b98
Merge branch 'master' into swarm-behaviour-handler
tcoratger May 13, 2023
5eb5258
add deprecation warning implementation for out_event
tcoratger May 13, 2023
860ed35
clean up
tcoratger May 13, 2023
6fec637
fix clippy
tcoratger May 13, 2023
56b6b9c
fix clippy
tcoratger May 13, 2023
722e9ea
Add test for produced warning
thomaseizinger May 14, 2023
25deeb9
Update deprecation message
thomaseizinger May 14, 2023
d7ef8d6
Merge branch 'master' into swarm-behaviour-handler
mergify[bot] May 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@
superflucious. Both are removed in favor of a derivation through `THandler`
(see [PR 2183]).

- Require `ConnectionHandler::{InEvent,OutEvent,Error}` to implement `Debug`
- Require `ConnectionHandler::{InEvent,ToBehaviour ,Error}` to implement `Debug`
tcoratger marked this conversation as resolved.
Show resolved Hide resolved
(see [PR 2183]).

- Remove `DisconnectedPeer::set_connected` and `Pool::add` (see [PR 2195]).
Expand Down
4 changes: 2 additions & 2 deletions misc/allow-block-list/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ where
S: Enforce,
{
type ConnectionHandler = dummy::ConnectionHandler;
type OutEvent = Void;
type ToSwarm = Void;

fn handle_established_inbound_connection(
&mut self,
Expand Down Expand Up @@ -261,7 +261,7 @@ where
&mut self,
cx: &mut Context<'_>,
_: &mut impl PollParameters,
) -> Poll<ToSwarm<Self::OutEvent, THandlerInEvent<Self>>> {
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
if let Some(peer) = self.close_connections.pop_front() {
return Poll::Ready(ToSwarm::CloseConnection {
peer_id: peer,
Expand Down
4 changes: 2 additions & 2 deletions misc/connection-limits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl ConnectionLimits {

impl NetworkBehaviour for Behaviour {
type ConnectionHandler = dummy::ConnectionHandler;
type OutEvent = Void;
type ToSwarm = Void;

fn handle_pending_inbound_connection(
&mut self,
Expand Down Expand Up @@ -355,7 +355,7 @@ impl NetworkBehaviour for Behaviour {
&mut self,
_: &mut Context<'_>,
_: &mut impl PollParameters,
) -> Poll<ToSwarm<Self::OutEvent, THandlerInEvent<Self>>> {
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
Poll::Pending
}
}
Expand Down
6 changes: 3 additions & 3 deletions protocols/autonat/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ pub struct Behaviour {

last_probe: Option<Instant>,

pending_actions: VecDeque<ToSwarm<<Self as NetworkBehaviour>::OutEvent, THandlerInEvent<Self>>>,
pending_actions: VecDeque<ToSwarm<<Self as NetworkBehaviour>::ToSwarm, THandlerInEvent<Self>>>,

probe_id: ProbeId,

Expand Down Expand Up @@ -426,7 +426,7 @@ impl Behaviour {
impl NetworkBehaviour for Behaviour {
type ConnectionHandler =
<request_response::Behaviour<AutoNatCodec> as NetworkBehaviour>::ConnectionHandler;
type OutEvent = Event;
type ToSwarm = Event;

fn poll(&mut self, cx: &mut Context<'_>, params: &mut impl PollParameters) -> Poll<Action> {
loop {
Expand Down Expand Up @@ -593,7 +593,7 @@ impl NetworkBehaviour for Behaviour {
}
}

type Action = ToSwarm<<Behaviour as NetworkBehaviour>::OutEvent, THandlerInEvent<Behaviour>>;
type Action = ToSwarm<<Behaviour as NetworkBehaviour>::ToSwarm, THandlerInEvent<Behaviour>>;

// Trait implemented for `AsClient` and `AsServer` to handle events from the inner [`request_response::Behaviour`] Protocol.
trait HandleInnerEvent {
Expand Down
4 changes: 2 additions & 2 deletions protocols/dcutr/src/behaviour_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ impl NetworkBehaviour for Behaviour {
handler::relayed::Handler,
Either<handler::direct::Handler, dummy::ConnectionHandler>,
>;
type OutEvent = Event;
type ToSwarm = Event;

fn handle_established_inbound_connection(
&mut self,
Expand Down Expand Up @@ -417,7 +417,7 @@ impl NetworkBehaviour for Behaviour {
&mut self,
_cx: &mut Context<'_>,
_: &mut impl PollParameters,
) -> Poll<ToSwarm<Self::OutEvent, THandlerInEvent<Self>>> {
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
if let Some(event) = self.queued_events.pop_front() {
return Poll::Ready(event);
}
Expand Down
8 changes: 4 additions & 4 deletions protocols/dcutr/src/handler/direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ pub struct Handler {
}

impl ConnectionHandler for Handler {
type InEvent = void::Void;
type OutEvent = Event;
type FromSwarm = void::Void;
tcoratger marked this conversation as resolved.
Show resolved Hide resolved
type ToBehaviour = Event;
type Error = ConnectionHandlerUpgrErr<std::io::Error>;
type InboundProtocol = DeniedUpgrade;
type OutboundProtocol = DeniedUpgrade;
Expand All @@ -52,7 +52,7 @@ impl ConnectionHandler for Handler {
SubstreamProtocol::new(DeniedUpgrade, ())
}

fn on_behaviour_event(&mut self, _: Self::InEvent) {}
fn on_behaviour_event(&mut self, _: Self::FromSwarm) {}

fn connection_keep_alive(&self) -> KeepAlive {
KeepAlive::No
Expand All @@ -65,7 +65,7 @@ impl ConnectionHandler for Handler {
ConnectionHandlerEvent<
Self::OutboundProtocol,
Self::OutboundOpenInfo,
Self::OutEvent,
Self::ToBehaviour,
Self::Error,
>,
> {
Expand Down
10 changes: 5 additions & 5 deletions protocols/dcutr/src/handler/relayed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub struct Handler {
ConnectionHandlerEvent<
<Self as ConnectionHandler>::OutboundProtocol,
<Self as ConnectionHandler>::OutboundOpenInfo,
<Self as ConnectionHandler>::OutEvent,
<Self as ConnectionHandler>::ToBehaviour,
<Self as ConnectionHandler>::Error,
>,
>,
Expand Down Expand Up @@ -294,8 +294,8 @@ impl Handler {
}

impl ConnectionHandler for Handler {
type InEvent = Command;
type OutEvent = Event;
type FromSwarm = Command;
type ToBehaviour = Event;
type Error = ConnectionHandlerUpgrErr<
Either<protocol::inbound::UpgradeError, protocol::outbound::UpgradeError>,
>;
Expand All @@ -320,7 +320,7 @@ impl ConnectionHandler for Handler {
}
}

fn on_behaviour_event(&mut self, event: Self::InEvent) {
fn on_behaviour_event(&mut self, event: Self::FromSwarm) {
match event {
Command::Connect { obs_addrs, attempt } => {
self.queued_events
Expand Down Expand Up @@ -363,7 +363,7 @@ impl ConnectionHandler for Handler {
ConnectionHandlerEvent<
Self::OutboundProtocol,
Self::OutboundOpenInfo,
Self::OutEvent,
Self::ToBehaviour,
Self::Error,
>,
> {
Expand Down
4 changes: 2 additions & 2 deletions protocols/floodsub/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ impl Floodsub {

impl NetworkBehaviour for Floodsub {
type ConnectionHandler = OneShotHandler<FloodsubProtocol, FloodsubRpc, InnerMessage>;
type OutEvent = FloodsubEvent;
type ToSwarm = FloodsubEvent;

fn handle_established_inbound_connection(
&mut self,
Expand Down Expand Up @@ -470,7 +470,7 @@ impl NetworkBehaviour for Floodsub {
&mut self,
_: &mut Context<'_>,
_: &mut impl PollParameters,
) -> Poll<ToSwarm<Self::OutEvent, THandlerInEvent<Self>>> {
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
if let Some(event) = self.events.pop_front() {
return Poll::Ready(event);
}
Expand Down
4 changes: 2 additions & 2 deletions protocols/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3307,7 +3307,7 @@ where
F: Send + 'static + TopicSubscriptionFilter,
{
type ConnectionHandler = Handler;
type OutEvent = Event;
type ToSwarm = Event;

fn handle_established_inbound_connection(
&mut self,
Expand Down Expand Up @@ -3465,7 +3465,7 @@ where
&mut self,
cx: &mut Context<'_>,
_: &mut impl PollParameters,
) -> Poll<ToSwarm<Self::OutEvent, THandlerInEvent<Self>>> {
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
if let Some(event) = self.events.pop_front() {
return Poll::Ready(event);
}
Expand Down
8 changes: 4 additions & 4 deletions protocols/gossipsub/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl EnabledHandler {
ConnectionHandlerEvent<
<Handler as ConnectionHandler>::OutboundProtocol,
<Handler as ConnectionHandler>::OutboundOpenInfo,
<Handler as ConnectionHandler>::OutEvent,
<Handler as ConnectionHandler>::ToBehaviour,
<Handler as ConnectionHandler>::Error,
>,
> {
Expand Down Expand Up @@ -392,8 +392,8 @@ impl EnabledHandler {
}

impl ConnectionHandler for Handler {
type InEvent = HandlerIn;
type OutEvent = HandlerEvent;
type FromSwarm = HandlerIn;
type ToBehaviour = HandlerEvent;
type Error = Void;
type InboundOpenInfo = ();
type InboundProtocol = either::Either<ProtocolConfig, DeniedUpgrade>;
Expand Down Expand Up @@ -456,7 +456,7 @@ impl ConnectionHandler for Handler {
ConnectionHandlerEvent<
Self::OutboundProtocol,
Self::OutboundOpenInfo,
Self::OutEvent,
Self::ToBehaviour,
Self::Error,
>,
> {
Expand Down
4 changes: 2 additions & 2 deletions protocols/identify/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl Behaviour {

impl NetworkBehaviour for Behaviour {
type ConnectionHandler = Handler;
type OutEvent = Event;
type ToSwarm = Event;

fn handle_established_inbound_connection(
&mut self,
Expand Down Expand Up @@ -324,7 +324,7 @@ impl NetworkBehaviour for Behaviour {
&mut self,
_cx: &mut Context<'_>,
params: &mut impl PollParameters,
) -> Poll<ToSwarm<Self::OutEvent, THandlerInEvent<Self>>> {
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
if let Some(event) = self.events.pop_front() {
return Poll::Ready(event);
}
Expand Down
6 changes: 3 additions & 3 deletions protocols/identify/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ impl Handler {
}

impl ConnectionHandler for Handler {
type InEvent = InEvent;
type OutEvent = Event;
type FromSwarm = InEvent;
type ToBehaviour = Event;
type Error = io::Error;
type InboundProtocol = SelectUpgrade<Identify, Push<InboundPush>>;
type OutboundProtocol = Either<Identify, Push<OutboundPush>>;
Expand All @@ -240,7 +240,7 @@ impl ConnectionHandler for Handler {
listen_addrs,
supported_protocols,
protocol,
}: Self::InEvent,
}: Self::FromSwarm,
) {
let info = Info {
public_key: self.public_key.clone(),
Expand Down
4 changes: 2 additions & 2 deletions protocols/kad/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1966,7 +1966,7 @@ where
TStore: RecordStore + Send + 'static,
{
type ConnectionHandler = KademliaHandler<QueryId>;
type OutEvent = KademliaEvent;
type ToSwarm = KademliaEvent;

fn handle_established_inbound_connection(
&mut self,
Expand Down Expand Up @@ -2307,7 +2307,7 @@ where
&mut self,
cx: &mut Context<'_>,
_: &mut impl PollParameters,
) -> Poll<ToSwarm<Self::OutEvent, THandlerInEvent<Self>>> {
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
let now = Instant::now();

// Calculate the available capacity for queries triggered by background jobs.
Expand Down
6 changes: 3 additions & 3 deletions protocols/kad/src/handler_priv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,8 @@ impl<TUserData> ConnectionHandler for KademliaHandler<TUserData>
where
TUserData: Clone + fmt::Debug + Send + 'static + Unpin,
{
type InEvent = KademliaHandlerIn<TUserData>;
type OutEvent = KademliaHandlerEvent<TUserData>;
type FromSwarm = KademliaHandlerIn<TUserData>;
type ToBehaviour = KademliaHandlerEvent<TUserData>;
type Error = io::Error; // TODO: better error type?
type InboundProtocol = Either<KademliaProtocolConfig, upgrade::DeniedUpgrade>;
type OutboundProtocol = KademliaProtocolConfig;
Expand Down Expand Up @@ -727,7 +727,7 @@ where
ConnectionHandlerEvent<
Self::OutboundProtocol,
Self::OutboundOpenInfo,
Self::OutEvent,
Self::ToBehaviour,
Self::Error,
>,
> {
Expand Down
4 changes: 2 additions & 2 deletions protocols/mdns/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ where
P: Provider,
{
type ConnectionHandler = dummy::ConnectionHandler;
type OutEvent = Event;
type ToSwarm = Event;

fn handle_established_inbound_connection(
&mut self,
Expand Down Expand Up @@ -252,7 +252,7 @@ where
&mut self,
cx: &mut Context<'_>,
_: &mut impl PollParameters,
) -> Poll<ToSwarm<Self::OutEvent, THandlerInEvent<Self>>> {
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
// Poll ifwatch.
while let Poll::Ready(Some(event)) = Pin::new(&mut self.if_watch).poll_next(cx) {
match event {
Expand Down
4 changes: 2 additions & 2 deletions protocols/perf/src/client/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub enum PerfError {

impl NetworkBehaviour for Behaviour {
type ConnectionHandler = Handler;
type OutEvent = Event;
type ToSwarm = Event;

fn handle_established_outbound_connection(
&mut self,
Expand Down Expand Up @@ -147,7 +147,7 @@ impl NetworkBehaviour for Behaviour {
&mut self,
_cx: &mut Context<'_>,
_: &mut impl PollParameters,
) -> Poll<ToSwarm<Self::OutEvent, THandlerInEvent<Self>>> {
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
if let Some(event) = self.queued_events.pop_front() {
return Poll::Ready(event);
}
Expand Down
10 changes: 5 additions & 5 deletions protocols/perf/src/client/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub struct Handler {
ConnectionHandlerEvent<
<Self as ConnectionHandler>::OutboundProtocol,
<Self as ConnectionHandler>::OutboundOpenInfo,
<Self as ConnectionHandler>::OutEvent,
<Self as ConnectionHandler>::ToBehaviour,
<Self as ConnectionHandler>::Error,
>,
>,
Expand All @@ -83,8 +83,8 @@ impl Default for Handler {
}

impl ConnectionHandler for Handler {
type InEvent = Command;
type OutEvent = Event;
type FromSwarm = Command;
type ToBehaviour = Event;
type Error = Void;
type InboundProtocol = DeniedUpgrade;
type OutboundProtocol = ReadyUpgrade<&'static [u8]>;
Expand All @@ -95,7 +95,7 @@ impl ConnectionHandler for Handler {
SubstreamProtocol::new(DeniedUpgrade, ())
}

fn on_behaviour_event(&mut self, command: Self::InEvent) {
fn on_behaviour_event(&mut self, command: Self::FromSwarm) {
self.queued_events
.push_back(ConnectionHandlerEvent::OutboundSubstreamRequest {
protocol: SubstreamProtocol::new(ReadyUpgrade::new(crate::PROTOCOL_NAME), command),
Expand Down Expand Up @@ -161,7 +161,7 @@ impl ConnectionHandler for Handler {
ConnectionHandlerEvent<
Self::OutboundProtocol,
Self::OutboundOpenInfo,
Self::OutEvent,
Self::ToBehaviour,
Self::Error,
>,
> {
Expand Down
4 changes: 2 additions & 2 deletions protocols/perf/src/server/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Behaviour {

impl NetworkBehaviour for Behaviour {
type ConnectionHandler = Handler;
type OutEvent = Event;
type ToSwarm = Event;

fn handle_established_inbound_connection(
&mut self,
Expand Down Expand Up @@ -110,7 +110,7 @@ impl NetworkBehaviour for Behaviour {
&mut self,
_cx: &mut Context<'_>,
_: &mut impl PollParameters,
) -> Poll<ToSwarm<Self::OutEvent, THandlerInEvent<Self>>> {
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
if let Some(event) = self.queued_events.pop_front() {
return Poll::Ready(event);
}
Expand Down
Loading