// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Cumulus.
// Cumulus is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Cumulus is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see .
use core::time::Duration;
use futures::prelude::*;
use sc_service::SpawnTaskHandle;
use smoldot::libp2p::{websocket, with_buffers};
use smoldot_light::platform::{
Address, ConnectError, ConnectionType, IpAddr, MultiStreamWebRtcConnection, PlatformRef,
SubstreamDirection,
};
use std::{net::SocketAddr, pin::Pin, time::Instant};
use tokio::net::TcpStream;
use tokio_util::compat::{Compat, TokioAsyncReadCompatExt};
type CompatTcpStream = Compat;
/// Platform implementation for tokio
/// This implementation is a port of the implementation for smol:
/// https://github.com/smol-dot/smoldot/blob/8c577b4a753fe96190f813070564ecc742b91a16/light-base/src/platform/default.rs
#[derive(Clone)]
pub struct TokioPlatform {
spawner: SpawnTaskHandle,
}
impl TokioPlatform {
pub fn new(spawner: SpawnTaskHandle) -> Self {
TokioPlatform { spawner }
}
}
impl PlatformRef for TokioPlatform {
type Delay = future::BoxFuture<'static, ()>;
type Instant = Instant;
type MultiStream = std::convert::Infallible;
type Stream = Stream;
type StreamConnectFuture = future::BoxFuture<'static, Result>;
type MultiStreamConnectFuture = future::BoxFuture<
'static,
Result, ConnectError>,
>;
type ReadWriteAccess<'a> = with_buffers::ReadWriteAccess<'a>;
type StreamUpdateFuture<'a> = future::BoxFuture<'a, ()>;
type StreamErrorRef<'a> = &'a std::io::Error;
type NextSubstreamFuture<'a> = future::Pending