commit
6f1243368f
@ -38,7 +38,7 @@ impl Client {
|
|||||||
// Start the network thread
|
// Start the network thread
|
||||||
let network_state = NetworkState::new(
|
let network_state = NetworkState::new(
|
||||||
&config.data_dir,
|
&config.data_dir,
|
||||||
&config.p2p_listen_port,
|
config.p2p_listen_port,
|
||||||
&log).expect("Network setup failed"); let (network_thread, network_tx, network_rx) = {
|
&log).expect("Network setup failed"); let (network_thread, network_tx, network_rx) = {
|
||||||
let (message_sender, message_receiver) = unbounded();
|
let (message_sender, message_receiver) = unbounded();
|
||||||
let (event_sender, event_receiver) = unbounded();
|
let (event_sender, event_receiver) = unbounded();
|
||||||
@ -46,9 +46,9 @@ impl Client {
|
|||||||
let thread = thread::spawn(move || {
|
let thread = thread::spawn(move || {
|
||||||
network_listen(
|
network_listen(
|
||||||
network_state,
|
network_state,
|
||||||
event_sender,
|
&event_sender,
|
||||||
message_receiver,
|
message_receiver,
|
||||||
network_log,
|
&network_log,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
(thread, message_sender, event_receiver)
|
(thread, message_sender, event_receiver)
|
||||||
|
@ -70,7 +70,6 @@ fn handle_network_message(
|
|||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
_ => Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
|
@ -4,13 +4,16 @@ pub enum WireMessageDecodeError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub enum WireMessageHeader {
|
pub enum WireMessageHeader {
|
||||||
|
Blocks,
|
||||||
|
/*
|
||||||
|
// Leave out until used
|
||||||
Status,
|
Status,
|
||||||
NewBlockHashes,
|
NewBlockHashes,
|
||||||
GetBlockHashes,
|
GetBlockHashes,
|
||||||
BlockHashes,
|
BlockHashes,
|
||||||
GetBlocks,
|
GetBlocks,
|
||||||
Blocks,
|
|
||||||
NewBlock,
|
NewBlock,
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct WireMessage<'a> {
|
pub struct WireMessage<'a> {
|
||||||
|
@ -37,9 +37,9 @@ use self::bytes::Bytes;
|
|||||||
pub use self::libp2p_floodsub::Message;
|
pub use self::libp2p_floodsub::Message;
|
||||||
|
|
||||||
pub fn listen(state: NetworkState,
|
pub fn listen(state: NetworkState,
|
||||||
events_to_app: UnboundedSender<NetworkEvent>,
|
events_to_app: &UnboundedSender<NetworkEvent>,
|
||||||
raw_rx: UnboundedReceiver<OutgoingMessage>,
|
raw_rx: UnboundedReceiver<OutgoingMessage>,
|
||||||
log: Logger)
|
log: &Logger)
|
||||||
{
|
{
|
||||||
let peer_store = state.peer_store;
|
let peer_store = state.peer_store;
|
||||||
let peer_id = state.peer_id;
|
let peer_id = state.peer_id;
|
||||||
@ -83,7 +83,7 @@ pub fn listen(state: NetworkState,
|
|||||||
let kad_config = libp2p_kad::KademliaConfig {
|
let kad_config = libp2p_kad::KademliaConfig {
|
||||||
parallelism: 3,
|
parallelism: 3,
|
||||||
record_store: (),
|
record_store: (),
|
||||||
peer_store: peer_store,
|
peer_store,
|
||||||
local_peer_id: peer_id.clone(),
|
local_peer_id: peer_id.clone(),
|
||||||
timeout: Duration::from_secs(2)
|
timeout: Duration::from_secs(2)
|
||||||
};
|
};
|
||||||
|
@ -36,7 +36,7 @@ impl NetworkState {
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
// config: LighthouseConfig,
|
// config: LighthouseConfig,
|
||||||
base_dir: &Path,
|
base_dir: &Path,
|
||||||
listen_port: &u16,
|
listen_port: u16,
|
||||||
log: &Logger)
|
log: &Logger)
|
||||||
-> Result <Self, Box<Error>>
|
-> Result <Self, Box<Error>>
|
||||||
{
|
{
|
||||||
@ -71,12 +71,12 @@ impl NetworkState {
|
|||||||
|
|
||||||
/// Return a TCP multiaddress on 0.0.0.0 for a given port.
|
/// Return a TCP multiaddress on 0.0.0.0 for a given port.
|
||||||
pub fn multiaddr_on_port(port: &str) -> Multiaddr {
|
pub fn multiaddr_on_port(port: &str) -> Multiaddr {
|
||||||
return format!("/ip4/0.0.0.0/tcp/{}", port)
|
format!("/ip4/0.0.0.0/tcp/{}", port)
|
||||||
.parse::<Multiaddr>().unwrap()
|
.parse::<Multiaddr>().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_peer(&mut self,
|
pub fn add_peer(&mut self,
|
||||||
peer_id: PeerId,
|
peer_id: &PeerId,
|
||||||
multiaddr: Multiaddr,
|
multiaddr: Multiaddr,
|
||||||
duration_secs: u64) {
|
duration_secs: u64) {
|
||||||
self.peer_store.peer_or_create(&peer_id)
|
self.peer_store.peer_or_create(&peer_id)
|
||||||
@ -113,7 +113,7 @@ impl NetworkState {
|
|||||||
let s_string = pem::encode(&pem_key);
|
let s_string = pem::encode(&pem_key);
|
||||||
let path = base_dir.join(LOCAL_PEM_FILE);
|
let path = base_dir.join(LOCAL_PEM_FILE);
|
||||||
let mut s_file = File::create(path)?;
|
let mut s_file = File::create(path)?;
|
||||||
s_file.write(s_string.as_bytes())?;
|
s_file.write_all(s_string.as_bytes())?;
|
||||||
Ok(sk)
|
Ok(sk)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user