Skip to content

Commit

Permalink
chore(identify): remove deprecated symbols
Browse files Browse the repository at this point in the history
Pull-Request: #4735.
  • Loading branch information
thomaseizinger authored Oct 30, 2023
1 parent 3ea0f75 commit 3820a98
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 28 deletions.
3 changes: 3 additions & 0 deletions protocols/identify/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

- Add `Info` to the `libp2p-identify::Event::Pushed` to report pushed info.
See [PR 4527](https://github.com/libp2p/rust-libp2p/pull/4527)
- Remove deprecated `initial_delay`.
Identify requests are always sent instantly after the connection has been established.
See [PR 4735](https://github.com/libp2p/rust-libp2p/pull/4735)

## 0.43.1

Expand Down
25 changes: 0 additions & 25 deletions protocols/identify/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,6 @@ pub struct Config {
///
/// Defaults to `rust-libp2p/<libp2p-identify-version>`.
pub agent_version: String,
/// The initial delay before the first identification request
/// is sent to a remote on a newly established connection.
///
/// Defaults to 0ms.
#[deprecated(note = "The `initial_delay` is no longer necessary and will be
completely removed since a remote should be able to instantly
answer to an identify request")]
pub initial_delay: Duration,
/// The interval at which identification requests are sent to
/// the remote on established connections after the first request,
/// i.e. the delay between identification requests.
Expand Down Expand Up @@ -106,13 +98,11 @@ pub struct Config {
impl Config {
/// Creates a new configuration for the identify [`Behaviour`] that
/// advertises the given protocol version and public key.
#[allow(deprecated)]
pub fn new(protocol_version: String, local_public_key: PublicKey) -> Self {
Self {
protocol_version,
agent_version: format!("rust-libp2p/{}", env!("CARGO_PKG_VERSION")),
local_public_key,
initial_delay: Duration::from_millis(0),
interval: Duration::from_secs(5 * 60),
push_listen_addr_updates: false,
cache_size: 100,
Expand All @@ -125,17 +115,6 @@ impl Config {
self
}

/// Configures the initial delay before the first identification
/// request is sent on a newly established connection to a peer.
#[deprecated(note = "The `initial_delay` is no longer necessary and will be
completely removed since a remote should be able to instantly
answer to an identify request thus also this setter will be removed")]
#[allow(deprecated)]
pub fn with_initial_delay(mut self, d: Duration) -> Self {
self.initial_delay = d;
self
}

/// Configures the interval at which identification requests are
/// sent to peers after the initial request.
pub fn with_interval(mut self, d: Duration) -> Self {
Expand Down Expand Up @@ -235,7 +214,6 @@ impl NetworkBehaviour for Behaviour {
type ConnectionHandler = Handler;
type ToSwarm = Event;

#[allow(deprecated)]
fn handle_established_inbound_connection(
&mut self,
_: ConnectionId,
Expand All @@ -244,7 +222,6 @@ impl NetworkBehaviour for Behaviour {
remote_addr: &Multiaddr,
) -> Result<THandler<Self>, ConnectionDenied> {
Ok(Handler::new(
self.config.initial_delay,
self.config.interval,
peer,
self.config.local_public_key.clone(),
Expand All @@ -255,7 +232,6 @@ impl NetworkBehaviour for Behaviour {
))
}

#[allow(deprecated)]
fn handle_established_outbound_connection(
&mut self,
_: ConnectionId,
Expand All @@ -264,7 +240,6 @@ impl NetworkBehaviour for Behaviour {
_: Endpoint,
) -> Result<THandler<Self>, ConnectionDenied> {
Ok(Handler::new(
self.config.initial_delay,
self.config.interval,
peer,
self.config.local_public_key.clone(),
Expand Down
4 changes: 1 addition & 3 deletions protocols/identify/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ pub enum Event {

impl Handler {
/// Creates a new `Handler`.
#[allow(clippy::too_many_arguments)]
pub fn new(
initial_delay: Duration,
interval: Duration,
remote_peer_id: PeerId,
public_key: PublicKey,
Expand All @@ -135,7 +133,7 @@ impl Handler {
STREAM_TIMEOUT,
MAX_CONCURRENT_STREAMS_PER_CONNECTION,
),
trigger_next_identify: Delay::new(initial_delay),
trigger_next_identify: Delay::new(Duration::ZERO),
exchanged_one_periodic_identify: false,
interval,
public_key,
Expand Down
39 changes: 39 additions & 0 deletions protocols/identify/tests/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use libp2p_identify as identify;
use libp2p_swarm::{Swarm, SwarmEvent};
use libp2p_swarm_test::SwarmExt;
use std::iter;
use std::time::{Duration, Instant};

#[async_std::test]
async fn periodic_identify() {
Expand Down Expand Up @@ -179,3 +180,41 @@ async fn discover_peer_after_disconnect() {

assert_eq!(connected_peer, swarm1_peer_id);
}

#[async_std::test]
async fn configured_interval_starts_after_first_identify() {
let _ = env_logger::try_init();

let identify_interval = Duration::from_secs(5);

let mut swarm1 = Swarm::new_ephemeral(|identity| {
identify::Behaviour::new(
identify::Config::new("a".to_string(), identity.public())
.with_interval(identify_interval),
)
});
let mut swarm2 = Swarm::new_ephemeral(|identity| {
identify::Behaviour::new(
identify::Config::new("a".to_string(), identity.public())
.with_agent_version("b".to_string()),
)
});

swarm1.listen().with_memory_addr_external().await;
swarm2.connect(&mut swarm1).await;

async_std::task::spawn(swarm2.loop_on_next());

let start = Instant::now();

// Wait until we identified.
swarm1
.wait(|event| {
matches!(event, SwarmEvent::Behaviour(identify::Event::Sent { .. })).then_some(())
})
.await;

let time_to_first_identify = Instant::now().duration_since(start);

assert!(time_to_first_identify < identify_interval)
}

0 comments on commit 3820a98

Please sign in to comment.