mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2024-12-28 14:57:17 +00:00
Adds basic structure for swarm behaviour and topology.
This commit is contained in:
parent
ac639c6427
commit
e8e4c4ab9b
@ -9,3 +9,4 @@ edition = "2018"
|
||||
libp2p = { git = "https://github.com/SigP/rust-libp2p", branch = "gossipsub" }
|
||||
slog = "2.4.1"
|
||||
version = { path = "../version" }
|
||||
tokio = "0.1.16"
|
||||
|
@ -1,14 +1,17 @@
|
||||
use crate::NetworkConfig;
|
||||
use libp2p::gossipsub::GossipsubEvent;
|
||||
use libp2p::PeerId;
|
||||
use libp2p::core::{muxing::StreamMuxer, nodes::Substream};
|
||||
use libp2p::gossipsub::{Gossipsub, GossipsubConfig, GossipsubEvent};
|
||||
use libp2p::{build_tcp_ws_secio_mplex_yamux, core, secio, Transport};
|
||||
use libp2p::{core::swarm::NetworkBehaviour, PeerId, Swarm};
|
||||
use slog::debug;
|
||||
use std::error;
|
||||
|
||||
/// The configuration and state of the libp2p components for the beacon node.
|
||||
pub struct Service {
|
||||
/// The libp2p Swarm handler.
|
||||
swarm: String,
|
||||
/// This node's PeerId.
|
||||
peer_id: PeerId,
|
||||
local_peer_id: PeerId,
|
||||
}
|
||||
|
||||
impl Service {
|
||||
@ -16,15 +19,22 @@ impl Service {
|
||||
debug!(log, "Libp2p Service starting");
|
||||
|
||||
let local_private_key = config.local_private_key;
|
||||
let peer_id = local_private_key.to_peer_id();
|
||||
debug!(log, "Local peer id: {:?}", peer_id);
|
||||
let local_peer_id = local_private_key.to_peer_id();
|
||||
debug!(log, "Local peer id: {:?}", local_peer_id);
|
||||
|
||||
// Set up the transport
|
||||
let transport = build_transport(local_private_key);
|
||||
// Set up gossipsub routing
|
||||
let behaviour = build_behaviour(local_peer_id, config.gs_config);
|
||||
// Set up Topology
|
||||
let topology = local_peer_id;
|
||||
|
||||
//let transport = libp2p::
|
||||
let swarm = Swarm::new(transport, behaviour, topology);
|
||||
|
||||
Service { peer_id }
|
||||
Service {
|
||||
local_peer_id,
|
||||
swarm,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,3 +58,12 @@ fn build_transport(
|
||||
// in the future.
|
||||
build_tcp_ws_secio_mplex_yamux(local_private_key)
|
||||
}
|
||||
|
||||
/// Builds the network behaviour for the libp2p Swarm.
|
||||
fn build_behaviour<TSubstream>(
|
||||
local_peer_id: PeerId,
|
||||
config: GossipsubConfig,
|
||||
) -> impl NetworkBehaviour {
|
||||
// TODO: Add Kademlia/Peer discovery
|
||||
Gossipsub::new(local_peer_id, config)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user