Skip to content

Commit f858ec6

Browse files
authored
feat(identify): immediately run identify protocol on new connections
Previously, and for unknown legacy reasons, we waited for a configurable delay (default 500ms) upon new connections before we ran the identify protocol. This unnecessarily slows down applications that wait for the identify handshake to complete before performing further actions. Resolves #3485. Pull-Request: #3545.
1 parent 9fc2da0 commit f858ec6

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

protocols/identify/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
- Raise MSRV to 1.65.
55
See [PR 3715].
66

7+
- Reduce the initial delay before running the identify protocol to 0 and make the option deprecated.
8+
See [PR 3545].
9+
710
[PR 3698]: https://github.com/libp2p/rust-libp2p/pull/3698
811
[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715
12+
[PR 3545]: https://github.com/libp2p/rust-libp2p/pull/3545
913

1014
## 0.42.2
1115

protocols/identify/src/behaviour.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ pub struct Config {
8888
/// The initial delay before the first identification request
8989
/// is sent to a remote on a newly established connection.
9090
///
91-
/// Defaults to 500ms.
91+
/// Defaults to 0ms.
92+
#[deprecated(note = "The `initial_delay` is no longer necessary and will be
93+
completely removed since a remote should be able to instantly
94+
answer to an identify request")]
9295
pub initial_delay: Duration,
9396
/// The interval at which identification requests are sent to
9497
/// the remote on established connections after the first request,
@@ -117,12 +120,13 @@ pub struct Config {
117120
impl Config {
118121
/// Creates a new configuration for the identify [`Behaviour`] that
119122
/// advertises the given protocol version and public key.
123+
#[allow(deprecated)]
120124
pub fn new(protocol_version: String, local_public_key: PublicKey) -> Self {
121125
Self {
122126
protocol_version,
123127
agent_version: format!("rust-libp2p/{}", env!("CARGO_PKG_VERSION")),
124128
local_public_key,
125-
initial_delay: Duration::from_millis(500),
129+
initial_delay: Duration::from_millis(0),
126130
interval: Duration::from_secs(5 * 60),
127131
push_listen_addr_updates: false,
128132
cache_size: 100,
@@ -137,6 +141,10 @@ impl Config {
137141

138142
/// Configures the initial delay before the first identification
139143
/// request is sent on a newly established connection to a peer.
144+
#[deprecated(note = "The `initial_delay` is no longer necessary and will be
145+
completely removed since a remote should be able to instantly
146+
answer to an identify request thus also this setter will be removed")]
147+
#[allow(deprecated)]
140148
pub fn with_initial_delay(mut self, d: Duration) -> Self {
141149
self.initial_delay = d;
142150
self
@@ -239,6 +247,7 @@ impl NetworkBehaviour for Behaviour {
239247
type ConnectionHandler = Handler;
240248
type OutEvent = Event;
241249

250+
#[allow(deprecated)]
242251
fn handle_established_inbound_connection(
243252
&mut self,
244253
_: ConnectionId,
@@ -257,6 +266,7 @@ impl NetworkBehaviour for Behaviour {
257266
))
258267
}
259268

269+
#[allow(deprecated)]
260270
fn handle_established_outbound_connection(
261271
&mut self,
262272
_: ConnectionId,
@@ -737,6 +747,7 @@ mod tests {
737747

738748
let mut swarm1 = {
739749
let (pubkey, transport) = transport();
750+
#[allow(deprecated)]
740751
let protocol = Behaviour::new(
741752
Config::new("a".to_string(), pubkey.clone())
742753
// `swarm1` will set `KeepAlive::No` once it identified `swarm2` and thus

0 commit comments

Comments
 (0)