Add default topics and initial topic subscription

This commit is contained in:
Age Manning
2019-03-13 15:37:44 +11:00
parent 8ee3523abd
commit 23a8fbfc74
4 changed files with 26 additions and 4 deletions

View File

@@ -5,6 +5,7 @@ use libp2p::{
tokio_io::{AsyncRead, AsyncWrite},
NetworkBehaviour, PeerId,
};
use types::Topic;
/// Builds the network behaviour for the libp2p Swarm.
/// Implements gossipsub message routing.
@@ -57,6 +58,10 @@ impl<TSubstream: AsyncRead + AsyncWrite> Behaviour<TSubstream> {
}
impl<TSubstream: AsyncRead + AsyncWrite> Behaviour<TSubstream> {
pub fn subscribe(&mut self, topic: Topic) -> bool {
self.gossipsub.subscribe(topic)
}
pub fn send_message(&self, message: String) {
// TODO: Encode and send via gossipsub