Add PubsubMessage and publish function to behaviour

This commit is contained in:
Age Manning
2019-03-25 22:00:11 +11:00
parent 214fb5b8ff
commit 05369df7e8
6 changed files with 78 additions and 12 deletions

View File

@@ -109,7 +109,7 @@ where
let state = self.get_state();
HelloMessage {
network_id: spec.network_id,
network_id: spec.chain_id,
latest_finalized_root: state.finalized_root,
latest_finalized_epoch: state.finalized_epoch,
best_root: self.best_block_root(),

View File

@@ -3,7 +3,7 @@ use crate::error;
use crate::message_handler::{HandlerMessage, MessageHandler};
use crate::NetworkConfig;
use crossbeam_channel::{unbounded as channel, Sender, TryRecvError};
use eth2_libp2p::RPCEvent;
use eth2_libp2p::{RPCEvent, PublishMessage};
use eth2_libp2p::Service as LibP2PService;
use eth2_libp2p::{Libp2pEvent, PeerId};
use futures::prelude::*;
@@ -12,6 +12,7 @@ use futures::Stream;
use slog::{debug, info, o, trace};
use std::sync::Arc;
use tokio::runtime::TaskExecutor;
use types::{BeaconBlock, Topic};
/// Service that handles communication between internal services and the eth2_libp2p network service.
pub struct Service {
@@ -161,7 +162,12 @@ fn network_service(
return Err(eth2_libp2p::error::Error::from(
"Network channel disconnected",
));
}
},
Ok(NetworkMessage::Publish(topic, message) => {
debug!(log, "Sending message on topic {:?}", topic);
libp2p_service.swarm.publish(topic,message)
}
}
Ok(Async::NotReady)
@@ -174,6 +180,8 @@ pub enum NetworkMessage {
/// Send a message to libp2p service.
//TODO: Define typing for messages across the wire
Send(PeerId, OutgoingMessage),
/// Publish a message to gossipsub
Publish(Topic, PublishMessage),
}
/// Type of outgoing messages that can be sent through the network service.
@@ -184,3 +192,4 @@ pub enum OutgoingMessage {
//TODO: Remove
NotifierTest,
}