Skip to content

Commit

Permalink
squash! Use upstream libp2p instead of our fork
Browse files Browse the repository at this point in the history
  • Loading branch information
rishflab committed Oct 13, 2021
1 parent 48c29a2 commit 12a4956
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 39 deletions.
35 changes: 2 additions & 33 deletions swap/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ mod tests {
struct StaticQuoteAsbEvent;

#[derive(libp2p::NetworkBehaviour)]
#[behaviour(out_event = "StaticQuoteAsbEvent")]
#[behaviour(event_process = true)]
struct StaticQuoteAsbBehaviour {
rendezvous: asb::rendezous::Behaviour,
// Support `Ping` as a workaround until https://github.com/libp2p/rust-libp2p/issues/2109 is fixed.
Expand All @@ -141,25 +141,6 @@ mod tests {
#[behaviour(ignore)]
registered: bool,
}

impl From<RequestResponseEvent<(), quote::BidQuote>> for StaticQuoteAsbEvent {
fn from(_: RequestResponseEvent<(), BidQuote>) -> Self {
StaticQuoteAsbEvent
}
}

impl From<libp2p::ping::Event> for StaticQuoteAsbEvent {
fn from(_: libp2p::ping::Event) -> Self {
StaticQuoteAsbEvent
}
}

impl From<libp2p::rendezvous::client::Event> for StaticQuoteAsbEvent {
fn from(_: libp2p::rendezvous::client::Event) -> Self {
StaticQuoteAsbEvent
}
}

impl NetworkBehaviourEventProcess<libp2p::rendezvous::client::Event> for StaticQuoteAsbBehaviour {
fn inject_event(&mut self, event: libp2p::rendezvous::client::Event) {
if let libp2p::rendezvous::client::Event::Registered { .. } = event {
Expand Down Expand Up @@ -189,7 +170,7 @@ mod tests {
struct RendezvousPointEvent;

#[derive(libp2p::NetworkBehaviour)]
#[behaviour(out_event = "RendezvousPointEvent")]
#[behaviour(event_process = true)]
struct RendezvousPointBehaviour {
rendezvous: libp2p::rendezvous::server::Behaviour,
// Support `Ping` as a workaround until https://github.com/libp2p/rust-libp2p/issues/2109 is fixed.
Expand All @@ -202,16 +183,4 @@ mod tests {
impl NetworkBehaviourEventProcess<libp2p::ping::PingEvent> for RendezvousPointBehaviour {
fn inject_event(&mut self, _: libp2p::ping::PingEvent) {}
}

impl From<libp2p::ping::Event> for RendezvousPointEvent {
fn from(_: libp2p::ping::Event) -> Self {
RendezvousPointEvent
}
}

impl From<libp2p::rendezvous::server::Event> for RendezvousPointEvent {
fn from(_: libp2p::rendezvous::server::Event) -> Self {
RendezvousPointEvent
}
}
}
5 changes: 2 additions & 3 deletions swap/src/cli/list_sellers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use anyhow::{Context, Result};
use futures::StreamExt;
use libp2p::multiaddr::Protocol;
use libp2p::ping::{Ping, PingConfig, PingEvent};
use libp2p::rendezvous::Namespace;
use libp2p::request_response::{RequestResponseEvent, RequestResponseMessage};
use libp2p::swarm::SwarmEvent;
use libp2p::{identity, rendezvous, Multiaddr, PeerId, Swarm};
Expand All @@ -29,7 +28,7 @@ pub async fn list_sellers(
identity: identity::Keypair,
) -> Result<Vec<Seller>> {
let behaviour = Behaviour {
rendezvous: libp2p::rendezvous::client::Behaviour::new(identity.clone()),
rendezvous: rendezvous::client::Behaviour::new(identity.clone()),
quote: quote::cli(),
ping: Ping::new(
PingConfig::new()
Expand Down Expand Up @@ -155,7 +154,7 @@ impl EventLoop {
);

self.swarm.behaviour_mut().rendezvous.discover(
Some(Namespace::new(self.namespace.to_string()).expect("our namespace to be a correct string")),
Some(rendezvous::Namespace::new(self.namespace.to_string()).expect("our namespace to be a correct string")),
None,
None,
self.rendezvous_peer_id,
Expand Down
4 changes: 1 addition & 3 deletions swap/src/network/cbor_request_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ where
where
T: AsyncRead + Unpin + Send,
{
let message = upgrade::read_length_prefixed(io, BUF_SIZE)
.await
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
let message = upgrade::read_length_prefixed(io, BUF_SIZE).await?;
let mut de = serde_cbor::Deserializer::from_slice(&message);
let msg = Req::deserialize(&mut de)
.map_err(|error| io::Error::new(io::ErrorKind::Other, error))?;
Expand Down

0 comments on commit 12a4956

Please sign in to comment.