Rename libp2p to eth2-libp2p

This commit is contained in:
Age Manning 2019-03-20 15:09:24 +11:00
parent 7c7f81d188
commit e080f63811
No known key found for this signature in database
GPG Key ID: 05EED64B79E06A93
16 changed files with 37 additions and 34 deletions

View File

@ -22,6 +22,7 @@ members = [
"beacon_node/db", "beacon_node/db",
"beacon_node/client", "beacon_node/client",
"beacon_node/network", "beacon_node/network",
"beacon_node/eth2-libp2p",
"beacon_node/rpc", "beacon_node/rpc",
"beacon_node/version", "beacon_node/version",
"beacon_node/beacon_chain", "beacon_node/beacon_chain",

View File

@ -1,5 +1,5 @@
[package] [package]
name = "libp2p" name = "eth2-libp2p"
version = "0.1.0" version = "0.1.0"
authors = ["Age Manning <Age@AgeManning.com>"] authors = ["Age Manning <Age@AgeManning.com>"]
edition = "2018" edition = "2018"

View File

@ -6,7 +6,7 @@ edition = "2018"
[dependencies] [dependencies]
beacon_chain = { path = "../beacon_chain" } beacon_chain = { path = "../beacon_chain" }
libp2p = { path = "../libp2p" } eth2-libp2p = { path = "../eth2-libp2p" }
version = { path = "../version" } version = { path = "../version" }
types = { path = "../../eth2/types" } types = { path = "../../eth2/types" }
slog = "2.4.1" slog = "2.4.1"

View File

@ -1,5 +1,5 @@
// generates error types // generates error types
use libp2p; use eth2_libp2p;
use error_chain::{ use error_chain::{
error_chain, error_chain_processing, impl_error_chain_kind, impl_error_chain_processed, error_chain, error_chain_processing, impl_error_chain_kind, impl_error_chain_processed,
@ -8,6 +8,6 @@ use error_chain::{
error_chain! { error_chain! {
links { links {
Libp2p(libp2p::error::Error, libp2p::error::ErrorKind); Libp2p(eth2_libp2p::error::Error, eth2_libp2p::error::ErrorKind);
} }
} }

View File

@ -5,5 +5,5 @@ mod message_handler;
mod service; mod service;
pub mod sync; pub mod sync;
pub use libp2p::NetworkConfig; pub use eth2_libp2p::NetworkConfig;
pub use service::Service; pub use service::Service;

View File

@ -3,11 +3,11 @@ use crate::error;
use crate::service::{NetworkMessage, OutgoingMessage}; use crate::service::{NetworkMessage, OutgoingMessage};
use crate::sync::SimpleSync; use crate::sync::SimpleSync;
use crossbeam_channel::{unbounded as channel, Sender}; use crossbeam_channel::{unbounded as channel, Sender};
use futures::future; use eth2_libp2p::{
use libp2p::{
rpc::{RPCMethod, RPCRequest, RPCResponse}, rpc::{RPCMethod, RPCRequest, RPCResponse},
HelloMessage, PeerId, RPCEvent, HelloMessage, PeerId, RPCEvent,
}; };
use futures::future;
use slog::warn; use slog::warn;
use slog::{debug, trace}; use slog::{debug, trace};
use std::collections::HashMap; use std::collections::HashMap;

View File

@ -3,20 +3,20 @@ use crate::error;
use crate::message_handler::{HandlerMessage, MessageHandler}; use crate::message_handler::{HandlerMessage, MessageHandler};
use crate::NetworkConfig; use crate::NetworkConfig;
use crossbeam_channel::{unbounded as channel, Sender, TryRecvError}; use crossbeam_channel::{unbounded as channel, Sender, TryRecvError};
use eth2_libp2p::RPCEvent;
use eth2_libp2p::Service as LibP2PService;
use eth2_libp2p::{Libp2pEvent, PeerId};
use futures::prelude::*; use futures::prelude::*;
use futures::sync::oneshot; use futures::sync::oneshot;
use futures::Stream; use futures::Stream;
use libp2p::RPCEvent;
use libp2p::Service as LibP2PService;
use libp2p::{Libp2pEvent, PeerId};
use slog::{debug, info, o, trace}; use slog::{debug, info, o, trace};
use std::sync::Arc; use std::sync::Arc;
use tokio::runtime::TaskExecutor; use tokio::runtime::TaskExecutor;
/// Service that handles communication between internal services and the libp2p network service. /// Service that handles communication between internal services and the eth2_libp2p network service.
pub struct Service { pub struct Service {
//libp2p_service: Arc<Mutex<LibP2PService>>, //eth2_libp2p_service: Arc<Mutex<LibP2PService>>,
libp2p_exit: oneshot::Sender<()>, eth2_libp2p_exit: oneshot::Sender<()>,
network_send: crossbeam_channel::Sender<NetworkMessage>, network_send: crossbeam_channel::Sender<NetworkMessage>,
//message_handler: MessageHandler, //message_handler: MessageHandler,
//message_handler_send: Sender<HandlerMessage>, //message_handler_send: Sender<HandlerMessage>,
@ -40,20 +40,20 @@ impl Service {
message_handler_log, message_handler_log,
)?; )?;
// launch libp2p service // launch eth2_libp2p service
let libp2p_log = log.new(o!("Service" => "Libp2p")); let eth2_libp2p_log = log.new(o!("Service" => "Libp2p"));
let libp2p_service = LibP2PService::new(config.clone(), libp2p_log)?; let eth2_libp2p_service = LibP2PService::new(config.clone(), eth2_libp2p_log)?;
// TODO: Spawn thread to handle libp2p messages and pass to message handler thread. // TODO: Spawn thread to handle eth2_libp2p messages and pass to message handler thread.
let libp2p_exit = spawn_service( let eth2_libp2p_exit = spawn_service(
libp2p_service, eth2_libp2p_service,
network_recv, network_recv,
message_handler_send, message_handler_send,
executor, executor,
log, log,
)?; )?;
let network_service = Service { let network_service = Service {
libp2p_exit, eth2_libp2p_exit,
network_send: network_send.clone(), network_send: network_send.clone(),
}; };
@ -72,7 +72,7 @@ impl Service {
} }
fn spawn_service( fn spawn_service(
libp2p_service: LibP2PService, eth2_libp2p_service: LibP2PService,
network_recv: crossbeam_channel::Receiver<NetworkMessage>, network_recv: crossbeam_channel::Receiver<NetworkMessage>,
message_handler_send: crossbeam_channel::Sender<HandlerMessage>, message_handler_send: crossbeam_channel::Sender<HandlerMessage>,
executor: &TaskExecutor, executor: &TaskExecutor,
@ -83,7 +83,7 @@ fn spawn_service(
// spawn on the current executor // spawn on the current executor
executor.spawn( executor.spawn(
network_service( network_service(
libp2p_service, eth2_libp2p_service,
network_recv, network_recv,
message_handler_send, message_handler_send,
log.clone(), log.clone(),
@ -100,18 +100,18 @@ fn spawn_service(
} }
fn network_service( fn network_service(
mut libp2p_service: LibP2PService, mut eth2_libp2p_service: LibP2PService,
network_recv: crossbeam_channel::Receiver<NetworkMessage>, network_recv: crossbeam_channel::Receiver<NetworkMessage>,
message_handler_send: crossbeam_channel::Sender<HandlerMessage>, message_handler_send: crossbeam_channel::Sender<HandlerMessage>,
log: slog::Logger, log: slog::Logger,
) -> impl futures::Future<Item = (), Error = libp2p::error::Error> { ) -> impl futures::Future<Item = (), Error = eth2_libp2p::error::Error> {
futures::future::poll_fn(move || -> Result<_, libp2p::error::Error> { futures::future::poll_fn(move || -> Result<_, eth2_libp2p::error::Error> {
// poll the swarm // poll the swarm
loop { loop {
match libp2p_service.poll() { match eth2_libp2p_service.poll() {
Ok(Async::Ready(Some(Libp2pEvent::RPC(peer_id, rpc_event)))) => { Ok(Async::Ready(Some(Libp2pEvent::RPC(peer_id, rpc_event)))) => {
trace!( trace!(
libp2p_service.log, eth2_libp2p_service.log,
"RPC Event: RPC message received: {:?}", "RPC Event: RPC message received: {:?}",
rpc_event rpc_event
); );
@ -120,13 +120,13 @@ fn network_service(
.map_err(|_| "failed to send rpc to handler")?; .map_err(|_| "failed to send rpc to handler")?;
} }
Ok(Async::Ready(Some(Libp2pEvent::PeerDialed(peer_id)))) => { Ok(Async::Ready(Some(Libp2pEvent::PeerDialed(peer_id)))) => {
debug!(libp2p_service.log, "Peer Dialed: {:?}", peer_id); debug!(eth2_libp2p_service.log, "Peer Dialed: {:?}", peer_id);
message_handler_send message_handler_send
.send(HandlerMessage::PeerDialed(peer_id)) .send(HandlerMessage::PeerDialed(peer_id))
.map_err(|_| "failed to send rpc to handler")?; .map_err(|_| "failed to send rpc to handler")?;
} }
Ok(Async::Ready(Some(Libp2pEvent::Message(m)))) => debug!( Ok(Async::Ready(Some(Libp2pEvent::Message(m)))) => debug!(
libp2p_service.log, eth2_libp2p_service.log,
"Network Service: Message received: {}", m "Network Service: Message received: {}", m
), ),
_ => break, _ => break,
@ -143,7 +143,7 @@ fn network_service(
trace!(log, "Sending RPC Event: {:?}", rpc_event); trace!(log, "Sending RPC Event: {:?}", rpc_event);
//TODO: Make swarm private //TODO: Make swarm private
//TODO: Implement correct peer id topic message handling //TODO: Implement correct peer id topic message handling
libp2p_service.swarm.send_rpc(peer_id, rpc_event); eth2_libp2p_service.swarm.send_rpc(peer_id, rpc_event);
} }
OutgoingMessage::NotifierTest => { OutgoingMessage::NotifierTest => {
debug!(log, "Received message from notifier"); debug!(log, "Received message from notifier");
@ -152,7 +152,9 @@ fn network_service(
} }
Err(TryRecvError::Empty) => break, Err(TryRecvError::Empty) => break,
Err(TryRecvError::Disconnected) => { Err(TryRecvError::Disconnected) => {
return Err(libp2p::error::Error::from("Network channel disconnected")); return Err(eth2_libp2p::error::Error::from(
"Network channel disconnected",
));
} }
} }
} }
@ -163,7 +165,7 @@ fn network_service(
/// Types of messages that the network service can receive. /// Types of messages that the network service can receive.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum NetworkMessage { pub enum NetworkMessage {
/// Send a message to libp2p service. /// Send a message to eth2_libp2p service.
//TODO: Define typing for messages across the wire //TODO: Define typing for messages across the wire
Send(PeerId, OutgoingMessage), Send(PeerId, OutgoingMessage),
} }

View File

@ -1,6 +1,6 @@
use crate::beacon_chain::BeaconChain; use crate::beacon_chain::BeaconChain;
use libp2p::rpc::HelloMessage; use eth2_libp2p::rpc::HelloMessage;
use libp2p::PeerId; use eth2_libp2p::PeerId;
use slog::{debug, o}; use slog::{debug, o};
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::Arc; use std::sync::Arc;