core/tests: Remove unnecessary util module (#2764)

This commit is contained in:
Thomas Eizinger
2022-07-25 08:34:05 +01:00
committed by GitHub
parent 95713ab91c
commit f85a9909ac
2 changed files with 0 additions and 59 deletions

View File

@ -18,8 +18,6 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
mod util;
use futures::prelude::*;
use libp2p_core::identity;
use libp2p_core::transport::{MemoryTransport, Transport};
@ -91,11 +89,6 @@ fn upgrade_pipeline() {
.apply(HelloUpgrade {})
.apply(HelloUpgrade {})
.multiplex(MplexConfig::default())
.and_then(|(peer, mplex), _| {
// Gracefully close the connection to allow protocol
// negotiation to complete.
util::CloseMuxer::new(mplex).map_ok(move |mplex| (peer, mplex))
})
.boxed();
let dialer_keys = identity::Keypair::generate_ed25519();
@ -110,11 +103,6 @@ fn upgrade_pipeline() {
.apply(HelloUpgrade {})
.apply(HelloUpgrade {})
.multiplex(MplexConfig::default())
.and_then(|(peer, mplex), _| {
// Gracefully close the connection to allow protocol
// negotiation to complete.
util::CloseMuxer::new(mplex).map_ok(move |mplex| (peer, mplex))
})
.boxed();
let listen_addr1 = Multiaddr::from(Protocol::Memory(random::<u64>()));

View File

@ -1,47 +0,0 @@
#![allow(dead_code)]
use futures::prelude::*;
use libp2p_core::muxing::StreamMuxer;
use std::{pin::Pin, task::Context, task::Poll};
pub struct CloseMuxer<M> {
state: CloseMuxerState<M>,
}
impl<M> CloseMuxer<M> {
pub fn new(m: M) -> CloseMuxer<M> {
CloseMuxer {
state: CloseMuxerState::Close(m),
}
}
}
pub enum CloseMuxerState<M> {
Close(M),
Done,
}
impl<M> Future for CloseMuxer<M>
where
M: StreamMuxer,
M::Error: From<std::io::Error>,
{
type Output = Result<M, M::Error>;
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
loop {
match std::mem::replace(&mut self.state, CloseMuxerState::Done) {
CloseMuxerState::Close(muxer) => {
if !muxer.poll_close(cx)?.is_ready() {
self.state = CloseMuxerState::Close(muxer);
return Poll::Pending;
}
return Poll::Ready(Ok(muxer));
}
CloseMuxerState::Done => panic!(),
}
}
}
}
impl<M> Unpin for CloseMuxer<M> {}