mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-29 17:51:35 +00:00
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.
This commit is contained in:
@ -88,7 +88,10 @@ pub struct Config {
|
||||
/// The initial delay before the first identification request
|
||||
/// is sent to a remote on a newly established connection.
|
||||
///
|
||||
/// Defaults to 500ms.
|
||||
/// 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,
|
||||
@ -117,12 +120,13 @@ 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(500),
|
||||
initial_delay: Duration::from_millis(0),
|
||||
interval: Duration::from_secs(5 * 60),
|
||||
push_listen_addr_updates: false,
|
||||
cache_size: 100,
|
||||
@ -137,6 +141,10 @@ impl Config {
|
||||
|
||||
/// 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
|
||||
@ -239,6 +247,7 @@ impl NetworkBehaviour for Behaviour {
|
||||
type ConnectionHandler = Handler;
|
||||
type OutEvent = Event;
|
||||
|
||||
#[allow(deprecated)]
|
||||
fn handle_established_inbound_connection(
|
||||
&mut self,
|
||||
_: ConnectionId,
|
||||
@ -257,6 +266,7 @@ impl NetworkBehaviour for Behaviour {
|
||||
))
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
fn handle_established_outbound_connection(
|
||||
&mut self,
|
||||
_: ConnectionId,
|
||||
@ -737,6 +747,7 @@ mod tests {
|
||||
|
||||
let mut swarm1 = {
|
||||
let (pubkey, transport) = transport();
|
||||
#[allow(deprecated)]
|
||||
let protocol = Behaviour::new(
|
||||
Config::new("a".to_string(), pubkey.clone())
|
||||
// `swarm1` will set `KeepAlive::No` once it identified `swarm2` and thus
|
||||
|
Reference in New Issue
Block a user