Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions include/libp2p/basic/reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,6 @@ namespace libp2p::basic {

virtual ~Reader() = default;

/**
* @brief Reads exactly {@code} min(out.size(), bytes) {@nocode} bytes to
* the buffer.
* @param out output argument. Read data will be written to this buffer.
* @param bytes number of bytes to read
* @param cb callback with result of operation
*
* @note caller should maintain validity of an output buffer until callback
* is executed. It is usually done with either wrapping buffer as shared
* pointer, or having buffer as part of some class/struct, and using
* enable_shared_from_this()
*/
virtual void read(BytesOut out, size_t bytes, ReadCallbackFunc cb) = 0;

/**
* @brief Reads up to {@code} min(out.size(), bytes) {@nocode} bytes to the
* buffer.
Expand Down
2 changes: 0 additions & 2 deletions include/libp2p/connection/loopback_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ namespace libp2p::connection {
const override;

protected:
void read(BytesOut out, size_t bytes, ReadCallbackFunc cb) override;

void readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) override;

void writeSome(BytesIn in, size_t bytes, WriteCallbackFunc cb) override;
Expand Down
1 change: 0 additions & 1 deletion include/libp2p/layer/websocket/ssl_connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ namespace libp2p::connection {
outcome::result<void> close() override;
bool isClosed() const override;

void read(BytesOut out, size_t bytes, ReadCallbackFunc cb) override;
void readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) override;
void deferReadCallback(outcome::result<size_t> res,
ReadCallbackFunc cb) override;
Expand Down
2 changes: 0 additions & 2 deletions include/libp2p/layer/websocket/ws_connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ namespace libp2p::connection {

bool isClosed() const override;

void read(BytesOut out, size_t bytes, ReadCallbackFunc cb) override;

void readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) override;

void deferReadCallback(outcome::result<size_t> res,
Expand Down
2 changes: 0 additions & 2 deletions include/libp2p/muxer/mplex/mplex_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ namespace libp2p::connection {

~MplexStream() override = default;

void read(BytesOut out, size_t bytes, ReadCallbackFunc cb) override;

void readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) override;

void deferReadCallback(outcome::result<size_t> res,
Expand Down
1 change: 0 additions & 1 deletion include/libp2p/muxer/mplex/mplexed_connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ namespace libp2p::connection {

/// usage of these four methods is highly not recommended or even forbidden:
/// use stream over this connection instead
void read(BytesOut out, size_t bytes, ReadCallbackFunc cb) override;
void readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) override;
void writeSome(BytesIn in, size_t bytes, WriteCallbackFunc cb) override;

Expand Down
2 changes: 0 additions & 2 deletions include/libp2p/muxer/yamux/yamux_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ namespace libp2p::connection {
size_t maximum_window_size,
size_t write_queue_limit);

void read(BytesOut out, size_t bytes, ReadCallbackFunc cb) override;

void readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) override;

void deferReadCallback(outcome::result<size_t> res,
Expand Down
1 change: 0 additions & 1 deletion include/libp2p/muxer/yamux/yamuxed_connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ namespace libp2p::connection {

/// usage of these four methods is highly not recommended or even forbidden:
/// use stream over this connection instead
void read(BytesOut out, size_t bytes, ReadCallbackFunc cb) override;
void readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) override;
void writeSome(BytesIn in, size_t bytes, WriteCallbackFunc cb) override;

Expand Down
2 changes: 0 additions & 2 deletions include/libp2p/security/noise/noise_connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ namespace libp2p::connection {

outcome::result<void> close() override;

void read(BytesOut out, size_t bytes, ReadCallbackFunc cb) override;

void readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) override;

void deferReadCallback(outcome::result<size_t> res,
Expand Down
2 changes: 0 additions & 2 deletions include/libp2p/security/plaintext/plaintext_connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ namespace libp2p::connection {

outcome::result<multi::Multiaddress> remoteMultiaddr() override;

void read(BytesOut out, size_t bytes, ReadCallbackFunc cb) override;

void readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) override;

void deferReadCallback(outcome::result<size_t> res,
Expand Down
2 changes: 0 additions & 2 deletions include/libp2p/security/secio/secio_connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ namespace libp2p::connection {

outcome::result<multi::Multiaddress> remoteMultiaddr() override;

void read(BytesOut out, size_t bytes, ReadCallbackFunc cb) override;

void readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) override;

void deferReadCallback(outcome::result<size_t> res,
Expand Down
1 change: 0 additions & 1 deletion include/libp2p/transport/quic/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ namespace libp2p::transport {
void operator=(QuicConnection &&) = delete;

// Reader
void read(BytesOut out, size_t bytes, ReadCallbackFunc cb) override;
void readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) override;
void deferReadCallback(outcome::result<size_t> res,
ReadCallbackFunc cb) override;
Expand Down
1 change: 0 additions & 1 deletion include/libp2p/transport/quic/stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ namespace libp2p::connection {
void operator=(QuicStream &&) = delete;

// Reader
void read(BytesOut out, size_t bytes, ReadCallbackFunc cb) override;
void readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) override;
void deferReadCallback(outcome::result<size_t> res,
ReadCallbackFunc cb) override;
Expand Down
2 changes: 0 additions & 2 deletions include/libp2p/transport/tcp/tcp_connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ namespace libp2p::transport {
ConnectCallbackFunc cb,
std::chrono::milliseconds timeout);

void read(BytesOut out, size_t bytes, ReadCallbackFunc cb) override;

void readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) override;

void deferReadCallback(outcome::result<size_t> res,
Expand Down
9 changes: 5 additions & 4 deletions src/basic/message_read_writer_bigendian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <arpa/inet.h>
#include <boost/assert.hpp>
#include <libp2p/basic/message_read_writer_error.hpp>
#include <libp2p/basic/read_return_size.hpp>
#include <libp2p/basic/write_return_size.hpp>
#include <libp2p/common/byteutil.hpp>

Expand All @@ -24,9 +25,9 @@ namespace libp2p::basic {
void MessageReadWriterBigEndian::read(ReadCallbackFunc cb) {
auto buffer = std::make_shared<std::vector<uint8_t>>();
buffer->resize(kLenMarkerSize);
conn_->read(
readReturnSize(
conn_,
*buffer,
kLenMarkerSize,
[self{shared_from_this()}, buffer, cb{std::move(cb)}](auto &&result) {
if (not result) {
return cb(result.error());
Expand All @@ -35,8 +36,8 @@ namespace libp2p::basic {
common::convert<uint32_t>(buffer->data()));
buffer->resize(msg_len);
std::fill(buffer->begin(), buffer->end(), 0u);
self->conn_->read(
*buffer, msg_len, [self, buffer, cb](auto &&result) {
readReturnSize(
self->conn_, *buffer, [self, buffer, cb](auto &&result) {
if (not result) {
return cb(result.error());
}
Expand Down
5 changes: 3 additions & 2 deletions src/basic/message_read_writer_uvarint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <boost/assert.hpp>
#include <boost/optional.hpp>
#include <libp2p/basic/message_read_writer_error.hpp>
#include <libp2p/basic/read_return_size.hpp>
#include <libp2p/basic/varint_reader.hpp>
#include <libp2p/basic/write_return_size.hpp>
#include <libp2p/multi/uvarint.hpp>
Expand All @@ -34,9 +35,9 @@ namespace libp2p::basic {
auto msg_len = varint_res.value().toUInt64();
if (0 != msg_len) {
auto buffer = std::make_shared<std::vector<uint8_t>>(msg_len, 0);
self->conn_->read(
readReturnSize(
self->conn_,
*buffer,
msg_len,
[self, buffer, cb = std::move(cb)](auto &&res) mutable {
if (!res) {
return cb(res.error());
Expand Down
7 changes: 4 additions & 3 deletions src/basic/varint_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include <libp2p/basic/varint_reader.hpp>
#include <libp2p/basic/read_return_size.hpp>

#include <vector>

Expand Down Expand Up @@ -44,10 +45,10 @@ namespace libp2p::basic {
}

// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
conn->read(
readReturnSize(
conn,
std::span(varint_buf->data() + current_length, 1),
1,
[c = std::move(conn), cb = std::move(cb), current_length, varint_buf](
[c = conn, cb = std::move(cb), current_length, varint_buf](
auto &&res) mutable {
if (not res.has_value()) {
return cb(res.error());
Expand Down
7 changes: 0 additions & 7 deletions src/connection/loopback_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,6 @@ namespace libp2p::connection {
return outcome::success(own_peer_info_.addresses.front());
}

void LoopbackStream::read(BytesOut out,
size_t bytes,
libp2p::basic::Reader::ReadCallbackFunc cb) {
ambigousSize(out, bytes);
readReturnSize(shared_from_this(), out, std::move(cb));
}

void LoopbackStream::writeSome(BytesIn in,
size_t bytes,
libp2p::basic::Writer::WriteCallbackFunc cb) {
Expand Down
7 changes: 0 additions & 7 deletions src/layer/websocket/ssl_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ namespace libp2p::connection {
return connection_->close();
}

void SslConnection::read(BytesOut out,
size_t bytes,
libp2p::basic::Reader::ReadCallbackFunc cb) {
ambigousSize(out, bytes);
readReturnSize(shared_from_this(), out, std::move(cb));
}

void SslConnection::readSome(BytesOut out,
size_t bytes,
libp2p::basic::Reader::ReadCallbackFunc cb) {
Expand Down
8 changes: 0 additions & 8 deletions src/layer/websocket/ws_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,6 @@ namespace libp2p::connection {
return connection_->close();
}

void WsConnection::read(BytesOut out,
size_t bytes,
libp2p::basic::Reader::ReadCallbackFunc cb) {
ambigousSize(out, bytes);
SL_TRACE(log_, "read {} bytes", bytes);
readReturnSize(shared_from_this(), out, std::move(cb));
}

void WsConnection::readSome(BytesOut out,
size_t bytes,
libp2p::basic::Reader::ReadCallbackFunc cb) {
Expand Down
19 changes: 10 additions & 9 deletions src/muxer/mplex/mplex_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <libp2p/muxer/mplex/mplex_frame.hpp>

#include <libp2p/basic/read_return_size.hpp>
#include <libp2p/basic/varint_reader.hpp>
#include <libp2p/multi/uvarint.hpp>
#include <libp2p/muxer/mplex/mplexed_connection.hpp>
Expand Down Expand Up @@ -100,16 +101,16 @@ namespace libp2p::connection {
// read data
std::shared_ptr<Bytes> data =
std::make_shared<Bytes>(length, 0);
reader->read(*data,
length,
[id_flag, data, cb{std::move(cb)}](
auto &&read_res) mutable {
if (!read_res) {
return cb(read_res.error());
}
readReturnSize(reader,
*data,
[id_flag, data, cb{std::move(cb)}](
auto &&read_res) mutable {
if (!read_res) {
return cb(read_res.error());
}

cb(createFrame(id_flag, std::move(*data)));
});
cb(createFrame(id_flag, std::move(*data)));
});
});
});
}
Expand Down
5 changes: 0 additions & 5 deletions src/muxer/mplex/mplex_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ namespace libp2p::connection {
StreamId stream_id)
: connection_{std::move(connection)}, stream_id_{stream_id} {}

void MplexStream::read(BytesOut out, size_t bytes, ReadCallbackFunc cb) {
ambigousSize(out, bytes);
readReturnSize(shared_from_this(), out, std::move(cb));
}

void MplexStream::readDone(outcome::result<size_t> res) {
auto cb{std::move(reading_->cb)};
reading_.reset();
Expand Down
7 changes: 1 addition & 6 deletions src/muxer/mplex/mplexed_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <libp2p/muxer/mplex/mplexed_connection.hpp>

#include <boost/assert.hpp>
#include <libp2p/basic/read_return_size.hpp>
#include <libp2p/basic/write_return_size.hpp>
#include <libp2p/muxer/mplex/mplex_frame.hpp>

Expand Down Expand Up @@ -124,12 +125,6 @@ namespace libp2p::connection {
return !is_active_ || connection_->isClosed();
}

void MplexedConnection::read(BytesOut out,
size_t bytes,
ReadCallbackFunc cb) {
connection_->read(out, bytes, std::move(cb));
}

void MplexedConnection::readSome(BytesOut out,
size_t bytes,
ReadCallbackFunc cb) {
Expand Down
5 changes: 0 additions & 5 deletions src/muxer/yamux/yamux_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ namespace libp2p::connection {
assert(write_queue_limit >= maximum_window_size_);
}

void YamuxStream::read(BytesOut out, size_t bytes, ReadCallbackFunc cb) {
ambigousSize(out, bytes);
readReturnSize(shared_from_this(), out, std::move(cb));
}

void YamuxStream::readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) {
ambigousSize(out, bytes);
doRead(out, std::move(cb));
Expand Down
7 changes: 0 additions & 7 deletions src/muxer/yamux/yamuxed_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,6 @@ namespace libp2p::connection {
return !started_ || connection_->isClosed();
}

void YamuxedConnection::read(BytesOut out,
size_t bytes,
ReadCallbackFunc cb) {
log()->error("YamuxedConnection::read : invalid direct call");
deferReadCallback(Error::CONNECTION_DIRECT_IO_FORBIDDEN, std::move(cb));
}

void YamuxedConnection::readSome(BytesOut out,
size_t bytes,
ReadCallbackFunc cb) {
Expand Down
19 changes: 10 additions & 9 deletions src/protocol/gossip/impl/stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <cassert>

#include <libp2p/basic/read_return_size.hpp>
#include <libp2p/basic/varint_reader.hpp>
#include <libp2p/basic/write_return_size.hpp>

Expand Down Expand Up @@ -83,15 +84,15 @@ namespace libp2p::protocol::gossip {

read_buffer_->resize(msg_len);

stream_->read(std::span(read_buffer_->data(), msg_len),
msg_len,
[self_wptr = weak_from_this(), this, buffer = read_buffer_](
auto &&res) {
if (self_wptr.expired()) {
return;
}
onMessageRead(std::forward<decltype(res)>(res));
});
readReturnSize(stream_,
std::span(read_buffer_->data(), msg_len),
[self_wptr = weak_from_this(), this, buffer = read_buffer_](
auto &&res) {
if (self_wptr.expired()) {
return;
}
onMessageRead(std::forward<decltype(res)>(res));
});
}

void Stream::onMessageRead(outcome::result<size_t> res) {
Expand Down
11 changes: 6 additions & 5 deletions src/protocol/ping/ping_client_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <libp2p/protocol/ping/ping_client_session.hpp>

#include <boost/assert.hpp>
#include <libp2p/basic/read_return_size.hpp>
#include <libp2p/basic/write_return_size.hpp>
#include <libp2p/protocol/ping/common.hpp>

Expand Down Expand Up @@ -84,11 +85,11 @@ namespace libp2p::protocol {
},
config_.timeout);

stream_->read(read_buffer_,
config_.message_size,
[self{shared_from_this()}](outcome::result<size_t> r) {
self->readCompleted(r);
});
readReturnSize(stream_,
read_buffer_,
[self{shared_from_this()}](outcome::result<size_t> r) {
self->readCompleted(r);
});
}

void PingClientSession::readCompleted(outcome::result<size_t> r) {
Expand Down
Loading
Loading