Skip to content

Commit

Permalink
Pass negotiated protocol directly to connection handler
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaseizinger committed Nov 2, 2023
1 parent 5d5a042 commit 310311a
Show file tree
Hide file tree
Showing 23 changed files with 412 additions and 921 deletions.
19 changes: 4 additions & 15 deletions protocols/dcutr/src/handler/relayed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,7 @@ impl Handler {

fn on_fully_negotiated_inbound(
&mut self,
FullyNegotiatedInbound {
protocol: output, ..
}: FullyNegotiatedInbound<
<Self as ConnectionHandler>::InboundProtocol,
FullyNegotiatedInbound { stream: output, .. }: FullyNegotiatedInbound<
<Self as ConnectionHandler>::InboundOpenInfo,
>,
) {
Expand All @@ -122,9 +119,7 @@ impl Handler {

fn on_fully_negotiated_outbound(
&mut self,
FullyNegotiatedOutbound {
protocol: stream, ..
}: FullyNegotiatedOutbound<
FullyNegotiatedOutbound { stream: stream, .. }: FullyNegotiatedOutbound<
<Self as ConnectionHandler>::OutboundProtocol,
<Self as ConnectionHandler>::OutboundOpenInfo,
>,
Expand All @@ -150,8 +145,7 @@ impl Handler {
fn on_listen_upgrade_error(
&mut self,
ListenUpgradeError { error, .. }: ListenUpgradeError<
<Self as ConnectionHandler>::InboundOpenInfo,
<Self as ConnectionHandler>::InboundProtocol,
<<Self as ConnectionHandler>::InboundProtocol as UpgradeInfo>::Info,
>,
) {
void::unreachable(error.into_inner());
Expand Down Expand Up @@ -290,12 +284,7 @@ impl ConnectionHandler for Handler {

fn on_connection_event(
&mut self,
event: ConnectionEvent<
Self::InboundProtocol,
Self::OutboundProtocol,
Self::InboundOpenInfo,
Self::OutboundOpenInfo,
>,
event: ConnectionEvent<Self::InboundOpenInfo, Self::OutboundOpenInfo>,
) {
match event {
ConnectionEvent::FullyNegotiatedInbound(fully_negotiated_inbound) => {
Expand Down
13 changes: 5 additions & 8 deletions protocols/gossipsub/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ impl EnabledHandler {

fn on_fully_negotiated_outbound(
&mut self,
FullyNegotiatedOutbound { protocol, .. }: FullyNegotiatedOutbound<
FullyNegotiatedOutbound {
stream: protocol, ..
}: FullyNegotiatedOutbound<
<Handler as ConnectionHandler>::OutboundProtocol,
<Handler as ConnectionHandler>::OutboundOpenInfo,
>,
Expand Down Expand Up @@ -455,12 +457,7 @@ impl ConnectionHandler for Handler {

fn on_connection_event(
&mut self,
event: ConnectionEvent<
Self::InboundProtocol,
Self::OutboundProtocol,
Self::InboundOpenInfo,
Self::OutboundOpenInfo,
>,
event: ConnectionEvent<Self::InboundOpenInfo, Self::OutboundOpenInfo>,
) {
match self {
Handler::Enabled(handler) => {
Expand Down Expand Up @@ -492,7 +489,7 @@ impl ConnectionHandler for Handler {

match event {
ConnectionEvent::FullyNegotiatedInbound(FullyNegotiatedInbound {
protocol,
stream: protocol,
..
}) => match protocol {
Either::Left(protocol) => handler.on_fully_negotiated_inbound(protocol),
Expand Down
16 changes: 3 additions & 13 deletions protocols/identify/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,7 @@ impl Handler {

fn on_fully_negotiated_inbound(
&mut self,
FullyNegotiatedInbound {
protocol: output, ..
}: FullyNegotiatedInbound<
<Self as ConnectionHandler>::InboundProtocol,
FullyNegotiatedInbound { stream: output, .. }: FullyNegotiatedInbound<
<Self as ConnectionHandler>::InboundOpenInfo,
>,
) {
Expand Down Expand Up @@ -180,9 +177,7 @@ impl Handler {

fn on_fully_negotiated_outbound(
&mut self,
FullyNegotiatedOutbound {
protocol: output, ..
}: FullyNegotiatedOutbound<
FullyNegotiatedOutbound { stream: output, .. }: FullyNegotiatedOutbound<
<Self as ConnectionHandler>::OutboundProtocol,
<Self as ConnectionHandler>::OutboundOpenInfo,
>,
Expand Down Expand Up @@ -373,12 +368,7 @@ impl ConnectionHandler for Handler {

fn on_connection_event(
&mut self,
event: ConnectionEvent<
Self::InboundProtocol,
Self::OutboundProtocol,
Self::InboundOpenInfo,
Self::OutboundOpenInfo,
>,
event: ConnectionEvent<Self::InboundOpenInfo, Self::OutboundOpenInfo>,
) {
match event {
ConnectionEvent::FullyNegotiatedInbound(fully_negotiated_inbound) => {
Expand Down
19 changes: 8 additions & 11 deletions protocols/kad/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,10 @@ impl Handler {

fn on_fully_negotiated_outbound(
&mut self,
FullyNegotiatedOutbound { protocol, info: () }: FullyNegotiatedOutbound<
FullyNegotiatedOutbound {
stream: protocol,
info: (),
}: FullyNegotiatedOutbound<
<Self as ConnectionHandler>::OutboundProtocol,
<Self as ConnectionHandler>::OutboundOpenInfo,
>,
Expand All @@ -519,10 +522,9 @@ impl Handler {

fn on_fully_negotiated_inbound(
&mut self,
FullyNegotiatedInbound { protocol, .. }: FullyNegotiatedInbound<
<Self as ConnectionHandler>::InboundProtocol,
<Self as ConnectionHandler>::InboundOpenInfo,
>,
FullyNegotiatedInbound {
stream: protocol, ..
}: FullyNegotiatedInbound<<Self as ConnectionHandler>::InboundOpenInfo>,
) {
// If `self.allow_listening` is false, then we produced a `DeniedUpgrade` and `protocol`
// is a `Void`.
Expand Down Expand Up @@ -755,12 +757,7 @@ impl ConnectionHandler for Handler {

fn on_connection_event(
&mut self,
event: ConnectionEvent<
Self::InboundProtocol,
Self::OutboundProtocol,
Self::InboundOpenInfo,
Self::OutboundOpenInfo,
>,
event: ConnectionEvent<Self::InboundOpenInfo, Self::OutboundOpenInfo>,
) {
match event {
ConnectionEvent::FullyNegotiatedOutbound(fully_negotiated_outbound) => {
Expand Down
12 changes: 4 additions & 8 deletions protocols/perf/src/client/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,15 @@ impl ConnectionHandler for Handler {

fn on_connection_event(
&mut self,
event: ConnectionEvent<
Self::InboundProtocol,
Self::OutboundProtocol,
Self::InboundOpenInfo,
Self::OutboundOpenInfo,
>,
event: ConnectionEvent<Self::InboundOpenInfo, Self::OutboundOpenInfo>,
) {
match event {
ConnectionEvent::FullyNegotiatedInbound(FullyNegotiatedInbound {
protocol, ..
stream: protocol,
..
}) => void::unreachable(protocol),
ConnectionEvent::FullyNegotiatedOutbound(FullyNegotiatedOutbound {
protocol,
stream: protocol,
info: (),
}) => {
let Command { id, params } = self
Expand Down
9 changes: 2 additions & 7 deletions protocols/perf/src/server/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,11 @@ impl ConnectionHandler for Handler {

fn on_connection_event(
&mut self,
event: ConnectionEvent<
Self::InboundProtocol,
Self::OutboundProtocol,
Self::InboundOpenInfo,
Self::OutboundOpenInfo,
>,
event: ConnectionEvent<Self::InboundOpenInfo, Self::OutboundOpenInfo>,
) {
match event {
ConnectionEvent::FullyNegotiatedInbound(FullyNegotiatedInbound {
protocol,
stream: protocol,
info: _,
}) => {
if self
Expand Down
11 changes: 6 additions & 5 deletions protocols/ping/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use futures::prelude::*;
use futures_timer::Delay;
use libp2p_identity::PeerId;
use libp2p_swarm::handler::{
ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound,
ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, UpgradeInfo,
};
use libp2p_swarm::{
ConnectionHandler, ConnectionHandlerEvent, ReadyUpgrade, Stream, StreamUpgradeError,
Expand Down Expand Up @@ -330,22 +330,23 @@ impl ConnectionHandler for Handler {
fn on_connection_event(
&mut self,
event: ConnectionEvent<
Self::InboundProtocol,
Self::OutboundProtocol,
<Self::InboundProtocol as UpgradeInfo>::Info,
<Self::OutboundProtocol as UpgradeInfo>::Info,
Self::InboundOpenInfo,
Self::OutboundOpenInfo,
>,
) {
match event {
ConnectionEvent::FullyNegotiatedInbound(FullyNegotiatedInbound {
protocol: mut stream,
mut stream,
protocol,
..
}) => {
stream.ignore_for_keep_alive();
self.inbound = Some(protocol::recv_ping(stream).boxed());
}
ConnectionEvent::FullyNegotiatedOutbound(FullyNegotiatedOutbound {
protocol: mut stream,
stream: mut stream,
..
}) => {
stream.ignore_for_keep_alive();
Expand Down
11 changes: 3 additions & 8 deletions protocols/relay/src/behaviour/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,22 +873,17 @@ impl ConnectionHandler for Handler {

fn on_connection_event(
&mut self,
event: ConnectionEvent<
Self::InboundProtocol,
Self::OutboundProtocol,
Self::InboundOpenInfo,
Self::OutboundOpenInfo,
>,
event: ConnectionEvent<Self::InboundOpenInfo, Self::OutboundOpenInfo>,
) {
match event {
ConnectionEvent::FullyNegotiatedInbound(FullyNegotiatedInbound {
protocol: stream,
stream: stream,
..
}) => {
self.on_fully_negotiated_inbound(stream);
}
ConnectionEvent::FullyNegotiatedOutbound(FullyNegotiatedOutbound {
protocol: stream,
stream: stream,
..
}) => {
self.on_fully_negotiated_outbound(stream);
Expand Down
11 changes: 3 additions & 8 deletions protocols/relay/src/priv_client/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,16 +474,11 @@ impl ConnectionHandler for Handler {

fn on_connection_event(
&mut self,
event: ConnectionEvent<
Self::InboundProtocol,
Self::OutboundProtocol,
Self::InboundOpenInfo,
Self::OutboundOpenInfo,
>,
event: ConnectionEvent<Self::InboundOpenInfo, Self::OutboundOpenInfo>,
) {
match event {
ConnectionEvent::FullyNegotiatedInbound(FullyNegotiatedInbound {
protocol: stream,
stream: stream,
..
}) => {
if self
Expand All @@ -495,7 +490,7 @@ impl ConnectionHandler for Handler {
}
}
ConnectionEvent::FullyNegotiatedOutbound(FullyNegotiatedOutbound {
protocol: stream,
stream: stream,
..
}) => {
let pending_request = self.pending_requests.pop_front().expect(
Expand Down
19 changes: 5 additions & 14 deletions protocols/request-response/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,9 @@ where
fn on_fully_negotiated_inbound(
&mut self,
FullyNegotiatedInbound {
protocol: (mut stream, protocol),
stream: (mut stream, protocol),
info: (),
}: FullyNegotiatedInbound<
<Self as ConnectionHandler>::InboundProtocol,
<Self as ConnectionHandler>::InboundOpenInfo,
>,
}: FullyNegotiatedInbound<<Self as ConnectionHandler>::InboundOpenInfo>,
) {
let mut codec = self.codec.clone();
let request_id = self.next_inbound_request_id();
Expand Down Expand Up @@ -171,7 +168,7 @@ where
fn on_fully_negotiated_outbound(
&mut self,
FullyNegotiatedOutbound {
protocol: (mut stream, protocol),
stream: (mut stream, protocol),
info: (),
}: FullyNegotiatedOutbound<
<Self as ConnectionHandler>::OutboundProtocol,
Expand Down Expand Up @@ -247,8 +244,7 @@ where
fn on_listen_upgrade_error(
&mut self,
ListenUpgradeError { error, .. }: ListenUpgradeError<
<Self as ConnectionHandler>::InboundOpenInfo,
<Self as ConnectionHandler>::InboundProtocol,
<<Self as ConnectionHandler>::InboundProtocol as UpgradeInfo>::Info,
>,
) {
void::unreachable(error)
Expand Down Expand Up @@ -463,12 +459,7 @@ where

fn on_connection_event(
&mut self,
event: ConnectionEvent<
Self::InboundProtocol,
Self::OutboundProtocol,
Self::InboundOpenInfo,
Self::OutboundOpenInfo,
>,
event: ConnectionEvent<Self::InboundOpenInfo, Self::OutboundOpenInfo>,
) {
match event {
ConnectionEvent::FullyNegotiatedInbound(fully_negotiated_inbound) => {
Expand Down
Loading

0 comments on commit 310311a

Please sign in to comment.