mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-28 09:11:34 +00:00
feat: replace ProtocolName
with AsRef<str>
Previously, a protocol could be any sequence of bytes as long as it started with `/`. Now, we directly parse a protocol as `String` which enforces it to be valid UTF8. To notify users of this change, we delete the `ProtocolName` trait. The new requirement is that users need to provide a type that implements `AsRef<str>`. We also add a `StreamProtocol` newtype in `libp2p-swarm` which provides an easy way for users to ensure their protocol strings are compliant. The newtype enforces that protocol strings start with `/`. `StreamProtocol` also implements `AsRef<str>`, meaning users can directly use it in their upgrades. `multistream-select` by itself only changes marginally with this patch. The only thing we enforce in the type-system is that protocols must implement `AsRef<str>`. Resolves: #2831. Pull-Request: #3746.
This commit is contained in:
@ -52,7 +52,7 @@ use crate::handler::{Handler, HandlerEvent, HandlerIn};
|
||||
use crate::mcache::MessageCache;
|
||||
use crate::metrics::{Churn, Config as MetricsConfig, Inclusion, Metrics, Penalty};
|
||||
use crate::peer_score::{PeerScore, PeerScoreParams, PeerScoreThresholds, RejectReason};
|
||||
use crate::protocol::{ProtocolConfig, SIGNING_PREFIX};
|
||||
use crate::protocol::SIGNING_PREFIX;
|
||||
use crate::subscription_filter::{AllowAllSubscriptionFilter, TopicSubscriptionFilter};
|
||||
use crate::time_cache::{DuplicateCache, TimeCache};
|
||||
use crate::topic::{Hasher, Topic, TopicHash};
|
||||
@ -3317,7 +3317,7 @@ where
|
||||
_: &Multiaddr,
|
||||
) -> Result<THandler<Self>, ConnectionDenied> {
|
||||
Ok(Handler::new(
|
||||
ProtocolConfig::new(&self.config),
|
||||
self.config.protocol_config(),
|
||||
self.config.idle_timeout(),
|
||||
))
|
||||
}
|
||||
@ -3330,7 +3330,7 @@ where
|
||||
_: Endpoint,
|
||||
) -> Result<THandler<Self>, ConnectionDenied> {
|
||||
Ok(Handler::new(
|
||||
ProtocolConfig::new(&self.config),
|
||||
self.config.protocol_config(),
|
||||
self.config.idle_timeout(),
|
||||
))
|
||||
}
|
||||
|
Reference in New Issue
Block a user