Skip to content

Commit

Permalink
WIP libp2p#2831: compiles error free
Browse files Browse the repository at this point in the history
  • Loading branch information
efarg committed Dec 1, 2022
1 parent a70b944 commit a770fdf
Show file tree
Hide file tree
Showing 6 changed files with 598 additions and 580 deletions.
2 changes: 1 addition & 1 deletion core/src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ pub use multistream_select::{NegotiatedComplete, NegotiationError, ProtocolError
pub struct ProtocolName(Cow<'static, str>);

impl ProtocolName {
fn protocol_name(&self) -> &str {
pub fn protocol_name(&self) -> &str {
self.0.as_ref()
}
}
Expand Down
19 changes: 7 additions & 12 deletions src/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,24 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

use crate::core::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo};
use bytes::Bytes;
use crate::core::upgrade::{InboundUpgrade, OutboundUpgrade, ProtocolName, UpgradeInfo};
use futures::prelude::*;
use std::{iter, sync::Arc};

/// Implementation of `ConnectionUpgrade`. Convenient to use with small protocols.
#[derive(Debug)]
pub struct SimpleProtocol<F> {
info: Bytes,
info: ProtocolName,
// Note: we put the closure `F` in an `Arc` because Rust closures aren't automatically clonable
// yet.
upgrade: Arc<F>,
}

impl<F> SimpleProtocol<F> {
/// Builds a `SimpleProtocol`.
pub fn new<N>(info: N, upgrade: F) -> SimpleProtocol<F>
where
N: Into<Bytes>,
{
pub fn new(info: ProtocolName, upgrade: F) -> SimpleProtocol<F> {
SimpleProtocol {
info: info.into(),
info: info,
upgrade: Arc::new(upgrade),
}
}
Expand All @@ -55,8 +51,7 @@ impl<F> Clone for SimpleProtocol<F> {
}

impl<F> UpgradeInfo for SimpleProtocol<F> {
type Info = Bytes;
type InfoIter = iter::Once<Self::Info>;
type InfoIter = iter::Once<ProtocolName>;

fn protocol_info(&self) -> Self::InfoIter {
iter::once(self.info.clone())
Expand All @@ -73,7 +68,7 @@ where
type Error = E;
type Future = O;

fn upgrade_inbound(self, socket: C, _: Self::Info) -> Self::Future {
fn upgrade_inbound(self, socket: C, _: ProtocolName) -> Self::Future {
let upgrade = &self.upgrade;
upgrade(socket)
}
Expand All @@ -89,7 +84,7 @@ where
type Error = E;
type Future = O;

fn upgrade_outbound(self, socket: C, _: Self::Info) -> Self::Future {
fn upgrade_outbound(self, socket: C, _: ProtocolName) -> Self::Future {
let upgrade = &self.upgrade;
upgrade(socket)
}
Expand Down
Loading

0 comments on commit a770fdf

Please sign in to comment.