Add libp2p transport - tcp/ws/secio and multiplexing.

This commit is contained in:
Age Manning
2019-03-06 23:31:08 +11:00
parent b68adc1ae3
commit ac639c6427
8 changed files with 108 additions and 49 deletions

View File

@@ -2,8 +2,7 @@
pub mod error;
mod message_handler;
mod messages;
mod network_config;
mod service;
pub use network_config::NetworkConfig;
pub use libp2p::NetworkConfig;
pub use service::Service;

View File

@@ -1,38 +0,0 @@
use libp2p::{GossipsubConfig, GossipsubConfigBuilder};
use std::net::IpAddr;
use version;
#[derive(Debug, Clone)]
/// Network configuration for lighthouse.
pub struct NetworkConfig {
//TODO: stubbing networking initial params, change in the future
/// IP address to listen on.
pub listen_addresses: Option<Vec<IpAddr>>,
/// Listen port UDP/TCP.
pub listen_port: Option<u16>,
/// Gossipsub configuration parameters.
pub gs_config: GossipsubConfig,
/// List of nodes to initially connect to.
pub boot_nodes: Vec<String>,
/// Client version
pub client_version: String,
}
impl Default for NetworkConfig {
/// Generate a default network configuration.
fn default() -> Self {
NetworkConfig {
listen_addresses: None,
listen_port: None,
gs_config: GossipsubConfigBuilder::new().build(),
boot_nodes: Vec::new(),
client_version: version::version(),
}
}
}
impl NetworkConfig {
pub fn new() -> Self {
NetworkConfig::default()
}
}

View File

@@ -30,10 +30,9 @@ impl Service {
// launch libp2p service
let libp2p_log = log.new(o!("Service" => "Libp2p"));
let libp2p_service = LibP2PService::new(libp2p_log);
let libp2p_service = LibP2PService::new(config, libp2p_log);
// TODO: Spawn thread to handle libp2p messages and pass to message handler thread.
let network = Service {};
Ok((Arc::new(network), network_send))