Skip to content

Commit

Permalink
use connection_limits::Behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
melekes committed Jun 23, 2023
1 parent d5b8198 commit 81f5cd0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
13 changes: 11 additions & 2 deletions client/network/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ use crate::{
use bytes::Bytes;
use futures::channel::oneshot;
use libp2p::{
core::Multiaddr, identify::Info as IdentifyInfo, identity::PublicKey, kad::RecordKey,
swarm::NetworkBehaviour, PeerId,
connection_limits::ConnectionLimits,
core::{connection, Multiaddr},
identify::Info as IdentifyInfo,
identity::PublicKey,
kad::RecordKey,
swarm::NetworkBehaviour,
PeerId,
};

use sc_network_common::role::{ObservedRole, Roles};
Expand All @@ -51,6 +56,8 @@ pub struct Behaviour<B: BlockT> {
peer_info: peer_info::PeerInfoBehaviour,
/// Discovers nodes of the network.
discovery: DiscoveryBehaviour,
/// Connection limits.
connection_limits: libp2p::connection_limits::Behaviour,
/// Generic request-response protocols.
request_responses: request_responses::RequestResponsesBehaviour,
}
Expand Down Expand Up @@ -171,11 +178,13 @@ impl<B: BlockT> Behaviour<B> {
disco_config: DiscoveryConfig,
request_response_protocols: Vec<ProtocolConfig>,
peerset: PeersetHandle,
connection_limits: ConnectionLimits,
) -> Result<Self, request_responses::RegisterError> {
Ok(Self {
substrate,
peer_info: peer_info::PeerInfoBehaviour::new(user_agent, local_public_key),
discovery: disco_config.finish(),
connection_limits: Behaviour::new(connection_limits),
request_responses: request_responses::RequestResponsesBehaviour::new(
request_response_protocols.into_iter(),
peerset,
Expand Down
12 changes: 5 additions & 7 deletions client/network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,11 @@ where
discovery_config,
request_response_protocols,
peerset_handle.clone(),
ConnectionLimits::default()
.with_max_established_per_peer(Some(crate::MAX_CONNECTIONS_PER_PEER as u32))
.with_max_established_incoming(Some(
crate::MAX_CONNECTIONS_ESTABLISHED_INCOMING,
)),
);

match result {
Expand All @@ -370,13 +375,6 @@ where
)
};
let builder = builder
.connection_limits(
ConnectionLimits::default()
.with_max_established_per_peer(Some(crate::MAX_CONNECTIONS_PER_PEER as u32))
.with_max_established_incoming(Some(
crate::MAX_CONNECTIONS_ESTABLISHED_INCOMING,
)),
)
.substream_upgrade_protocol_override(upgrade::Version::V1Lazy)
.notify_handler_buffer_size(NonZeroUsize::new(32).expect("32 != 0; qed"))
// NOTE: 24 is somewhat arbitrary and should be tuned in the future if necessary.
Expand Down

0 comments on commit 81f5cd0

Please sign in to comment.