Skip to content
This repository has been archived by the owner on Dec 26, 2024. It is now read-only.

Commit

Permalink
refactor: remove dial from NetworkManager (#1808)
Browse files Browse the repository at this point in the history
refactor(network): remove dial from NetworkManager
  • Loading branch information
eitanm-starkware authored Mar 14, 2024
1 parent a74c8d2 commit 88f2623
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
29 changes: 19 additions & 10 deletions crates/papyrus_network/src/bin/p2p_integration_endpoint.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::str::FromStr;
use std::time::Duration;

use clap::Parser;
use papyrus_network::{network_manager, NetworkConfig};
use libp2p::PeerId;
use papyrus_network::{network_manager, NetworkConfig, PeerAddressConfig};
use papyrus_storage::{open_storage, StorageConfig};

/// A dummy P2P capable node for integration with other P2P capable nodes.
Expand All @@ -16,9 +18,17 @@ struct Args {
#[arg(short, long)]
quic_port: u16,

/// Address this node attempts to dial to.
/// Id of the peer node.
#[arg(short, long)]
dial_address: Option<String>,
peer_id: String,

/// IP address of the peer node.
#[arg(short, long)]
peer_ip: String,

/// TCP port the peer node listens on.
#[arg(short, long)]
peer_tcp_port: u16,

/// Amount of time (in seconds) to wait until closing an idle connection.
#[arg(short = 't', long, default_value_t = 1)]
Expand All @@ -31,21 +41,20 @@ async fn main() {

let (storage_reader, _storage_writer) =
open_storage(StorageConfig::default()).expect("failed to open storage");
let mut network_manager = network_manager::NetworkManager::new(
let network_manager = network_manager::NetworkManager::new(
NetworkConfig {
tcp_port: args.tcp_port,
quic_port: args.quic_port,
session_timeout: Duration::from_secs(10),
idle_connection_timeout: Duration::from_secs(args.idle_connection_timeout),
header_buffer_size: 100000,
peer: None,
peer: Some(PeerAddressConfig {
peer_id: PeerId::from_str(&args.peer_id).expect("Invalid peer ID"),
tcp_port: args.peer_tcp_port,
ip: args.peer_ip,
}),
},
storage_reader,
);
// TODO: use peer config from the network config and remove the dial function from the network
// manager (use the dial within the run function instead of here).
if let Some(dial_address) = args.dial_address.as_ref() {
network_manager.dial(dial_address);
}
network_manager.run().await.expect("Network manager failed");
}
8 changes: 1 addition & 7 deletions crates/papyrus_network/src/network_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use papyrus_storage::StorageReader;
use tracing::{debug, error, trace};

use self::swarm_trait::SwarmTrait;
use crate::bin_utils::{build_swarm, dial};
use crate::bin_utils::build_swarm;
use crate::converters::{Router, RouterError};
use crate::db_executor::{self, BlockHeaderDBExecutor, DBExecutor, Data, QueryId};
use crate::streamed_bytes::behaviour::{Behaviour, SessionError};
Expand Down Expand Up @@ -293,10 +293,4 @@ impl NetworkManager {
let db_executor = BlockHeaderDBExecutor::new(storage_reader);
Self::generic_new(swarm, db_executor, header_buffer_size, peer)
}

// TODO(shahak): Move this to the constructor and add the address to the config once we have
// p2p sync.
pub fn dial(&mut self, dial_address: &str) {
dial(&mut self.swarm, dial_address);
}
}

0 comments on commit 88f2623

Please sign in to comment.