mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-12 09:31:20 +00:00
*: Format with rustfmt (#2188)
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
This commit is contained in:
@ -303,7 +303,7 @@ impl NetworkBehaviour for Relay {
|
||||
|
||||
fn inject_dial_failure(&mut self, peer_id: &PeerId) {
|
||||
if let Entry::Occupied(o) = self.listeners.entry(*peer_id) {
|
||||
if matches!(o.get(), RelayListener::Connecting{ .. }) {
|
||||
if matches!(o.get(), RelayListener::Connecting { .. }) {
|
||||
// By removing the entry, the channel to the listener is dropped and thus the
|
||||
// listener is notified that dialing the relay failed.
|
||||
o.remove_entry();
|
||||
|
@ -23,8 +23,8 @@ use crate::protocol::Peer;
|
||||
|
||||
use asynchronous_codec::{Framed, FramedParts};
|
||||
use bytes::BytesMut;
|
||||
use futures::{future::BoxFuture, prelude::*};
|
||||
use futures::channel::oneshot;
|
||||
use futures::{future::BoxFuture, prelude::*};
|
||||
use libp2p_core::{Multiaddr, PeerId};
|
||||
use libp2p_swarm::NegotiatedSubstream;
|
||||
use prost::Message;
|
||||
@ -47,8 +47,7 @@ pub struct IncomingDstReq {
|
||||
src: Peer,
|
||||
}
|
||||
|
||||
impl IncomingDstReq
|
||||
{
|
||||
impl IncomingDstReq {
|
||||
/// Creates a `IncomingDstReq`.
|
||||
pub(crate) fn new(stream: Framed<NegotiatedSubstream, UviBytes>, src: Peer) -> Self {
|
||||
IncomingDstReq {
|
||||
@ -73,7 +72,10 @@ impl IncomingDstReq
|
||||
/// stream then points to the source (as retreived with `src_id()` and `src_addrs()`).
|
||||
pub fn accept(
|
||||
self,
|
||||
) -> BoxFuture<'static, Result<(PeerId, super::Connection, oneshot::Receiver<()>), IncomingDstReqError>> {
|
||||
) -> BoxFuture<
|
||||
'static,
|
||||
Result<(PeerId, super::Connection, oneshot::Receiver<()>), IncomingDstReqError>,
|
||||
> {
|
||||
let IncomingDstReq { mut stream, src } = self;
|
||||
let msg = CircuitRelay {
|
||||
r#type: Some(circuit_relay::Type::Status.into()),
|
||||
@ -101,7 +103,11 @@ impl IncomingDstReq
|
||||
|
||||
let (tx, rx) = oneshot::channel();
|
||||
|
||||
Ok((src.peer_id, super::Connection::new(read_buffer.freeze(), io, tx), rx))
|
||||
Ok((
|
||||
src.peer_id,
|
||||
super::Connection::new(read_buffer.freeze(), io, tx),
|
||||
rx,
|
||||
))
|
||||
}
|
||||
.boxed()
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ use crate::message_proto::{circuit_relay, circuit_relay::Status, CircuitRelay};
|
||||
use crate::protocol::Peer;
|
||||
|
||||
use asynchronous_codec::{Framed, FramedParts};
|
||||
use bytes::{BytesMut, Bytes};
|
||||
use bytes::{Bytes, BytesMut};
|
||||
use futures::channel::oneshot;
|
||||
use futures::future::BoxFuture;
|
||||
use futures::prelude::*;
|
||||
@ -50,8 +50,7 @@ pub struct IncomingRelayReq {
|
||||
_notifier: oneshot::Sender<()>,
|
||||
}
|
||||
|
||||
impl IncomingRelayReq
|
||||
{
|
||||
impl IncomingRelayReq {
|
||||
/// Creates a [`IncomingRelayReq`] as well as a Future that resolves once the
|
||||
/// [`IncomingRelayReq`] is dropped.
|
||||
pub(crate) fn new(
|
||||
|
@ -27,7 +27,7 @@ use futures::prelude::*;
|
||||
use libp2p_core::{upgrade, Multiaddr, PeerId};
|
||||
use libp2p_swarm::NegotiatedSubstream;
|
||||
use prost::Message;
|
||||
use std::{fmt, error, iter};
|
||||
use std::{error, fmt, iter};
|
||||
use unsigned_varint::codec::UviBytes;
|
||||
|
||||
/// Ask the remote to become a destination. The upgrade succeeds if the remote accepts, and fails
|
||||
@ -96,14 +96,9 @@ impl upgrade::OutboundUpgrade<NegotiatedSubstream> for OutgoingDstReq {
|
||||
|
||||
async move {
|
||||
substream.send(std::io::Cursor::new(self.message)).await?;
|
||||
let msg =
|
||||
substream
|
||||
.next()
|
||||
.await
|
||||
.ok_or_else(|| OutgoingDstReqError::Io(std::io::Error::new(
|
||||
std::io::ErrorKind::UnexpectedEof,
|
||||
"",
|
||||
)))??;
|
||||
let msg = substream.next().await.ok_or_else(|| {
|
||||
OutgoingDstReqError::Io(std::io::Error::new(std::io::ErrorKind::UnexpectedEof, ""))
|
||||
})??;
|
||||
|
||||
let msg = std::io::Cursor::new(msg);
|
||||
let CircuitRelay {
|
||||
|
@ -103,14 +103,12 @@ impl upgrade::OutboundUpgrade<NegotiatedSubstream> for OutgoingRelayReq {
|
||||
|
||||
async move {
|
||||
substream.send(std::io::Cursor::new(encoded)).await?;
|
||||
let msg =
|
||||
substream
|
||||
.next()
|
||||
.await
|
||||
.ok_or_else(|| OutgoingRelayReqError::Io(std::io::Error::new(
|
||||
std::io::ErrorKind::UnexpectedEof,
|
||||
"",
|
||||
)))??;
|
||||
let msg = substream.next().await.ok_or_else(|| {
|
||||
OutgoingRelayReqError::Io(std::io::Error::new(
|
||||
std::io::ErrorKind::UnexpectedEof,
|
||||
"",
|
||||
))
|
||||
})??;
|
||||
|
||||
let msg = std::io::Cursor::new(msg);
|
||||
let CircuitRelay {
|
||||
|
@ -402,7 +402,7 @@ impl<T: Transport> Stream for RelayListener<T> {
|
||||
stream,
|
||||
src_peer_id,
|
||||
relay_addr,
|
||||
relay_peer_id: _
|
||||
relay_peer_id: _,
|
||||
})) => {
|
||||
return Poll::Ready(Some(Ok(ListenerEvent::Upgrade {
|
||||
upgrade: RelayedListenerUpgrade::Relayed(Some(stream)),
|
||||
|
Reference in New Issue
Block a user