mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-14 10:31:21 +00:00
Swarm rework (#182)
* Rename Transport::RawConn to Output * Remove AsyncRead + AsyncWrite bound on Transport::Output * UpgradedNode now always implements Transport * Add and tweak modifiers for Transport and ConnectionUpgrade * Secio upgrade now returns the pubkey in its output * Add upgrade::apply * Add Transport::and_then * Rework the swarm * Rustfmt * Fix concerns
This commit is contained in:
@ -18,17 +18,17 @@
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
use futures::{Async, Future, Poll, Stream};
|
||||
use futures::stream::Then as StreamThen;
|
||||
use futures::sync::{mpsc, oneshot};
|
||||
use futures::{Async, Future, Poll, Stream};
|
||||
use multiaddr::{AddrComponent, Multiaddr};
|
||||
use rw_stream_sink::RwStreamSink;
|
||||
use std::io::{Error as IoError, ErrorKind as IoErrorKind};
|
||||
use std::io::{Read, Write};
|
||||
use std::iter;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use stdweb::{self, Reference};
|
||||
use stdweb::web::TypedArray;
|
||||
use stdweb::{self, Reference};
|
||||
use swarm::Transport;
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
@ -52,10 +52,10 @@ impl BrowserWsConfig {
|
||||
}
|
||||
|
||||
impl Transport for BrowserWsConfig {
|
||||
type RawConn = BrowserWsConn;
|
||||
type Output = BrowserWsConn;
|
||||
type Listener = Box<Stream<Item = Self::ListenerUpgrade, Error = IoError>>; // TODO: use `!`
|
||||
type ListenerUpgrade = Box<Future<Item = (Self::RawConn, Multiaddr), Error = IoError>>; // TODO: use `!`
|
||||
type Dial = Box<Future<Item = (Self::RawConn, Multiaddr), Error = IoError>>;
|
||||
type ListenerUpgrade = Box<Future<Item = (Self::Output, Multiaddr), Error = IoError>>; // TODO: use `!`
|
||||
type Dial = Box<Future<Item = (Self::Output, Multiaddr), Error = IoError>>;
|
||||
|
||||
#[inline]
|
||||
fn listen_on(self, a: Multiaddr) -> Result<(Self::Listener, Multiaddr), (Self, Multiaddr)> {
|
||||
|
@ -23,6 +23,7 @@ use multiaddr::{AddrComponent, Multiaddr};
|
||||
use rw_stream_sink::RwStreamSink;
|
||||
use std::io::{Error as IoError, ErrorKind as IoErrorKind};
|
||||
use swarm::Transport;
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
use websocket::client::builder::ClientBuilder;
|
||||
use websocket::message::OwnedMessage;
|
||||
use websocket::server::upgrade::async::IntoWs;
|
||||
@ -59,13 +60,13 @@ where
|
||||
// TODO: this 'static is pretty arbitrary and is necessary because of the websocket library
|
||||
T: Transport + 'static,
|
||||
// TODO: this Send is pretty arbitrary and is necessary because of the websocket library
|
||||
T::RawConn: Send,
|
||||
T::Output: AsyncRead + AsyncWrite + Send,
|
||||
{
|
||||
type RawConn = Box<AsyncStream>;
|
||||
type Output = Box<AsyncStream>;
|
||||
type Listener =
|
||||
stream::Map<T::Listener, fn(<T as Transport>::ListenerUpgrade) -> Self::ListenerUpgrade>;
|
||||
type ListenerUpgrade = Box<Future<Item = (Self::RawConn, Multiaddr), Error = IoError>>;
|
||||
type Dial = Box<Future<Item = (Self::RawConn, Multiaddr), Error = IoError>>;
|
||||
type ListenerUpgrade = Box<Future<Item = (Self::Output, Multiaddr), Error = IoError>>;
|
||||
type Dial = Box<Future<Item = (Self::Output, Multiaddr), Error = IoError>>;
|
||||
|
||||
fn listen_on(
|
||||
self,
|
||||
|
@ -88,10 +88,10 @@ extern crate stdweb;
|
||||
#[cfg(not(target_os = "emscripten"))]
|
||||
extern crate websocket;
|
||||
|
||||
#[cfg(not(target_os = "emscripten"))]
|
||||
mod desktop;
|
||||
#[cfg(target_os = "emscripten")]
|
||||
mod browser;
|
||||
#[cfg(not(target_os = "emscripten"))]
|
||||
mod desktop;
|
||||
|
||||
#[cfg(target_os = "emscripten")]
|
||||
pub use self::browser::{BrowserWsConfig, BrowserWsConn};
|
||||
|
Reference in New Issue
Block a user