Skip to content

Commit a303b8a

Browse files
committed
Merge branch 'master' into refactor/1
Signed-off-by: turuslan <[email protected]> # Conflicts: # example/02-kademlia/rendezvous_chat.cpp # src/protocol/ping/ping_client_session.cpp # src/protocol_muxer/multiselect/multiselect_instance.cpp # src/protocol_muxer/multiselect/simple_stream_negotiate.cpp # test/libp2p/connection/security_conn/plaintext_connection_test.cpp # test/libp2p/transport/tcp/tcp_integration_test.cpp
2 parents 9841a60 + e0d8e05 commit a303b8a

File tree

69 files changed

+298
-267
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+298
-267
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Bug Report
2+
description: Create a bug report for cpp-libp2p
3+
4+
body:
5+
- type: markdown
6+
attributes:
7+
value: |
8+
Thank you for filing a bug report!
9+
- type: textarea
10+
attributes:
11+
label: Summary
12+
description: Please provide a short summary of the bug, along with any information you feel relevant to replicate the bug.
13+
validations:
14+
required: true
15+
- type: textarea
16+
attributes:
17+
label: Expected behavior
18+
description: Describe what you expect to happen.
19+
validations:
20+
required: true
21+
- type: textarea
22+
attributes:
23+
label: Actual behavior
24+
description: Describe what actually happens.
25+
validations:
26+
required: true
27+
- type: textarea
28+
attributes:
29+
label: Relevant log output
30+
description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
31+
render: shell
32+
validations:
33+
required: false
34+
- type: textarea
35+
attributes:
36+
label: Possible Solution
37+
description: Suggest a fix/reason for the bug, or ideas how to implement the addition or change.
38+
validations:
39+
required: false
40+
- type: textarea
41+
attributes:
42+
label: Version
43+
description: Which version of libp2p are you using? libp2p version (version number, commit, or branch)
44+
validations:
45+
required: false
46+
- type: dropdown
47+
attributes:
48+
label: Would you like to work on fixing this bug ?
49+
description: Any contribution towards fixing the bug is greatly appreciated. We are more than happy to provide help on the process.
50+
options:
51+
- "Yes"
52+
- "No"
53+
- Maybe
54+
validations:
55+
required: true

.github/ISSUE_TEMPLATE/config.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
blank_issues_enabled: true
2+
contact_links:
3+
- name: Technical Questions
4+
url: https://github.com/libp2p/cpp-libp2p/discussions/new?category=q-a
5+
about: Please ask technical questions in the cpp-libp2p Github Discussions forum.
6+
- name: Community-wide libp2p Discussion
7+
url: https://discuss.libp2p.io
8+
about: Discussions and questions about the libp2p community.
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Enhancement
2+
description: Suggest an improvement to an existing cpp-libp2p feature.
3+
body:
4+
- type: textarea
5+
attributes:
6+
label: Description
7+
description: Describe the enhancement that you are proposing.
8+
validations:
9+
required: true
10+
- type: textarea
11+
attributes:
12+
label: Motivation
13+
description: Explain why this enhancement is beneficial.
14+
validations:
15+
required: true
16+
- type: textarea
17+
attributes:
18+
label: Current Implementation
19+
description: Describe the current implementation.
20+
validations:
21+
required: true
22+
- type: dropdown
23+
attributes:
24+
label: Are you planning to do it yourself in a pull request ?
25+
description: Any contribution is greatly appreciated. We are more than happy to provide help on the process.
26+
options:
27+
- "Yes"
28+
- "No"
29+
- Maybe
30+
validations:
31+
required: true
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Feature request
2+
description: Suggest a new feature in cpp-libp2p
3+
body:
4+
- type: markdown
5+
attributes:
6+
value: |
7+
If you'd like to suggest a feature related to libp2p but not specifically related to the C++ implementation, please file an issue at https://github.com/libp2p/specs instead.
8+
- type: textarea
9+
attributes:
10+
label: Description
11+
description: Briefly describe the feature that you are requesting.
12+
validations:
13+
required: true
14+
- type: textarea
15+
attributes:
16+
label: Motivation
17+
description: Explain why this feature is needed.
18+
validations:
19+
required: true
20+
- type: textarea
21+
attributes:
22+
label: Requirements
23+
description: Write a list of what you want this feature to do.
24+
placeholder: "1."
25+
validations:
26+
required: true
27+
- type: textarea
28+
attributes:
29+
label: Open questions
30+
description: Use this section to ask any questions that are related to the feature.
31+
validations:
32+
required: false
33+
- type: dropdown
34+
attributes:
35+
label: Are you planning to do it yourself in a pull request ?
36+
description: Any contribution is greatly appreciated. We are more than happy to provide help on the process.
37+
options:
38+
- "Yes"
39+
- "No"
40+
- Maybe
41+
validations:
42+
required: true

example/01-echo/libp2p_echo_server.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ dPtse4GVRA2swbXcZX5iFVi/V8poIpdVrgn5iMadkQnYf9APWJuGcebK
195195
io_context->run();
196196
std::exit(EXIT_SUCCESS);
197197
} catch (const boost::system::error_code &ec) {
198-
log->error("Server cannot run: {}", ec.message());
198+
log->error("Server cannot run: {}", ec);
199199
std::exit(EXIT_FAILURE);
200200
} catch (...) {
201201
log->error("Unknown error happened");

example/02-kademlia/rendezvous_chat.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <boost/beast.hpp>
1313

14+
#include <libp2p/basic/write_return_size.hpp>
1415
#include <libp2p/common/literals.hpp>
1516
#include <libp2p/injector/kademlia_injector.hpp>
1617
#include <libp2p/log/configurator.hpp>
@@ -69,9 +70,9 @@ class Session : public std::enable_shared_from_this<Session> {
6970
return false;
7071
}
7172

72-
stream_->write(
73+
libp2p::writeReturnSize(
74+
stream_,
7375
*buffer,
74-
buffer->size(),
7576
[self = shared_from_this(), buffer](outcome::result<size_t> result) {
7677
if (not result) {
7778
self->close();

example/03-gossip/console_async_reader.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ namespace libp2p::protocol::example::utility {
2121
void ConsoleAsyncReader::read() {
2222
input_.consume(input_.data().size());
2323
boost::asio::async_read_until(
24-
in_, input_, "\n",
24+
in_,
25+
input_,
26+
"\n",
2527
[this](const boost::system::error_code &e, std::size_t size) {
2628
onRead(e, size);
2729
});

example/03-gossip/console_async_reader.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
#pragma once
88

9-
#include <string>
109
#include <functional>
10+
#include <string>
1111

1212
#include <boost/asio.hpp>
1313

@@ -39,4 +39,4 @@ namespace libp2p::protocol::example::utility {
3939
bool stopped_ = false;
4040
};
4141

42-
} //namespace libp2p::protocol::example::utility
42+
} // namespace libp2p::protocol::example::utility

include/libp2p/basic/varint_prefix_reader.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ namespace libp2p::basic {
4242
return value_;
4343
}
4444

45+
size_t size() const {
46+
return got_bytes_;
47+
}
48+
4549
/// Resets reader's state
4650
void reset();
4751

include/libp2p/basic/writer.hpp

-15
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,6 @@ namespace libp2p::basic {
1919

2020
virtual ~Writer() = default;
2121

22-
/**
23-
* @brief Write exactly {@code} in.size() {@nocode} bytes.
24-
* Won't call \param cb before all are successfully written.
25-
* Returns immediately.
26-
* @param in data to write.
27-
* @param bytes number of bytes to write
28-
* @param cb callback with result of operation
29-
*
30-
* @note caller should maintain validity of an input buffer until callback
31-
* is executed. It is usually done with either wrapping buffer as shared
32-
* pointer, or having buffer as part of some class/struct, and using
33-
* enable_shared_from_this()
34-
*/
35-
virtual void write(BytesIn in, size_t bytes, WriteCallbackFunc cb) = 0;
36-
3722
/**
3823
* @brief Write up to {@code} in.size() {@nocode} bytes.
3924
* Calls \param cb after only some bytes has been successfully written,

include/libp2p/connection/loopback_stream.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ namespace libp2p::connection {
4444

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

47-
void write(BytesIn in, size_t bytes, WriteCallbackFunc cb) override;
48-
4947
void writeSome(BytesIn in, size_t bytes, WriteCallbackFunc cb) override;
5048

5149
void deferReadCallback(outcome::result<size_t> res,

include/libp2p/layer/websocket/ssl_connection.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ namespace libp2p::connection {
3737
void deferReadCallback(outcome::result<size_t> res,
3838
ReadCallbackFunc cb) override;
3939

40-
void write(BytesIn in, size_t bytes, WriteCallbackFunc cb) override;
4140
void writeSome(BytesIn in, size_t bytes, WriteCallbackFunc cb) override;
4241
void deferWriteCallback(std::error_code ec, WriteCallbackFunc cb) override;
4342

include/libp2p/layer/websocket/ws_connection.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ namespace libp2p::connection {
7575
void deferReadCallback(outcome::result<size_t> res,
7676
ReadCallbackFunc cb) override;
7777

78-
void write(BytesIn in, size_t bytes, WriteCallbackFunc cb) override;
79-
8078
void writeSome(BytesIn in, size_t bytes, WriteCallbackFunc cb) override;
8179

8280
void deferWriteCallback(std::error_code ec, WriteCallbackFunc cb) override;

include/libp2p/muxer/mplex/mplex_stream.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ namespace libp2p::connection {
5757
void deferReadCallback(outcome::result<size_t> res,
5858
ReadCallbackFunc cb) override;
5959

60-
void write(BytesIn in, size_t bytes, WriteCallbackFunc cb) override;
61-
6260
void writeSome(BytesIn in, size_t bytes, WriteCallbackFunc cb) override;
6361

6462
void deferWriteCallback(std::error_code ec, WriteCallbackFunc cb) override;

include/libp2p/muxer/mplex/mplexed_connection.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ namespace libp2p::connection {
6666
/// use stream over this connection instead
6767
void read(BytesOut out, size_t bytes, ReadCallbackFunc cb) override;
6868
void readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) override;
69-
void write(BytesIn in, size_t bytes, WriteCallbackFunc cb) override;
7069
void writeSome(BytesIn in, size_t bytes, WriteCallbackFunc cb) override;
7170

7271
void deferReadCallback(outcome::result<size_t> res,

include/libp2p/muxer/yamux/yamux_stream.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ namespace libp2p::connection {
5959
void deferReadCallback(outcome::result<size_t> res,
6060
ReadCallbackFunc cb) override;
6161

62-
void write(BytesIn in, size_t bytes, WriteCallbackFunc cb) override;
63-
6462
void writeSome(BytesIn in, size_t bytes, WriteCallbackFunc cb) override;
6563

6664
void deferWriteCallback(std::error_code ec, WriteCallbackFunc cb) override;

include/libp2p/muxer/yamux/yamuxed_connection.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ namespace libp2p::connection {
113113
/// use stream over this connection instead
114114
void read(BytesOut out, size_t bytes, ReadCallbackFunc cb) override;
115115
void readSome(BytesOut out, size_t bytes, ReadCallbackFunc cb) override;
116-
void write(BytesIn in, size_t bytes, WriteCallbackFunc cb) override;
117116
void writeSome(BytesIn in, size_t bytes, WriteCallbackFunc cb) override;
118117

119118
/// Initiates async readSome on connection

include/libp2p/security/noise/noise_connection.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ namespace libp2p::connection {
5353
void deferReadCallback(outcome::result<size_t> res,
5454
ReadCallbackFunc cb) override;
5555

56-
void write(BytesIn in, size_t bytes, WriteCallbackFunc cb) override;
57-
5856
void writeSome(BytesIn in, size_t bytes, WriteCallbackFunc cb) override;
5957

6058
void deferWriteCallback(std::error_code ec, WriteCallbackFunc cb) override;

include/libp2p/security/plaintext/plaintext_connection.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ namespace libp2p::connection {
4242
void deferReadCallback(outcome::result<size_t> res,
4343
ReadCallbackFunc cb) override;
4444

45-
void write(BytesIn in, size_t bytes, WriteCallbackFunc cb) override;
46-
4745
void writeSome(BytesIn in, size_t bytes, WriteCallbackFunc cb) override;
4846

4947
void deferWriteCallback(std::error_code ec, WriteCallbackFunc cb) override;

include/libp2p/security/secio/secio_connection.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ namespace libp2p::connection {
103103
void deferReadCallback(outcome::result<size_t> res,
104104
ReadCallbackFunc cb) override;
105105

106-
void write(BytesIn in, size_t bytes, WriteCallbackFunc cb) override;
107-
108106
void writeSome(BytesIn in, size_t bytes, WriteCallbackFunc cb) override;
109107

110108
void deferWriteCallback(std::error_code ec, WriteCallbackFunc cb) override;

include/libp2p/transport/tcp/tcp_connection.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ namespace libp2p::transport {
9595
void deferReadCallback(outcome::result<size_t> res,
9696
ReadCallbackFunc cb) override;
9797

98-
void write(BytesIn in, size_t bytes, WriteCallbackFunc cb) override;
99-
10098
void writeSome(BytesIn in, size_t bytes, WriteCallbackFunc cb) override;
10199

102100
void deferWriteCallback(std::error_code ec, WriteCallbackFunc cb) override;

src/basic/message_read_writer_bigendian.cpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <arpa/inet.h>
1212
#include <boost/assert.hpp>
1313
#include <libp2p/basic/message_read_writer_error.hpp>
14+
#include <libp2p/basic/write_return_size.hpp>
1415
#include <libp2p/common/byteutil.hpp>
1516

1617
namespace libp2p::basic {
@@ -55,13 +56,14 @@ namespace libp2p::basic {
5556
raw_buf.reserve(kLenMarkerSize + buffer.size());
5657
common::putUint32BE(raw_buf, buffer.size());
5758
raw_buf.insert(raw_buf.end(), buffer.begin(), buffer.end());
58-
conn_->write(raw_buf,
59-
raw_buf.size(),
60-
[self{shared_from_this()}, cb{std::move(cb)}](auto &&result) {
61-
if (not result) {
62-
return cb(result.error());
63-
}
64-
cb(result.value() - self->kLenMarkerSize);
65-
});
59+
writeReturnSize(
60+
conn_,
61+
raw_buf,
62+
[self{shared_from_this()}, cb{std::move(cb)}](auto &&result) {
63+
if (not result) {
64+
return cb(result.error());
65+
}
66+
cb(result.value() - self->kLenMarkerSize);
67+
});
6668
}
6769
} // namespace libp2p::basic

src/basic/message_read_writer_uvarint.cpp

+12-11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <boost/optional.hpp>
1313
#include <libp2p/basic/message_read_writer_error.hpp>
1414
#include <libp2p/basic/varint_reader.hpp>
15+
#include <libp2p/basic/write_return_size.hpp>
1516
#include <libp2p/multi/uvarint.hpp>
1617

1718
namespace libp2p::basic {
@@ -59,16 +60,16 @@ namespace libp2p::basic {
5960
std::make_move_iterator(varint_len.toVector().end()));
6061
msg_bytes->insert(msg_bytes->end(), buffer.begin(), buffer.end());
6162

62-
conn_->write(*msg_bytes,
63-
msg_bytes->size(),
64-
[cb = std::move(cb),
65-
varint_size = varint_len.size(),
66-
msg_bytes](auto &&res) {
67-
if (!res) {
68-
return cb(res.error());
69-
}
70-
// hide a written varint from the user of the method
71-
cb(res.value() - varint_size);
72-
});
63+
writeReturnSize(conn_,
64+
*msg_bytes,
65+
[cb = std::move(cb),
66+
varint_size = varint_len.size(),
67+
msg_bytes](auto &&res) {
68+
if (!res) {
69+
return cb(res.error());
70+
}
71+
// hide a written varint from the user of the method
72+
cb(res.value() - varint_size);
73+
});
7374
}
7475
} // namespace libp2p::basic

0 commit comments

Comments
 (0)