Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaka committed May 7, 2019
1 parent 8537eb3 commit f1d389b
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 8 deletions.
8 changes: 7 additions & 1 deletion core/src/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,19 @@ where
A: AsyncRead,
B: AsyncRead,
{
#[inline]
unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [u8]) -> bool {
match self {
EitherOutput::First(a) => a.prepare_uninitialized_buffer(buf),
EitherOutput::Second(b) => b.prepare_uninitialized_buffer(buf),
}
}

fn read_buf<Bu: bytes::BufMut>(&mut self, buf: &mut Bu) -> Poll<usize, IoError> {
match self {
EitherOutput::First(a) => a.read_buf(buf),
EitherOutput::Second(b) => b.read_buf(buf),
}
}
}

impl<A, B> Read for EitherOutput<A, B>
Expand Down
6 changes: 5 additions & 1 deletion core/src/muxing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,11 @@ where
P: Deref,
P::Target: StreamMuxer,
{
#[inline]
// TODO: ?
/*unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [u8]) -> bool {
false
}*/

fn poll_read(&mut self, buf: &mut [u8]) -> Poll<usize, io::Error> {
let s = self.substream.as_mut().expect("substream was empty");
self.muxer.read_substream(s, buf).map_err(|e| e.into())
Expand Down
3 changes: 3 additions & 0 deletions core/src/transport/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ impl io::Write for DummyStream {
}

impl tokio_io::AsyncRead for DummyStream {
unsafe fn prepare_uninitialized_buffer(&self, _: &mut [u8]) -> bool {
false
}
}

impl tokio_io::AsyncWrite for DummyStream {
Expand Down
7 changes: 7 additions & 0 deletions misc/multistream-select/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ impl<TInner> tokio_io::AsyncRead for Negotiated<TInner>
where
TInner: tokio_io::AsyncRead
{
unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [u8]) -> bool {
self.0.prepare_uninitialized_buffer(buf)
}

fn read_buf<B: bytes::BufMut>(&mut self, buf: &mut B) -> Poll<usize, io::Error> {
self.0.read_buf(buf)
}
}

impl<TInner> io::Write for Negotiated<TInner>
Expand Down
3 changes: 3 additions & 0 deletions misc/rw-stream-sink/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ where
S: Stream<Error = IoError>,
S::Item: IntoBuf,
{
unsafe fn prepare_uninitialized_buffer(&self, _: &mut [u8]) -> bool {
false
}
}

impl<S> Write for RwStreamSink<S>
Expand Down
1 change: 1 addition & 0 deletions protocols/noise/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ repository = "https://github.com/libp2p/rust-libp2p"
edition = "2018"

[dependencies]
bytes = "0.4"
curve25519-dalek = "1"
futures = "0.1"
lazy_static = "1.2"
Expand Down
6 changes: 5 additions & 1 deletion protocols/noise/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,11 @@ impl<T: io::Write> io::Write for NoiseOutput<T> {
}
}

impl<T: AsyncRead> AsyncRead for NoiseOutput<T> {}
impl<T: AsyncRead> AsyncRead for NoiseOutput<T> {
unsafe fn prepare_uninitialized_buffer(&self, _: &mut [u8]) -> bool {
false
}
}

impl<T: AsyncWrite> AsyncWrite for NoiseOutput<T> {
fn shutdown(&mut self) -> Poll<(), io::Error> {
Expand Down
9 changes: 8 additions & 1 deletion protocols/noise/src/io/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,14 @@ impl<T: io::Write> io::Write for State<T> {
}
}

impl<T: AsyncRead> AsyncRead for State<T> {}
impl<T: AsyncRead> AsyncRead for State<T> {
unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [u8]) -> bool {
self.io.prepare_uninitialized_buffer(buf)
}
fn read_buf<B: bytes::BufMut>(&mut self, buf: &mut B) -> Poll<usize, io::Error> {
self.io.read_buf(buf)
}
}

impl<T: AsyncWrite> AsyncWrite for State<T> {
fn shutdown(&mut self) -> Poll<(), io::Error> {
Expand Down
7 changes: 7 additions & 0 deletions src/bandwidth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ impl<TInner> Read for BandwidthConnecLogging<TInner>
impl<TInner> tokio_io::AsyncRead for BandwidthConnecLogging<TInner>
where TInner: tokio_io::AsyncRead
{
unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [u8]) -> bool {
self.inner.prepare_uninitialized_buffer(buf)
}

fn read_buf<B: bytes::BufMut>(&mut self, buf: &mut B) -> Poll<usize, io::Error> {
self.inner.read_buf(buf)
}
}

impl<TInner> Write for BandwidthConnecLogging<TInner>
Expand Down
1 change: 1 addition & 0 deletions transports/ratelimit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ categories = ["network-programming", "asynchronous"]

[dependencies]
aio-limited = "0.1"
bytes = "0.4"
futures = "0.1"
libp2p-core = { version = "0.7.0", path = "../../core" }
log = "0.4"
Expand Down
10 changes: 9 additions & 1 deletion transports/ratelimit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,15 @@ impl<C: AsyncRead + AsyncWrite> io::Write for Connection<C> {
}
}

impl<C: AsyncRead + AsyncWrite> AsyncRead for Connection<C> {}
impl<C: AsyncRead + AsyncWrite> AsyncRead for Connection<C> {
unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [u8]) -> bool {
self.reader.prepare_uninitialized_buffer(buf)
}

fn read_buf<B: bytes::BufMut>(&mut self, buf: &mut B) -> Poll<usize, io::Error> {
self.reader.read_buf(buf)
}
}

impl<C: AsyncRead + AsyncWrite> AsyncWrite for Connection<C> {
fn shutdown(&mut self) -> Poll<(), io::Error> {
Expand Down
1 change: 1 addition & 0 deletions transports/tcp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ keywords = ["peer-to-peer", "libp2p", "networking"]
categories = ["network-programming", "asynchronous"]

[dependencies]
bytes = "0.4"
get_if_addrs = "0.5.3"
libp2p-core = { version = "0.7.0", path = "../../core" }
log = "0.4.1"
Expand Down
10 changes: 9 additions & 1 deletion transports/tcp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,15 @@ impl Read for TcpTransStream {
}
}

impl AsyncRead for TcpTransStream {}
impl AsyncRead for TcpTransStream {
unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [u8]) -> bool {
self.inner.prepare_uninitialized_buffer(buf)
}

fn read_buf<B: bytes::BufMut>(&mut self, buf: &mut B) -> Poll<usize, io::Error> {
self.inner.read_buf(buf)
}
}

impl Write for TcpTransStream {
#[inline]
Expand Down
6 changes: 5 additions & 1 deletion transports/wasm-ext/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,11 @@ impl io::Read for Connection {
}
}

impl tokio_io::AsyncRead for Connection {}
impl tokio_io::AsyncRead for Connection {
unsafe fn prepare_uninitialized_buffer(&self, _: &mut [u8]) -> bool {
false
}
}

impl io::Write for Connection {
fn write(&mut self, buf: &[u8]) -> Result<usize, io::Error> {
Expand Down
10 changes: 9 additions & 1 deletion transports/websocket/src/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,15 @@ impl Drop for BrowserWsConn {
}
}

impl AsyncRead for BrowserWsConn {}
impl AsyncRead for BrowserWsConn {
unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [u8]) -> bool {
self.incoming_data.prepare_uninitialized_buffer(buf)
}

fn read_buf<B: bytes::BufMut>(&mut self, buf: &mut B) -> Poll<usize, io::Error> {
self.incoming_data.read_buf(buf)
}
}

impl Read for BrowserWsConn {
#[inline]
Expand Down

0 comments on commit f1d389b

Please sign in to comment.