Skip to content

Commit

Permalink
Merge pull request #2324 from subspace/remove-old-protocols
Browse files Browse the repository at this point in the history
Remove support of connected-peers and peer-info protocols.
  • Loading branch information
shamil-gadelshin authored Dec 15, 2023
2 parents 3f3a82a + bc8af4b commit 3dabbf1
Show file tree
Hide file tree
Showing 18 changed files with 15 additions and 2,071 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ use subspace_networking::utils::multihash::ToMultihash;
use subspace_networking::utils::strip_peer_id;
use subspace_networking::{
construct, Config, KademliaMode, KnownPeersManager, KnownPeersManagerConfig, Node, NodeRunner,
PeerInfo, PeerInfoProvider, PieceByIndexRequest, PieceByIndexRequestHandler,
PieceByIndexResponse, SegmentHeaderBySegmentIndexesRequestHandler, SegmentHeaderRequest,
SegmentHeaderResponse,
PieceByIndexRequest, PieceByIndexRequestHandler, PieceByIndexResponse,
SegmentHeaderBySegmentIndexesRequestHandler, SegmentHeaderRequest, SegmentHeaderResponse,
};
use subspace_rpc_primitives::MAX_SEGMENT_HEADERS_PER_REQUEST;
use tracing::{debug, error, info, Instrument};
Expand All @@ -26,8 +25,6 @@ use tracing::{debug, error, info, Instrument};
///
/// Must be the same as RPC limit since all requests go to the node anyway.
const SEGMENT_HEADER_NUMBER_LIMIT: u64 = MAX_SEGMENT_HEADERS_PER_REQUEST as u64;
/// Should be sufficient number of target connections for everyone, limits are higher
const TARGET_CONNECTIONS: u32 = 15;

#[allow(clippy::type_complexity, clippy::too_many_arguments)]
pub(super) fn configure_dsn(
Expand Down Expand Up @@ -66,7 +63,6 @@ pub(super) fn configure_dsn(
protocol_prefix,
keypair,
piece_cache.clone(),
Some(PeerInfoProvider::new_farmer()),
prometheus_metrics_registry,
);
let config = Config {
Expand Down Expand Up @@ -183,19 +179,6 @@ pub(super) fn configure_dsn(
max_pending_outgoing_connections: pending_out_connections,
max_established_incoming_connections: in_connections,
max_pending_incoming_connections: pending_in_connections,
// Non-farmer connections
general_connected_peers_handler: Some(Arc::new(|peer_info| {
!PeerInfo::is_farmer(peer_info)
})),
// Proactively maintain permanent connections with farmers
special_connected_peers_handler: Some(Arc::new(PeerInfo::is_farmer)),
// Do not have any target for general peers
general_connected_peers_target: 0,
special_connected_peers_target: TARGET_CONNECTIONS,
// Allow up to quarter of incoming connections to be maintained
general_connected_peers_limit: in_connections / 4,
// Allow to maintain some extra farmer connections beyond direct interest too
special_connected_peers_limit: TARGET_CONNECTIONS + in_connections / 4,
bootstrap_addresses: bootstrap_nodes,
kademlia_mode: KademliaMode::Dynamic,
external_addresses,
Expand Down
10 changes: 2 additions & 8 deletions crates/subspace-networking/examples/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::sync::Arc;
use std::time::{Duration, Instant};
use subspace_core_primitives::PieceIndex;
use subspace_networking::utils::piece_provider::{NoPieceValidator, PieceProvider, RetryPolicy};
use subspace_networking::{Config, Node, PeerInfoProvider, PieceByIndexRequestHandler};
use subspace_networking::{Config, Node, PieceByIndexRequestHandler};
use tokio::sync::Semaphore;
use tracing::{error, info, warn, Level};
use tracing_subscriber::fmt::Subscriber;
Expand Down Expand Up @@ -281,13 +281,7 @@ pub async fn configure_dsn(
) -> Node {
let keypair = Keypair::generate_ed25519();

let default_config = Config::new(
protocol_prefix,
keypair,
(),
Some(PeerInfoProvider::Client),
None,
);
let default_config = Config::new(protocol_prefix, keypair, (), None);

let config = Config {
listen_on: vec!["/ip4/0.0.0.0/tcp/0".parse().unwrap()],
Expand Down
12 changes: 3 additions & 9 deletions crates/subspace-networking/examples/random-walker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use std::sync::Arc;
use std::time::{Duration, Instant};
use subspace_core_primitives::PieceIndex;
use subspace_networking::{
Config, Multihash, Node, PeerDiscovered, PeerInfoProvider, PieceByIndexRequest,
PieceByIndexRequestHandler, PieceByIndexResponse, SendRequestError,
Config, Multihash, Node, PeerDiscovered, PieceByIndexRequest, PieceByIndexRequestHandler,
PieceByIndexResponse, SendRequestError,
};
use tracing::{debug, error, info, warn, Level};
use tracing_subscriber::fmt::Subscriber;
Expand Down Expand Up @@ -360,13 +360,7 @@ async fn configure_dsn(
) -> Node {
let keypair = Keypair::generate_ed25519();

let default_config = Config::new(
protocol_prefix,
keypair,
(),
Some(PeerInfoProvider::Client),
None,
);
let default_config = Config::new(protocol_prefix, keypair, (), None);

let config = Config {
listen_on: vec!["/ip4/0.0.0.0/tcp/0".parse().unwrap()],
Expand Down
33 changes: 0 additions & 33 deletions crates/subspace-networking/src/behavior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ mod tests;
use crate::protocols::autonat_wrapper::{
Behaviour as AutonatWrapper, Config as AutonatWrapperConfig,
};
use crate::protocols::connected_peers::Config as ConnectedPeersConfig;
use crate::protocols::peer_info::Event as PeerInfoEvent;
use crate::protocols::request_response::request_response_factory::{
Event as RequestResponseEvent, RequestHandler, RequestResponseFactoryBehaviour,
};
use crate::protocols::reserved_peers::{
Behaviour as ReservedPeersBehaviour, Config as ReservedPeersConfig, Event as ReservedPeersEvent,
};
use crate::protocols::subspace_connection_limits::Behaviour as ConnectionLimitsBehaviour;
use crate::{PeerInfoConfig, PeerInfoProvider};
use derive_more::From;
use libp2p::allow_block_list::{Behaviour as AllowBlockListBehaviour, BlockedPeers};
use libp2p::autonat::Event as AutonatEvent;
Expand Down Expand Up @@ -49,22 +46,6 @@ pub(crate) struct BehaviorConfig<RecordStore> {
pub(crate) connection_limits: ConnectionLimits,
/// The configuration for the [`ReservedPeersBehaviour`].
pub(crate) reserved_peers: ReservedPeersConfig,
// TODO: Restore or remove connected peer later
#[allow(dead_code)]
/// The configuration for the [`PeerInfo`] protocol.
pub(crate) peer_info_config: PeerInfoConfig,
// TODO: Restore or remove connected peer later
#[allow(dead_code)]
/// Provides peer-info for local peer.
pub(crate) peer_info_provider: Option<PeerInfoProvider>,
/// The configuration for the [`ConnectedPeers`] protocol (general instance).
// TODO: Restore or remove connected peer later
#[allow(dead_code)]
pub(crate) general_connected_peers_config: Option<ConnectedPeersConfig>,
// TODO: Restore or remove connected peer later
#[allow(dead_code)]
/// The configuration for the [`ConnectedPeers`] protocol (special instance).
pub(crate) special_connected_peers_config: Option<ConnectedPeersConfig>,
/// Autonat configuration.
pub(crate) autonat: AutonatWrapperConfig,
}
Expand Down Expand Up @@ -138,16 +119,6 @@ where
.expect("RequestResponse protocols registration failed."),
block_list: BlockListBehaviour::default(),
reserved_peers: ReservedPeersBehaviour::new(config.reserved_peers),
// TODO: Restore or remove connected peer later
//peer_info: peer_info.into(),
// general_connected_peers: config
// .general_connected_peers_config
// .map(ConnectedPeersBehaviour::new)
// .into(),
// special_connected_peers: config
// .special_connected_peers_config
// .map(ConnectedPeersBehaviour::new)
// .into(),
autonat: AutonatWrapper::new(config.autonat),
}
}
Expand All @@ -163,9 +134,5 @@ pub(crate) enum Event {
/// Event stub for connection limits and block list behaviours. We won't receive such events.
VoidEventStub(VoidEvent),
ReservedPeers(ReservedPeersEvent),
PeerInfo(PeerInfoEvent),
// TODO: Restore or remove connected peer later
// GeneralConnectedPeers(ConnectedPeersEvent<GeneralConnectedPeersInstance>),
// SpecialConnectedPeers(ConnectedPeersEvent<SpecialConnectedPeersInstance>),
Autonat(AutonatEvent),
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,6 @@ async fn main() -> Result<(), Box<dyn Error>> {
max_established_outgoing_connections: out_peers,
max_pending_incoming_connections: pending_in_peers,
max_pending_outgoing_connections: pending_out_peers,
// Maintain proactive connections with all peers
general_connected_peers_handler: Some(Arc::new(|_| true)),
// Maintain some number of persistent connections
general_connected_peers_target: in_peers / 8,
// Allow some more persistent connections from other peers
general_connected_peers_limit: in_peers / 4,
bootstrap_addresses: bootstrap_nodes,
kademlia_mode: KademliaMode::Static(Mode::Server),
external_addresses,
Expand All @@ -195,7 +189,6 @@ async fn main() -> Result<(), Box<dyn Error>> {
protocol_version.to_string(),
keypair,
(),
None,
dsn_metrics_registry,
)
};
Expand Down
68 changes: 0 additions & 68 deletions crates/subspace-networking/src/constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ use crate::constructor::transport::build_transport;
use crate::node::Node;
use crate::node_runner::{NodeRunner, NodeRunnerConfig};
use crate::protocols::autonat_wrapper::Config as AutonatWrapperConfig;
use crate::protocols::connected_peers::Config as ConnectedPeersConfig;
use crate::protocols::peer_info::PeerInfoProvider;
use crate::protocols::request_response::request_response_factory::RequestHandler;
use crate::protocols::reserved_peers::Config as ReservedPeersConfig;
use crate::shared::Shared;
use crate::utils::rate_limiter::RateLimiter;
use crate::utils::{strip_peer_id, SubspaceMetrics};
use crate::{PeerInfo, PeerInfoConfig};
use backoff::{ExponentialBackoff, SystemClock};
use futures::channel::mpsc;
use libp2p::autonat::Config as AutonatConfig;
Expand Down Expand Up @@ -47,15 +44,9 @@ use subspace_core_primitives::{crypto, Piece};
use thiserror::Error;
use tracing::{debug, error, info};

/// Defines whether connection should be maintained permanently.
pub type ConnectedPeersHandler = Arc<dyn Fn(&PeerInfo) -> bool + Send + Sync + 'static>;

const DEFAULT_NETWORK_PROTOCOL_VERSION: &str = "dev";
const KADEMLIA_PROTOCOL: &str = "/subspace/kad/0.1.0";
const GOSSIPSUB_PROTOCOL_PREFIX: &str = "subspace/gossipsub";
const PEER_INFO_PROTOCOL_NAME: &str = "/subspace/peer-info/1.0.0";
const GENERAL_CONNECTED_PEERS_PROTOCOL_LOG_TARGET: &str = "general-connected-peers";
const SPECIAL_CONNECTED_PEERS_PROTOCOL_LOG_TARGET: &str = "special-connected-peers";

/// Defines max_negotiating_inbound_streams constant for the swarm.
/// It must be set for large plots.
Expand Down Expand Up @@ -245,26 +236,6 @@ pub struct Config<LocalRecordProvider> {
pub metrics: Option<SubspaceMetrics>,
/// Defines protocol version for the network peers. Affects network partition.
pub protocol_version: String,
/// Specifies a source for peer information. None disables the protocol.
pub peer_info_provider: Option<PeerInfoProvider>,
/// Defines whether we maintain a persistent connection for common peers.
/// `None` (the default) disables the protocol.
pub general_connected_peers_handler: Option<ConnectedPeersHandler>,
/// Defines whether we maintain a persistent connection for special peers.
/// `None` (the default) disables the protocol.
pub special_connected_peers_handler: Option<ConnectedPeersHandler>,
/// Defines target total (in and out) connection number that should be maintained for general
/// peers (defaults to 0).
pub general_connected_peers_target: u32,
/// Defines target total (in and out) connection number that should be maintained for special
/// peers (defaults to 0).
pub special_connected_peers_target: u32,
/// Defines max total (in and out) connection number that should be maintained for general
/// peers (defaults to 0, will be automatically raised if set lower than target).
pub general_connected_peers_limit: u32,
/// Defines max total (in and out) connection number that should be maintained for special
/// peers (defaults to 0, will be automatically raised if set lower than target).
pub special_connected_peers_limit: u32,
/// Addresses to bootstrap Kademlia network
pub bootstrap_addresses: Vec<Multiaddr>,
/// Kademlia mode. The default value is set to Static(Client). The peer won't add its address
Expand Down Expand Up @@ -294,7 +265,6 @@ impl Default for Config<()> {
DEFAULT_NETWORK_PROTOCOL_VERSION.to_string(),
keypair,
(),
Some(PeerInfoProvider::new_client()),
None,
)
}
Expand All @@ -309,7 +279,6 @@ where
protocol_version: String,
keypair: identity::Keypair,
local_records_provider: LocalRecordProvider,
peer_info_provider: Option<PeerInfoProvider>,
prometheus_registry: Option<&mut Registry>,
) -> Self {
let (libp2p_metrics, metrics) = prometheus_registry
Expand Down Expand Up @@ -396,14 +365,6 @@ where
libp2p_metrics,
metrics,
protocol_version,
peer_info_provider,
// Don't need to keep additional connections by default
general_connected_peers_handler: None,
special_connected_peers_handler: None,
general_connected_peers_target: 0,
special_connected_peers_target: 0,
general_connected_peers_limit: 0,
special_connected_peers_limit: 0,
bootstrap_addresses: Vec::new(),
kademlia_mode: KademliaMode::Static(Mode::Client),
external_addresses: Vec::new(),
Expand Down Expand Up @@ -468,13 +429,6 @@ where
libp2p_metrics,
metrics,
protocol_version,
peer_info_provider,
general_connected_peers_handler: general_connection_decision_handler,
special_connected_peers_handler: special_connection_decision_handler,
general_connected_peers_target,
special_connected_peers_target,
general_connected_peers_limit,
special_connected_peers_limit,
bootstrap_addresses,
kademlia_mode,
external_addresses,
Expand Down Expand Up @@ -523,26 +477,6 @@ where
reserved_peers: reserved_peers.clone(),
dialing_interval: DIALING_INTERVAL_IN_SECS,
},
peer_info_config: PeerInfoConfig::new(PEER_INFO_PROTOCOL_NAME),
peer_info_provider,
general_connected_peers_config: general_connection_decision_handler.as_ref().map(|_| {
ConnectedPeersConfig {
log_target: GENERAL_CONNECTED_PEERS_PROTOCOL_LOG_TARGET,
target_connected_peers: general_connected_peers_target,
max_connected_peers: general_connected_peers_limit
.max(general_connected_peers_target),
..ConnectedPeersConfig::default()
}
}),
special_connected_peers_config: special_connection_decision_handler.as_ref().map(|_| {
ConnectedPeersConfig {
log_target: SPECIAL_CONNECTED_PEERS_PROTOCOL_LOG_TARGET,
target_connected_peers: special_connected_peers_target,
max_connected_peers: special_connected_peers_limit
.max(special_connected_peers_target),
..ConnectedPeersConfig::default()
}
}),
autonat: AutonatWrapperConfig {
inner_config: AutonatConfig {
use_connected: true,
Expand Down Expand Up @@ -658,8 +592,6 @@ where
libp2p_metrics,
metrics,
protocol_version,
general_connection_decision_handler,
special_connection_decision_handler,
bootstrap_addresses,
disable_bootstrap_on_start,
});
Expand Down
5 changes: 1 addition & 4 deletions crates/subspace-networking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ pub use crate::node::{
GetClosestPeersError, Node, SendRequestError, SubscribeError, TopicSubscription,
};
pub use crate::node_runner::NodeRunner;
pub use crate::protocols::peer_info::{
Config as PeerInfoConfig, Notification, NotificationHandler, PeerInfo, PeerInfoProvider,
};
pub use constructor::{
construct, peer_id, Config, CreationError, KademliaMode, LocalRecordProvider,
};
Expand All @@ -51,7 +48,7 @@ pub use protocols::request_response::handlers::piece_by_index::{
pub use protocols::request_response::handlers::segment_header::{
SegmentHeaderBySegmentIndexesRequestHandler, SegmentHeaderRequest, SegmentHeaderResponse,
};
pub use shared::{NewPeerInfo, PeerDiscovered};
pub use shared::PeerDiscovered;
pub use utils::multihash::Multihash;
pub use utils::unique_record_binary_heap::{KeyWrapper, UniqueRecordBinaryHeap};
pub use utils::PeerAddress;
6 changes: 0 additions & 6 deletions crates/subspace-networking/src/node.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::protocols::request_response::handlers::generic_request_handler::GenericRequest;
use crate::protocols::request_response::request_response_factory;
pub use crate::shared::NewPeerInfo;
use crate::shared::{Command, CreatedSubscription, PeerDiscovered, Shared};
use crate::utils::multihash::Multihash;
use crate::utils::rate_limiter::RateLimiterPermit;
Expand Down Expand Up @@ -546,11 +545,6 @@ impl Node {
Ok(())
}

/// Callback is called when we receive new [`crate::protocols::peer_info::PeerInfo`]
pub fn on_peer_info(&self, callback: HandlerFn<NewPeerInfo>) -> HandlerId {
self.shared.handlers.new_peer_info.add(callback)
}

/// Callback is called when a peer is disconnected.
pub fn on_disconnected_peer(&self, callback: HandlerFn<PeerId>) -> HandlerId {
self.shared.handlers.disconnected_peer.add(callback)
Expand Down
Loading

0 comments on commit 3dabbf1

Please sign in to comment.