diff --git a/example/02-kademlia/rendezvous_chat.cpp b/example/02-kademlia/rendezvous_chat.cpp index a77929b27..ae00d5f15 100644 --- a/example/02-kademlia/rendezvous_chat.cpp +++ b/example/02-kademlia/rendezvous_chat.cpp @@ -47,7 +47,6 @@ class Session : public std::enable_shared_from_this { stream_->readSome( *incoming_, - incoming_->size(), [self = shared_from_this()](outcome::result result) { if (not result) { self->close(); diff --git a/include/libp2p/basic/read.hpp b/include/libp2p/basic/read.hpp index 24326845b..3ae94c993 100644 --- a/include/libp2p/basic/read.hpp +++ b/include/libp2p/basic/read.hpp @@ -18,7 +18,6 @@ namespace libp2p { // read some bytes reader->readSome( out, - out.size(), [weak{std::weak_ptr{reader}}, out, cb{std::move(cb)}]( outcome::result n_res) mutable { if (n_res.has_error()) { diff --git a/include/libp2p/basic/reader.hpp b/include/libp2p/basic/reader.hpp index a6cf95b72..3e938bee0 100644 --- a/include/libp2p/basic/reader.hpp +++ b/include/libp2p/basic/reader.hpp @@ -32,7 +32,7 @@ namespace libp2p::basic { * pointer, or having buffer as part of some class/struct, and using * enable_shared_from_this() */ - virtual void readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) = 0; + virtual void readSome(BytesOut out, ReadCallbackFunc cb) = 0; /** * @brief Defers reporting result or error to callback to avoid reentrancy diff --git a/include/libp2p/common/ambigous_size.hpp b/include/libp2p/common/ambigous_size.hpp deleted file mode 100644 index 5aa887ab5..000000000 --- a/include/libp2p/common/ambigous_size.hpp +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Copyright Quadrivium LLC - * All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include - -namespace libp2p { - // TODO(turuslan): https://github.com/libp2p/cpp-libp2p/issues/203 - template - void ambigousSize(std::span &s, size_t n) { - if (n > s.size()) { - throw std::logic_error{"libp2p::ambigousSize"}; - } - s = s.first(n); - } -} // namespace libp2p diff --git a/include/libp2p/connection/as_asio_read_write.hpp b/include/libp2p/connection/as_asio_read_write.hpp index 038a08c64..3025e4afe 100644 --- a/include/libp2p/connection/as_asio_read_write.hpp +++ b/include/libp2p/connection/as_asio_read_write.hpp @@ -68,7 +68,7 @@ namespace libp2p { boost::asio::mutable_buffer, MutableBufferSequence>::first(buffers)}; impl->readSome( - asioBuffer(buffer), buffer.size(), wrapCb(std::forward(cb))); + asioBuffer(buffer), wrapCb(std::forward(cb))); } template diff --git a/include/libp2p/connection/loopback_stream.hpp b/include/libp2p/connection/loopback_stream.hpp index dd60764ba..849f42eb0 100644 --- a/include/libp2p/connection/loopback_stream.hpp +++ b/include/libp2p/connection/loopback_stream.hpp @@ -40,7 +40,7 @@ namespace libp2p::connection { const override; protected: - void readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) override; + void readSome(BytesOut out, ReadCallbackFunc cb) override; void writeSome(BytesIn in, WriteCallbackFunc cb) override; diff --git a/include/libp2p/layer/websocket/ssl_connection.hpp b/include/libp2p/layer/websocket/ssl_connection.hpp index a0d2efa94..1be41e301 100644 --- a/include/libp2p/layer/websocket/ssl_connection.hpp +++ b/include/libp2p/layer/websocket/ssl_connection.hpp @@ -32,7 +32,7 @@ namespace libp2p::connection { outcome::result close() override; bool isClosed() const override; - void readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) override; + void readSome(BytesOut out, ReadCallbackFunc cb) override; void deferReadCallback(outcome::result res, ReadCallbackFunc cb) override; diff --git a/include/libp2p/layer/websocket/ws_connection.hpp b/include/libp2p/layer/websocket/ws_connection.hpp index 7480532de..e2e8ac206 100644 --- a/include/libp2p/layer/websocket/ws_connection.hpp +++ b/include/libp2p/layer/websocket/ws_connection.hpp @@ -68,7 +68,7 @@ namespace libp2p::connection { bool isClosed() const override; - void readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) override; + void readSome(BytesOut out, ReadCallbackFunc cb) override; void deferReadCallback(outcome::result res, ReadCallbackFunc cb) override; diff --git a/include/libp2p/muxer/mplex/mplex_stream.hpp b/include/libp2p/muxer/mplex/mplex_stream.hpp index a6e6863fe..4f6866033 100644 --- a/include/libp2p/muxer/mplex/mplex_stream.hpp +++ b/include/libp2p/muxer/mplex/mplex_stream.hpp @@ -50,7 +50,7 @@ namespace libp2p::connection { ~MplexStream() override = default; - void readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) override; + void readSome(BytesOut out, ReadCallbackFunc cb) override; void deferReadCallback(outcome::result res, ReadCallbackFunc cb) override; diff --git a/include/libp2p/muxer/mplex/mplexed_connection.hpp b/include/libp2p/muxer/mplex/mplexed_connection.hpp index b650856fb..166af8836 100644 --- a/include/libp2p/muxer/mplex/mplexed_connection.hpp +++ b/include/libp2p/muxer/mplex/mplexed_connection.hpp @@ -64,7 +64,7 @@ namespace libp2p::connection { /// usage of these four methods is highly not recommended or even forbidden: /// use stream over this connection instead - void readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) override; + void readSome(BytesOut out, ReadCallbackFunc cb) override; void writeSome(BytesIn in, WriteCallbackFunc cb) override; void deferReadCallback(outcome::result res, diff --git a/include/libp2p/muxer/yamux/yamux_stream.hpp b/include/libp2p/muxer/yamux/yamux_stream.hpp index 8795d8bb1..9815a2a76 100644 --- a/include/libp2p/muxer/yamux/yamux_stream.hpp +++ b/include/libp2p/muxer/yamux/yamux_stream.hpp @@ -54,7 +54,7 @@ namespace libp2p::connection { size_t maximum_window_size, size_t write_queue_limit); - void readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) override; + void readSome(BytesOut out, ReadCallbackFunc cb) override; void deferReadCallback(outcome::result res, ReadCallbackFunc cb) override; diff --git a/include/libp2p/muxer/yamux/yamuxed_connection.hpp b/include/libp2p/muxer/yamux/yamuxed_connection.hpp index 0b959e929..86afe206d 100644 --- a/include/libp2p/muxer/yamux/yamuxed_connection.hpp +++ b/include/libp2p/muxer/yamux/yamuxed_connection.hpp @@ -111,7 +111,7 @@ namespace libp2p::connection { /// usage of these four methods is highly not recommended or even forbidden: /// use stream over this connection instead - void readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) override; + void readSome(BytesOut out, ReadCallbackFunc cb) override; void writeSome(BytesIn in, WriteCallbackFunc cb) override; /// Initiates async readSome on connection diff --git a/include/libp2p/security/noise/noise_connection.hpp b/include/libp2p/security/noise/noise_connection.hpp index 49c5e27e4..26b767c40 100644 --- a/include/libp2p/security/noise/noise_connection.hpp +++ b/include/libp2p/security/noise/noise_connection.hpp @@ -38,7 +38,7 @@ namespace libp2p::connection { outcome::result close() override; - void readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) override; + void readSome(BytesOut out, ReadCallbackFunc cb) override; void deferReadCallback(outcome::result res, ReadCallbackFunc cb) override; diff --git a/include/libp2p/security/plaintext/plaintext_connection.hpp b/include/libp2p/security/plaintext/plaintext_connection.hpp index cc469c7ca..5d6a9180b 100644 --- a/include/libp2p/security/plaintext/plaintext_connection.hpp +++ b/include/libp2p/security/plaintext/plaintext_connection.hpp @@ -35,7 +35,7 @@ namespace libp2p::connection { outcome::result remoteMultiaddr() override; - void readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) override; + void readSome(BytesOut out, ReadCallbackFunc cb) override; void deferReadCallback(outcome::result res, ReadCallbackFunc cb) override; diff --git a/include/libp2p/security/secio/secio_connection.hpp b/include/libp2p/security/secio/secio_connection.hpp index ca311885b..1346ce6fb 100644 --- a/include/libp2p/security/secio/secio_connection.hpp +++ b/include/libp2p/security/secio/secio_connection.hpp @@ -97,7 +97,7 @@ namespace libp2p::connection { outcome::result remoteMultiaddr() override; - void readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) override; + void readSome(BytesOut out, ReadCallbackFunc cb) override; void deferReadCallback(outcome::result res, ReadCallbackFunc cb) override; diff --git a/include/libp2p/transport/quic/connection.hpp b/include/libp2p/transport/quic/connection.hpp index bb6f69f1e..5c389727b 100644 --- a/include/libp2p/transport/quic/connection.hpp +++ b/include/libp2p/transport/quic/connection.hpp @@ -39,7 +39,7 @@ namespace libp2p::transport { void operator=(QuicConnection &&) = delete; // Reader - void readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) override; + void readSome(BytesOut out, ReadCallbackFunc cb) override; void deferReadCallback(outcome::result res, ReadCallbackFunc cb) override; diff --git a/include/libp2p/transport/quic/stream.hpp b/include/libp2p/transport/quic/stream.hpp index da6058e39..453a443a8 100644 --- a/include/libp2p/transport/quic/stream.hpp +++ b/include/libp2p/transport/quic/stream.hpp @@ -32,7 +32,7 @@ namespace libp2p::connection { void operator=(QuicStream &&) = delete; // Reader - void readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) override; + void readSome(BytesOut out, ReadCallbackFunc cb) override; void deferReadCallback(outcome::result res, ReadCallbackFunc cb) override; diff --git a/include/libp2p/transport/tcp/tcp_connection.hpp b/include/libp2p/transport/tcp/tcp_connection.hpp index ad680cdb5..c61bae905 100644 --- a/include/libp2p/transport/tcp/tcp_connection.hpp +++ b/include/libp2p/transport/tcp/tcp_connection.hpp @@ -61,7 +61,7 @@ namespace libp2p::transport { ConnectCallbackFunc cb, std::chrono::milliseconds timeout); - void readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) override; + void readSome(BytesOut out, ReadCallbackFunc cb) override; void deferReadCallback(outcome::result res, ReadCallbackFunc cb) override; diff --git a/src/connection/loopback_stream.cpp b/src/connection/loopback_stream.cpp index b486ae117..2b3d52b1c 100644 --- a/src/connection/loopback_stream.cpp +++ b/src/connection/loopback_stream.cpp @@ -7,7 +7,6 @@ #include #include -#include namespace libp2p::connection { @@ -109,7 +108,6 @@ namespace libp2p::connection { } void LoopbackStream::readSome(BytesOut out, - size_t bytes, libp2p::basic::Reader::ReadCallbackFunc cb) { if (is_reset_) { return deferReadCallback(Error::STREAM_RESET_BY_HOST, std::move(cb)); @@ -117,7 +115,7 @@ namespace libp2p::connection { if (!is_readable_) { return deferReadCallback(Error::STREAM_NOT_READABLE, std::move(cb)); } - if (bytes == 0 || out.empty() || static_cast(out.size()) < bytes) { + if (out.empty()) { return cb(Error::STREAM_INVALID_ARGUMENT); } @@ -125,8 +123,7 @@ namespace libp2p::connection { // it to the caller, if so auto read_lambda = [self{shared_from_this()}, cb{std::move(cb)}, - out, - bytes](outcome::result res) mutable { + out](outcome::result res) mutable { if (!res) { self->data_notified_ = true; self->deferReadCallback(res.as_failure(), std::move(cb)); @@ -134,7 +131,7 @@ namespace libp2p::connection { } if (self->buffer_.size() > 0) { - auto to_read = std::min(self->buffer_.size(), bytes); + auto to_read = std::min(self->buffer_.size(), out.size()); if (boost::asio::buffer_copy(boost::asio::buffer(out.data(), to_read), self->buffer_.data(), diff --git a/src/layer/websocket/ssl_connection.cpp b/src/layer/websocket/ssl_connection.cpp index e9dd92200..4c3804160 100644 --- a/src/layer/websocket/ssl_connection.cpp +++ b/src/layer/websocket/ssl_connection.cpp @@ -7,7 +7,6 @@ #include #include -#include #include #include @@ -44,9 +43,7 @@ namespace libp2p::connection { } void SslConnection::readSome(BytesOut out, - size_t bytes, libp2p::basic::Reader::ReadCallbackFunc cb) { - ambigousSize(out, bytes); ssl_.async_read_some(asioBuffer(out), toAsioCbSize(std::move(cb))); } diff --git a/src/layer/websocket/ws_connection.cpp b/src/layer/websocket/ws_connection.cpp index 2669b2050..251893174 100644 --- a/src/layer/websocket/ws_connection.cpp +++ b/src/layer/websocket/ws_connection.cpp @@ -7,7 +7,6 @@ #include #include -#include #include #include #include @@ -86,10 +85,8 @@ namespace libp2p::connection { } void WsConnection::readSome(BytesOut out, - size_t bytes, libp2p::basic::Reader::ReadCallbackFunc cb) { - ambigousSize(out, bytes); - SL_TRACE(log_, "read some upto {} bytes", bytes); + SL_TRACE(log_, "read some upto {} bytes", out.size()); auto on_read = [weak{weak_from_this()}, out, cb{std::move(cb)}]( boost::system::error_code ec, size_t n) mutable { if (ec) { @@ -97,7 +94,7 @@ namespace libp2p::connection { } else if (n != 0) { cb(n); } else if (auto self = weak.lock()) { - self->readSome(out, out.size(), std::move(cb)); + self->readSome(out, std::move(cb)); } else { cb(boost::system::errc::broken_pipe); } diff --git a/src/muxer/mplex/mplex_stream.cpp b/src/muxer/mplex/mplex_stream.cpp index 393309f68..099e13671 100644 --- a/src/muxer/mplex/mplex_stream.cpp +++ b/src/muxer/mplex/mplex_stream.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #define TRY_GET_CONNECTION(tmp) \ @@ -59,8 +58,7 @@ namespace libp2p::connection { return true; } - void MplexStream::readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) { - ambigousSize(out, bytes); + void MplexStream::readSome(BytesOut out, ReadCallbackFunc cb) { if (is_reset_) { return cb(Error::STREAM_RESET_BY_PEER); } diff --git a/src/muxer/mplex/mplexed_connection.cpp b/src/muxer/mplex/mplexed_connection.cpp index c170bdcf3..3d31b9b7b 100644 --- a/src/muxer/mplex/mplexed_connection.cpp +++ b/src/muxer/mplex/mplexed_connection.cpp @@ -126,9 +126,8 @@ namespace libp2p::connection { } void MplexedConnection::readSome(BytesOut out, - size_t bytes, ReadCallbackFunc cb) { - connection_->readSome(out, bytes, std::move(cb)); + connection_->readSome(out, std::move(cb)); } void MplexedConnection::writeSome(BytesIn in, diff --git a/src/muxer/yamux/yamux_stream.cpp b/src/muxer/yamux/yamux_stream.cpp index b4a895e26..e16f2037f 100644 --- a/src/muxer/yamux/yamux_stream.cpp +++ b/src/muxer/yamux/yamux_stream.cpp @@ -9,7 +9,6 @@ #include #include -#include #include #include @@ -67,8 +66,7 @@ namespace libp2p::connection { assert(write_queue_limit >= maximum_window_size_); } - void YamuxStream::readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) { - ambigousSize(out, bytes); + void YamuxStream::readSome(BytesOut out, ReadCallbackFunc cb) { doRead(out, std::move(cb)); } diff --git a/src/muxer/yamux/yamuxed_connection.cpp b/src/muxer/yamux/yamuxed_connection.cpp index 2138ec70e..5177298ba 100644 --- a/src/muxer/yamux/yamuxed_connection.cpp +++ b/src/muxer/yamux/yamuxed_connection.cpp @@ -164,7 +164,6 @@ namespace libp2p::connection { } void YamuxedConnection::readSome(BytesOut out, - size_t bytes, ReadCallbackFunc cb) { log()->error("YamuxedConnection::readSome : invalid direct call"); deferReadCallback(Error::CONNECTION_DIRECT_IO_FORBIDDEN, std::move(cb)); @@ -189,7 +188,6 @@ namespace libp2p::connection { void YamuxedConnection::continueReading() { SL_TRACE(log(), "YamuxedConnection::continueReading"); connection_->readSome(*raw_read_buffer_, - raw_read_buffer_->size(), [wptr = weak_from_this(), buffer = raw_read_buffer_]( outcome::result res) { auto self = wptr.lock(); diff --git a/src/protocol/echo/client_echo_session.cpp b/src/protocol/echo/client_echo_session.cpp index 2457267dd..f1b36ab8e 100644 --- a/src/protocol/echo/client_echo_session.cpp +++ b/src/protocol/echo/client_echo_session.cpp @@ -55,7 +55,7 @@ namespace libp2p::protocol { completed(); } - stream_->readSome(span, span.size(), [self](outcome::result rr) { + stream_->readSome(span, [self](outcome::result rr) { if (!rr && !self->ec_) { self->ec_ = rr.error(); return self->completed(); diff --git a/src/protocol/echo/server_echo_session.cpp b/src/protocol/echo/server_echo_session.cpp index c07b6780f..291bea4fe 100644 --- a/src/protocol/echo/server_echo_session.cpp +++ b/src/protocol/echo/server_echo_session.cpp @@ -48,7 +48,6 @@ namespace libp2p::protocol { stream_->readSome( buf_, - buf_.size(), [self{shared_from_this()}](outcome::result rread) { self->onRead(rread); }); diff --git a/src/security/noise/noise_connection.cpp b/src/security/noise/noise_connection.cpp index db8360066..8a2003145 100644 --- a/src/security/noise/noise_connection.cpp +++ b/src/security/noise/noise_connection.cpp @@ -7,7 +7,6 @@ #include #include -#include #include #include #include @@ -47,9 +46,7 @@ namespace libp2p::connection { } void NoiseConnection::readSome(BytesOut out, - size_t bytes, libp2p::basic::Reader::ReadCallbackFunc cb) { - ambigousSize(out, bytes); if (not frame_buffer_->empty()) { auto n{std::min(out.size(), frame_buffer_->size())}; auto begin{frame_buffer_->begin()}; @@ -65,7 +62,7 @@ namespace libp2p::connection { auto decrypted = IF_ERROR_CB_RETURN(self->decoder_cs_->decrypt({}, *data, {})); self->frame_buffer_->assign(decrypted.begin(), decrypted.end()); - self->readSome(out, out.size(), std::move(cb)); + self->readSome(out, std::move(cb)); }); } diff --git a/src/security/plaintext/plaintext_connection.cpp b/src/security/plaintext/plaintext_connection.cpp index fe561575c..17eadf700 100644 --- a/src/security/plaintext/plaintext_connection.cpp +++ b/src/security/plaintext/plaintext_connection.cpp @@ -59,9 +59,8 @@ namespace libp2p::connection { } void PlaintextConnection::readSome(BytesOut in, - size_t bytes, Reader::ReadCallbackFunc f) { - return original_connection_->readSome(in, bytes, std::move(f)); + return original_connection_->readSome(in, std::move(f)); }; void PlaintextConnection::writeSome(BytesIn in, diff --git a/src/security/secio/secio_connection.cpp b/src/security/secio/secio_connection.cpp index 1c3699973..78f6dd633 100644 --- a/src/security/secio/secio_connection.cpp +++ b/src/security/secio/secio_connection.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -184,9 +183,7 @@ namespace libp2p::connection { } void SecioConnection::readSome(BytesOut out, - size_t bytes, basic::Reader::ReadCallbackFunc cb) { - ambigousSize(out, bytes); // TODO(107): Reentrancy if (!isInitialized()) { @@ -205,7 +202,7 @@ namespace libp2p::connection { readNextMessage([self{shared_from_this()}, out, cb{std::move(cb)}]( outcome::result result) { IF_ERROR_CB_RETURN(result); - self->readSome(out, out.size(), std::move(cb)); + self->readSome(out, std::move(cb)); }); } diff --git a/src/security/tls/tls_connection.cpp b/src/security/tls/tls_connection.cpp index 6dd7863d5..a26840699 100644 --- a/src/security/tls/tls_connection.cpp +++ b/src/security/tls/tls_connection.cpp @@ -7,7 +7,6 @@ #include "tls_connection.hpp" #include -#include #include #include @@ -141,10 +140,8 @@ namespace libp2p::connection { } void TlsConnection::readSome(BytesOut out, - size_t bytes, Reader::ReadCallbackFunc cb) { - ambigousSize(out, bytes); - SL_TRACE(log(), "reading some up to {} bytes", bytes); + SL_TRACE(log(), "reading some up to {} bytes", out.size()); socket_.async_read_some(asioBuffer(out), closeOnError(*this, std::move(cb))); } diff --git a/src/security/tls/tls_connection.hpp b/src/security/tls/tls_connection.hpp index a022e9952..590907e79 100644 --- a/src/security/tls/tls_connection.hpp +++ b/src/security/tls/tls_connection.hpp @@ -77,7 +77,7 @@ namespace libp2p::connection { outcome::result remoteMultiaddr() override; /// Async reads up to the # of bytes given - void readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) override; + void readSome(BytesOut out, ReadCallbackFunc cb) override; /// Defers read callback to avoid reentrancy in async calls void deferReadCallback(outcome::result res, diff --git a/src/transport/quic/connection.cpp b/src/transport/quic/connection.cpp index 2910d4550..c39f0ef50 100644 --- a/src/transport/quic/connection.cpp +++ b/src/transport/quic/connection.cpp @@ -33,7 +33,6 @@ namespace libp2p::transport { } void QuicConnection::readSome(BytesOut out, - size_t bytes, ReadCallbackFunc cb) { throw std::logic_error{"QuicConnection::readSome must not be called"}; } diff --git a/src/transport/quic/stream.cpp b/src/transport/quic/stream.cpp index d37f27759..33e0baa60 100644 --- a/src/transport/quic/stream.cpp +++ b/src/transport/quic/stream.cpp @@ -6,7 +6,6 @@ #include #include -#include #include #include #include @@ -27,9 +26,7 @@ namespace libp2p::connection { } void QuicStream::readSome(BytesOut out, - size_t bytes, basic::Reader::ReadCallbackFunc cb) { - ambigousSize(out, bytes); outcome::result r = QuicError::STREAM_CLOSED; if (not stream_ctx_) { return cb(r); diff --git a/src/transport/tcp/tcp_connection.cpp b/src/transport/tcp/tcp_connection.cpp index 60841e261..af531a896 100644 --- a/src/transport/tcp/tcp_connection.cpp +++ b/src/transport/tcp/tcp_connection.cpp @@ -7,7 +7,6 @@ #include #include -#include #include #include #include @@ -173,11 +172,9 @@ namespace libp2p::transport { } void TcpConnection::readSome(BytesOut out, - size_t bytes, TcpConnection::ReadCallbackFunc cb) { - ByteCounter::getInstance().incrementBytesRead(bytes); - ambigousSize(out, bytes); - TRACE("{} read some up to {}", debug_str_, bytes); + ByteCounter::getInstance().incrementBytesRead(out.size()); + TRACE("{} read some up to {}", debug_str_, out.size()); socket_.async_read_some(asioBuffer(out), closeOnError(*this, std::move(cb))); } diff --git a/test/acceptance/p2p/muxer.cpp b/test/acceptance/p2p/muxer.cpp index a0c67e261..67731bf9d 100644 --- a/test/acceptance/p2p/muxer.cpp +++ b/test/acceptance/p2p/muxer.cpp @@ -128,7 +128,7 @@ struct Server : public std::enable_shared_from_this { println("onStream executed"); stream->readSome( - *buf, buf->size(), [buf, stream, this](outcome::result rread) { + *buf, [buf, stream, this](outcome::result rread) { if (!rread) { if (rread.error() == RawConnection::Error::CONNECTION_CLOSED_BY_PEER || rread.error() == Stream::Error::STREAM_RESET_BY_HOST) { diff --git a/test/libp2p/transport/tcp/tcp_integration_test.cpp b/test/libp2p/transport/tcp/tcp_integration_test.cpp index e156969b9..d9fe9edef 100644 --- a/test/libp2p/transport/tcp/tcp_integration_test.cpp +++ b/test/libp2p/transport/tcp/tcp_integration_test.cpp @@ -147,7 +147,7 @@ TEST(TCP, SingleListenerCanAcceptManyClients) { auto buf = std::make_shared>(kSize, 0); conn->readSome( - *buf, buf->size(), [&counter, conn, buf, context](auto &&res) { + *buf, [&counter, conn, buf, context](auto &&res) { ASSERT_OUTCOME_SUCCESS(res); libp2p::writeReturnSize( @@ -244,7 +244,7 @@ TEST(TCP, ClientClosesConnection) { EXPECT_FALSE(conn->isInitiator()); auto buf = std::make_shared>(100, 0); - conn->readSome(*buf, buf->size(), [conn, buf](auto &&res) { + conn->readSome(*buf, [conn, buf](auto &&res) { ASSERT_OUTCOME_ERROR(res, boost::asio::error::eof); }); }); @@ -286,7 +286,7 @@ TEST(TCP, ServerClosesConnection) { auto conn = expectConnectionValid(rconn); EXPECT_TRUE(conn->isInitiator()); auto buf = std::make_shared>(100, 0); - conn->readSome(*buf, buf->size(), [conn, buf](auto &&res) { + conn->readSome(*buf, [conn, buf](auto &&res) { ASSERT_OUTCOME_ERROR(res, boost::asio::error::eof); }); }); @@ -312,7 +312,7 @@ TEST(TCP, OneTransportServerHandlesManyClients) { EXPECT_FALSE(conn->isInitiator()); auto buf = std::make_shared>(kSize, 0); - conn->readSome(*buf, kSize, [&counter, conn, buf](auto &&res) { + conn->readSome(*buf, [&counter, conn, buf](auto &&res) { ASSERT_OUTCOME_SUCCESS(res); libp2p::writeReturnSize(conn, *buf, [&counter, buf, conn](auto &&res) { diff --git a/test/mock/libp2p/basic/read_writer_mock.hpp b/test/mock/libp2p/basic/read_writer_mock.hpp index ecc1f02b2..815e6b63b 100644 --- a/test/mock/libp2p/basic/read_writer_mock.hpp +++ b/test/mock/libp2p/basic/read_writer_mock.hpp @@ -12,7 +12,7 @@ namespace libp2p::basic { struct ReadWriterMock : public ReadWriter { - MOCK_METHOD3(readSome, void(BytesOut, size_t, Reader::ReadCallbackFunc)); + MOCK_METHOD2(readSome, void(BytesOut, Reader::ReadCallbackFunc)); MOCK_METHOD2(writeSome, void(BytesIn, Writer::WriteCallbackFunc)); }; diff --git a/test/mock/libp2p/connection/capable_connection_mock.hpp b/test/mock/libp2p/connection/capable_connection_mock.hpp index c5a6d81ae..c5345a29d 100644 --- a/test/mock/libp2p/connection/capable_connection_mock.hpp +++ b/test/mock/libp2p/connection/capable_connection_mock.hpp @@ -32,7 +32,7 @@ namespace libp2p::connection { MOCK_CONST_METHOD0(isClosed, bool(void)); MOCK_METHOD0(close, outcome::result()); - MOCK_METHOD3(readSome, void(BytesOut, size_t, Reader::ReadCallbackFunc)); + MOCK_METHOD2(readSome, void(BytesOut, Reader::ReadCallbackFunc)); MOCK_METHOD2(writeSome, void(BytesIn, Writer::WriteCallbackFunc)); MOCK_METHOD2(deferReadCallback, void(outcome::result, Reader::ReadCallbackFunc)); @@ -82,9 +82,8 @@ namespace libp2p::connection { }; void readSome(BytesOut in, - size_t bytes, Reader::ReadCallbackFunc f) override { - return real_->readSome(in, bytes, f); + return real_->readSome(in, f); }; void writeSome(BytesIn in, diff --git a/test/mock/libp2p/connection/layer_connection_mock.hpp b/test/mock/libp2p/connection/layer_connection_mock.hpp index dc8ca5f84..4473f7d59 100644 --- a/test/mock/libp2p/connection/layer_connection_mock.hpp +++ b/test/mock/libp2p/connection/layer_connection_mock.hpp @@ -21,7 +21,7 @@ namespace libp2p::connection { MOCK_METHOD0(close, outcome::result()); - MOCK_METHOD3(readSome, void(BytesOut, size_t, Reader::ReadCallbackFunc)); + MOCK_METHOD2(readSome, void(BytesOut, Reader::ReadCallbackFunc)); MOCK_METHOD2(writeSome, void(BytesIn, Writer::WriteCallbackFunc)); MOCK_METHOD2(deferReadCallback, void(outcome::result, Reader::ReadCallbackFunc)); diff --git a/test/mock/libp2p/connection/secure_connection_mock.hpp b/test/mock/libp2p/connection/secure_connection_mock.hpp index 47136fe3a..13007db2d 100644 --- a/test/mock/libp2p/connection/secure_connection_mock.hpp +++ b/test/mock/libp2p/connection/secure_connection_mock.hpp @@ -19,7 +19,7 @@ namespace libp2p::connection { MOCK_METHOD0(close, outcome::result(void)); - MOCK_METHOD3(readSome, void(BytesOut, size_t, Reader::ReadCallbackFunc)); + MOCK_METHOD2(readSome, void(BytesOut, Reader::ReadCallbackFunc)); MOCK_METHOD2(writeSome, void(BytesIn, Writer::WriteCallbackFunc)); MOCK_METHOD2(deferReadCallback, diff --git a/test/mock/libp2p/connection/stream_mock.hpp b/test/mock/libp2p/connection/stream_mock.hpp index 8f2455834..0dcd61308 100644 --- a/test/mock/libp2p/connection/stream_mock.hpp +++ b/test/mock/libp2p/connection/stream_mock.hpp @@ -27,7 +27,7 @@ namespace libp2p::connection { MOCK_METHOD1(close, void(VoidResultHandlerFunc)); - MOCK_METHOD3(readSome, void(BytesOut, size_t, Reader::ReadCallbackFunc)); + MOCK_METHOD2(readSome, void(BytesOut, Reader::ReadCallbackFunc)); MOCK_METHOD2(writeSome, void(BytesIn, Writer::WriteCallbackFunc)); MOCK_METHOD2(deferReadCallback, diff --git a/test/testutil/expect_read.hpp b/test/testutil/expect_read.hpp index 7e5fbb08c..ccf770a88 100644 --- a/test/testutil/expect_read.hpp +++ b/test/testutil/expect_read.hpp @@ -10,29 +10,23 @@ #include #define EXPECT_CALL_READ(mock) \ - EXPECT_CALL(mock, readSome(testing::_, testing::_, testing::_)) + EXPECT_CALL(mock, readSome(testing::_, testing::_)) #define WILL_READ(_expected) \ WillOnce([expected{qtils::asVec(_expected)}]( \ libp2p::BytesOut out, \ - size_t ambigous_size, \ libp2p::basic::Reader::ReadCallbackFunc cb) { \ - ASSERT_EQ(out.size(), ambigous_size); \ ASSERT_GE(out.size(), expected.size()); \ memcpy(out.data(), expected.data(), expected.size()); \ cb(expected.size()); \ }) #define WILL_READ_SIZE(_expected) \ WillOnce([expected{_expected}](libp2p::BytesOut out, \ - size_t ambigous_size, \ libp2p::basic::Reader::ReadCallbackFunc cb) { \ - ASSERT_EQ(out.size(), ambigous_size); \ ASSERT_EQ(out.size(), expected); \ cb(expected); \ }) #define WILL_READ_ERROR() \ WillOnce([](libp2p::BytesOut out, \ - size_t ambigous_size, \ libp2p::basic::Reader::ReadCallbackFunc cb) { \ - ASSERT_EQ(out.size(), ambigous_size); \ cb(std::errc::io_error); \ })