Addressing #473 ... if I understood the ticket right, we want to pass… (#1395)

* Addressing #473 ... if I understood the ticket right, we want to pass through whatever the application provides as a topic identifier, leaving hashing (or not hashing) up to the application.

* Remove TopicDescriptor and use Topic newtype everywhere

* PR feedback

Use From<Topic> instead of Into<String>
Use impl Into<Topic> instead of Topic in public API

Co-authored-by: Peat Bakke <peat@peat.org>
This commit is contained in:
Rüdiger Klaehn
2020-01-27 15:23:01 +01:00
committed by Pierre Krieger
parent 2ef7c40cda
commit 3b50cbd1b8
6 changed files with 46 additions and 142 deletions

View File

@ -19,11 +19,11 @@
// DEALINGS IN THE SOFTWARE.
use crate::rpc_proto;
use crate::topic::TopicHash;
use futures::prelude::*;
use crate::topic::Topic;
use libp2p_core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo, PeerId, upgrade};
use prost::Message;
use std::{error, fmt, io, iter, pin::Pin};
use futures::{Future, io::{AsyncRead, AsyncWrite}};
/// Implementation of `ConnectionUpgrade` for the floodsub protocol.
#[derive(Debug, Clone, Default)]
@ -68,7 +68,7 @@ where
sequence_number: publish.seqno.unwrap_or_default(),
topics: publish.topic_ids
.into_iter()
.map(TopicHash::from_raw)
.map(Topic::new)
.collect(),
});
}
@ -83,7 +83,7 @@ where
} else {
FloodsubSubscriptionAction::Unsubscribe
},
topic: TopicHash::from_raw(sub.topic_id.unwrap_or_default()),
topic: Topic::new(sub.topic_id.unwrap_or_default()),
})
.collect(),
})
@ -184,7 +184,7 @@ impl FloodsubRpc {
seqno: Some(msg.sequence_number),
topic_ids: msg.topics
.into_iter()
.map(TopicHash::into_string)
.map(|topic| topic.into())
.collect()
}
})
@ -194,7 +194,7 @@ impl FloodsubRpc {
.map(|topic| {
rpc_proto::rpc::SubOpts {
subscribe: Some(topic.action == FloodsubSubscriptionAction::Subscribe),
topic_id: Some(topic.topic.into_string())
topic_id: Some(topic.topic.into())
}
})
.collect()
@ -221,7 +221,7 @@ pub struct FloodsubMessage {
/// List of topics this message belongs to.
///
/// Each message can belong to multiple topics at once.
pub topics: Vec<TopicHash>,
pub topics: Vec<Topic>,
}
/// A subscription received by the floodsub system.
@ -230,7 +230,7 @@ pub struct FloodsubSubscription {
/// Action to perform.
pub action: FloodsubSubscriptionAction,
/// The topic from which to subscribe or unsubscribe.
pub topic: TopicHash,
pub topic: Topic,
}
/// Action that a subscription wants to perform.