Skip to content

Commit 9a28cd2

Browse files
Allow reporting of supported protocols by remote
1 parent f2801fb commit 9a28cd2

File tree

23 files changed

+151
-36
lines changed

23 files changed

+151
-36
lines changed

protocols/dcutr/src/handler/direct.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ impl ConnectionHandler for Handler {
9393
| ConnectionEvent::DialUpgradeError(_)
9494
| ConnectionEvent::ListenUpgradeError(_)
9595
| ConnectionEvent::AddressChange(_)
96-
| ConnectionEvent::ProtocolsChange(_) => {}
96+
| ConnectionEvent::LocalProtocolsChange(_)
97+
| ConnectionEvent::RemoteProtocolsChange(_) => {}
9798
}
9899
}
99100
}

protocols/dcutr/src/handler/relayed.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,9 @@ impl ConnectionHandler for Handler {
419419
ConnectionEvent::DialUpgradeError(dial_upgrade_error) => {
420420
self.on_dial_upgrade_error(dial_upgrade_error)
421421
}
422-
ConnectionEvent::AddressChange(_) | ConnectionEvent::ProtocolsChange(_) => {}
422+
ConnectionEvent::AddressChange(_)
423+
| ConnectionEvent::LocalProtocolsChange(_)
424+
| ConnectionEvent::RemoteProtocolsChange(_) => {}
423425
}
424426
}
425427
}

protocols/gossipsub/src/handler.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,8 @@ impl ConnectionHandler for Handler {
578578
}
579579
ConnectionEvent::AddressChange(_)
580580
| ConnectionEvent::ListenUpgradeError(_)
581-
| ConnectionEvent::ProtocolsChange(_) => {}
581+
| ConnectionEvent::LocalProtocolsChange(_)
582+
| ConnectionEvent::RemoteProtocolsChange(_) => {}
582583
}
583584
}
584585
}

protocols/identify/src/handler.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ impl ConnectionHandler for Handler {
346346
}
347347
ConnectionEvent::AddressChange(_)
348348
| ConnectionEvent::ListenUpgradeError(_)
349-
| ConnectionEvent::ProtocolsChange(_) => {}
349+
| ConnectionEvent::LocalProtocolsChange(_) => {}
350+
ConnectionEvent::RemoteProtocolsChange(_) => {}
350351
}
351352
}
352353
}

protocols/kad/src/handler.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,26 @@ where
788788
}
789789
ConnectionEvent::AddressChange(_)
790790
| ConnectionEvent::ListenUpgradeError(_)
791-
| ConnectionEvent::ProtocolsChange(_) => {}
791+
| ConnectionEvent::LocalProtocolsChange(_) => {}
792+
ConnectionEvent::RemoteProtocolsChange(ProtocolsChange { protocols }) => {
793+
// TODO: We should cache this / it will get simpler with #2831.
794+
let kademlia_protocols = self
795+
.config
796+
.protocol_config
797+
.protocol_names()
798+
.iter()
799+
.filter_map(|b| String::from_utf8(b.to_vec()).ok())
800+
.collect::<Vec<_>>();
801+
802+
let remote_supports_our_kademlia_protocols =
803+
kademlia_protocols.iter().all(|p| protocols.contains(p));
804+
805+
if remote_supports_our_kademlia_protocols {
806+
self.protocol_status = ProtocolStatus::Confirmed;
807+
} else {
808+
self.protocol_status = ProtocolStatus::NotSupported;
809+
}
810+
}
792811
}
793812
}
794813
}

protocols/perf/src/client/handler.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl ConnectionHandler for Handler {
127127
.boxed(),
128128
),
129129

130-
ConnectionEvent::AddressChange(_) | ConnectionEvent::ProtocolsChange(_) => {}
130+
ConnectionEvent::AddressChange(_) | ConnectionEvent::LocalProtocolsChange(_) => {}
131131
ConnectionEvent::DialUpgradeError(DialUpgradeError {
132132
info: Command { id, .. },
133133
error,
@@ -147,6 +147,7 @@ impl ConnectionHandler for Handler {
147147
},
148148
}
149149
}
150+
ConnectionEvent::RemoteProtocolsChange(_) => {}
150151
}
151152
}
152153

protocols/perf/src/server/handler.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ impl ConnectionHandler for Handler {
104104
ConnectionEvent::DialUpgradeError(DialUpgradeError { info, .. }) => {
105105
void::unreachable(info)
106106
}
107-
ConnectionEvent::AddressChange(_) | ConnectionEvent::ProtocolsChange(_) => {}
107+
ConnectionEvent::AddressChange(_)
108+
| ConnectionEvent::LocalProtocolsChange(_)
109+
| ConnectionEvent::RemoteProtocolsChange(_) => {}
108110
ConnectionEvent::ListenUpgradeError(ListenUpgradeError { info: (), error }) => {
109111
match error {
110112
ConnectionHandlerUpgrErr::Timeout => {}

protocols/ping/src/handler.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,8 @@ impl ConnectionHandler for Handler {
413413
}
414414
ConnectionEvent::AddressChange(_)
415415
| ConnectionEvent::ListenUpgradeError(_)
416-
| ConnectionEvent::ProtocolsChange(_) => {}
416+
| ConnectionEvent::LocalProtocolsChange(_)
417+
| ConnectionEvent::RemoteProtocolsChange(_) => {}
417418
}
418419
}
419420
}

protocols/relay/src/behaviour/handler.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,9 @@ impl ConnectionHandler for Handler {
954954
ConnectionEvent::DialUpgradeError(dial_upgrade_error) => {
955955
self.on_dial_upgrade_error(dial_upgrade_error)
956956
}
957-
ConnectionEvent::AddressChange(_) | ConnectionEvent::ProtocolsChange(_) => {}
957+
ConnectionEvent::AddressChange(_)
958+
| ConnectionEvent::LocalProtocolsChange(_)
959+
| ConnectionEvent::RemoteProtocolsChange(_) => {}
958960
}
959961
}
960962
}

protocols/relay/src/priv_client/handler.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,9 @@ impl ConnectionHandler for Handler {
613613
ConnectionEvent::DialUpgradeError(dial_upgrade_error) => {
614614
self.on_dial_upgrade_error(dial_upgrade_error)
615615
}
616-
ConnectionEvent::AddressChange(_) | ConnectionEvent::ProtocolsChange(_) => {}
616+
ConnectionEvent::AddressChange(_)
617+
| ConnectionEvent::LocalProtocolsChange(_)
618+
| ConnectionEvent::RemoteProtocolsChange(_) => {}
617619
}
618620
}
619621
}

0 commit comments

Comments
 (0)