mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-24 07:11:38 +00:00
Rewrite floodsub to use the ProtocolsHandler (#603)
* Move lib.rs to protocol.rs * Rewrite floodsub for ProtocolsHandler * Add a FloodsubBehaviour * Fix closing floodsub after a message * Address concern * Make it conform to the protocol * Make it really conformant * Address concerns
This commit is contained in:
@ -59,6 +59,27 @@ impl Topic {
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<TopicHash> for Topic {
|
||||
#[inline]
|
||||
fn as_ref(&self) -> &TopicHash {
|
||||
&self.hash
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Topic> for TopicHash {
|
||||
#[inline]
|
||||
fn from(topic: Topic) -> TopicHash {
|
||||
topic.hash
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a Topic> for TopicHash {
|
||||
#[inline]
|
||||
fn from(topic: &'a Topic) -> TopicHash {
|
||||
topic.hash.clone()
|
||||
}
|
||||
}
|
||||
|
||||
/// Builder for a `TopicHash`.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TopicBuilder {
|
||||
@ -78,15 +99,17 @@ impl TopicBuilder {
|
||||
|
||||
/// Turns the builder into an actual `Topic`.
|
||||
pub fn build(self) -> Topic {
|
||||
let bytes = self.builder
|
||||
let bytes = self
|
||||
.builder
|
||||
.write_to_bytes()
|
||||
.expect("protobuf message is always valid");
|
||||
// TODO: https://github.com/libp2p/rust-libp2p/issues/473
|
||||
let hash = TopicHash {
|
||||
hash: bs58::encode(&bytes).into_string(),
|
||||
};
|
||||
Topic {
|
||||
descriptor: self.builder,
|
||||
hash: hash,
|
||||
hash,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user