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 43 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
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/distributed-key-value-store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ async-trait = "0.1"
env_logger = "0.10"
futures = "0.3.28"
libp2p = { path = "../../libp2p", features = ["async-std", "dns", "kad", "mdns", "noise", "macros", "tcp", "websocket", "yamux"] }
multiaddr = { version = "0.17.1" }
multiaddr = { version = "0.17.1" }
2 changes: 1 addition & 1 deletion examples/distributed-key-value-store/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async fn main() -> Result<(), Box<dyn Error>> {

// We create a custom network behaviour that combines Kademlia and mDNS.
#[derive(NetworkBehaviour)]
#[behaviour(out_event = "MyBehaviourEvent")]
#[behaviour(to_swarm = "MyBehaviourEvent")]
struct MyBehaviour {
kademlia: Kademlia<MemoryStore>,
mdns: mdns::async_io::Behaviour,
Expand Down
2 changes: 1 addition & 1 deletion examples/file-sharing/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ impl EventLoop {
}

#[derive(NetworkBehaviour)]
#[behaviour(out_event = "ComposedEvent")]
#[behaviour(to_swarm = "ComposedEvent")]
struct ComposedBehaviour {
request_response: request_response::Behaviour<FileExchangeCodec>,
kademlia: Kademlia<MemoryStore>,
Expand Down
2 changes: 1 addition & 1 deletion examples/ipfs-private/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ async fn main() -> Result<(), Box<dyn Error>> {

// We create a custom network behaviour that combines gossipsub, ping and identify.
#[derive(NetworkBehaviour)]
#[behaviour(out_event = "MyBehaviourEvent")]
#[behaviour(to_swarm = "MyBehaviourEvent")]
struct MyBehaviour {
gossipsub: gossipsub::Behaviour,
identify: identify::Behaviour,
Expand Down
3 changes: 3 additions & 0 deletions libp2p/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
This newtype enforces additional variants like a leading forward-slash.
We encourage users to use `StreamProtocol` when implementing `UpgradeInfo`.
See [PR 3746].

- Rename `NetworkBehaviour::OutEvent` to `NetworkBehaviour::ToSwarm`, `ConnectionHandler::InEvent` to `ConnectionHandler::FromBehaviour`, `ConnectionHandler::OutEvent` to `ConnectionHandler::ToBehaviour`. See [PR 3848].

[PR 3746]: https://github.com/libp2p/rust-libp2p/pull/3746
[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715
[PR 3848]: https://github.com/libp2p/rust-libp2p/pull/3848

## 0.51.3

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 @@ -209,7 +209,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 @@ -427,7 +427,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 @@ -594,7 +594,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 @@ -237,7 +237,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 @@ -415,7 +415,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 @@ -39,8 +39,8 @@ pub struct Handler {
}

impl ConnectionHandler for Handler {
type InEvent = void::Void;
type OutEvent = Event;
type FromBehaviour = void::Void;
type ToBehaviour = Event;
type Error = StreamUpgradeError<std::io::Error>;
type InboundProtocol = DeniedUpgrade;
type OutboundProtocol = DeniedUpgrade;
Expand All @@ -51,7 +51,7 @@ impl ConnectionHandler for Handler {
SubstreamProtocol::new(DeniedUpgrade, ())
}

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

fn connection_keep_alive(&self) -> KeepAlive {
KeepAlive::No
Expand All @@ -64,7 +64,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 @@ -135,7 +135,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 @@ -254,8 +254,8 @@ impl Handler {
}

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

fn on_behaviour_event(&mut self, event: Self::InEvent) {
fn on_behaviour_event(&mut self, event: Self::FromBehaviour) {
match event {
Command::Connect { obs_addrs } => {
self.queued_events
Expand Down Expand Up @@ -323,7 +323,7 @@ impl ConnectionHandler for Handler {
ConnectionHandlerEvent<
Self::OutboundProtocol,
Self::OutboundOpenInfo,
Self::OutEvent,
Self::ToBehaviour,
Self::Error,
>,
> {
Expand Down
2 changes: 1 addition & 1 deletion protocols/dcutr/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fn build_client() -> Swarm<Client> {

#[derive(NetworkBehaviour)]
#[behaviour(
out_event = "ClientEvent",
to_swarm = "ClientEvent",
event_process = false,
prelude = "libp2p_swarm::derive_prelude"
)]
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 @@ -225,7 +225,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 @@ -393,8 +393,8 @@ impl EnabledHandler {
}

impl ConnectionHandler for Handler {
type InEvent = HandlerIn;
type OutEvent = HandlerEvent;
type FromBehaviour = HandlerIn;
type ToBehaviour = HandlerEvent;
type Error = Void;
type InboundOpenInfo = ();
type InboundProtocol = either::Either<ProtocolConfig, DeniedUpgrade>;
Expand Down Expand Up @@ -457,7 +457,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 @@ -234,7 +234,7 @@ impl Behaviour {

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

#[allow(deprecated)]
fn handle_established_inbound_connection(
Expand Down Expand Up @@ -319,7 +319,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.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 @@ -242,8 +242,8 @@ impl Handler {
}

impl ConnectionHandler for Handler {
type InEvent = InEvent;
type OutEvent = Event;
type FromBehaviour = InEvent;
type ToBehaviour = Event;
type Error = io::Error;
type InboundProtocol = SelectUpgrade<Identify, Push<InboundPush>>;
type OutboundProtocol = Either<Identify, Push<OutboundPush>>;
Expand All @@ -254,7 +254,7 @@ impl ConnectionHandler for Handler {
SubstreamProtocol::new(SelectUpgrade::new(Identify, Push::inbound()), ())
}

fn on_behaviour_event(&mut self, event: Self::InEvent) {
fn on_behaviour_event(&mut self, event: Self::FromBehaviour) {
match event {
InEvent::AddressesChanged(addresses) => {
self.external_addresses = addresses;
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 @@ -1960,7 +1960,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 @@ -2301,7 +2301,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.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,8 @@ impl<TUserData> ConnectionHandler for KademliaHandler<TUserData>
where
TUserData: Clone + fmt::Debug + Send + 'static + Unpin,
{
type InEvent = KademliaHandlerIn<TUserData>;
type OutEvent = KademliaHandlerEvent<TUserData>;
type FromBehaviour = 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 @@ -713,7 +713,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
Loading