Skip to content

Commit 911b65b

Browse files
authored
Merge pull request #686 from evoskuil/master
Pass maximum request setting from config to socket.
2 parents 81ff25c + 604e00e commit 911b65b

32 files changed

+228
-205
lines changed

include/bitcoin/network/channels/channel_rpc.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,17 @@ class BCT_API channel_rpc
6060
{
6161
}
6262

63+
/// Serialize and write response to client (requires strand).
64+
/// Completion handler is always invoked on the channel strand.
65+
void send(rpc::response_t&& message, size_t size_hint,
66+
result_handler&& handler) NOEXCEPT;
67+
6368
/// Resume reading from the socket (requires strand).
6469
void resume() NOEXCEPT override;
6570

6671
/// Must call after successful message handling if no stop.
6772
virtual void receive() NOEXCEPT;
6873

69-
/// Serialize and write response to client (requires strand).
70-
/// Completion handler is always invoked on the channel strand.
71-
virtual void send(rpc::response_t&& message, size_t size_hint,
72-
result_handler&& handler) NOEXCEPT;
73-
7474
protected:
7575
/// Stranded handler invoked from stop().
7676
void stopping(const code& ec) NOEXCEPT override;

include/bitcoin/network/net.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,10 @@ class BCT_API net
214214
friend class session;
215215

216216
/// I/O factories.
217-
virtual acceptor::ptr create_acceptor() NOEXCEPT;
218-
virtual connector::ptr create_connector(bool seed=false) NOEXCEPT;
217+
virtual acceptor::ptr create_acceptor(size_t maximum) NOEXCEPT;
219218
virtual connectors_ptr create_connectors(size_t count) NOEXCEPT;
219+
virtual connector::ptr create_connector(size_t maximum) NOEXCEPT;
220+
virtual connector::ptr create_connector() NOEXCEPT;
220221

221222
/// Sequences.
222223
virtual void do_start(const result_handler& handler) NOEXCEPT;

include/bitcoin/network/net/acceptor.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ class BCT_API acceptor
4747
// ------------------------------------------------------------------------
4848

4949
/// Construct an instance.
50-
acceptor(const logger& log, asio::strand& strand,
51-
asio::io_context& service, std::atomic_bool& suspended) NOEXCEPT;
50+
acceptor(const logger& log, asio::strand& strand, asio::io_context& service,
51+
size_t maximum_request, std::atomic_bool& suspended) NOEXCEPT;
5252

5353
/// Asserts/logs stopped.
5454
virtual ~acceptor() NOEXCEPT;
@@ -81,6 +81,7 @@ class BCT_API acceptor
8181
virtual code start(const asio::endpoint& point) NOEXCEPT;
8282

8383
// These are thread safe.
84+
const size_t maximum_;
8485
asio::io_context& service_;
8586
asio::strand& strand_;
8687
std::atomic_bool& suspended_;

include/bitcoin/network/net/connector.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class BCT_API connector
5252
/// Construct an instance.
5353
connector(const logger& log, asio::strand& strand,
5454
asio::io_context& service, const steady_clock::duration& timeout,
55-
std::atomic_bool& suspended) NOEXCEPT;
55+
size_t maximum_request, std::atomic_bool& suspended) NOEXCEPT;
5656

5757
/// Asserts/logs stopped.
5858
virtual ~connector() NOEXCEPT;
@@ -88,6 +88,7 @@ class BCT_API connector
8888
const config::address& host, socket_handler&& handler) NOEXCEPT;
8989

9090
// These are thread safe
91+
const size_t maximum_;
9192
asio::io_context& service_;
9293
asio::strand& strand_;
9394
std::atomic_bool& suspended_;

include/bitcoin/network/net/socket.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ class BCT_API socket
4444
DELETE_COPY_MOVE(socket);
4545

4646
/// Use only for incoming connections (defaults outgoing address).
47-
socket(const logger& log, asio::io_context& service) NOEXCEPT;
47+
socket(const logger& log, asio::io_context& service,
48+
size_t maximum_request) NOEXCEPT;
4849

4950
/// Use only for outgoing connections (retains outgoing address).
5051
socket(const logger& log, asio::io_context& service,
51-
const config::address& address) NOEXCEPT;
52+
size_t maximum_request, const config::address& address) NOEXCEPT;
5253

5354
/// Asserts/logs stopped.
5455
virtual ~socket() NOEXCEPT;
@@ -284,12 +285,12 @@ class BCT_API socket
284285

285286
protected:
286287
// These are thread safe.
288+
const size_t maximum_;
287289
asio::strand strand_;
288290
asio::io_context& service_;
289291
std::atomic_bool stopped_{};
290292

291293
// These are protected by strand (see also handle_accept).
292-
size_t maximum_;
293294
asio::socket socket_;
294295
config::address address_;
295296
config::authority authority_{};

include/bitcoin/network/sessions/session.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,13 @@ class BCT_API session
187187
/// -----------------------------------------------------------------------
188188

189189
/// Call to create channel acceptor.
190-
virtual acceptor::ptr create_acceptor() NOEXCEPT;
190+
virtual acceptor::ptr create_acceptor(size_t maximum) NOEXCEPT;
191191

192-
/// Call to create channel connector (option for seed connection timeout).
193-
virtual connector::ptr create_connector(bool seed=false) NOEXCEPT;
192+
/// Call to create channel connector for seed connections.
193+
virtual connector::ptr create_connector() NOEXCEPT;
194+
195+
/// Call to create channel connector for manual/outbound connections.
196+
virtual connector::ptr create_connector(size_t maximum) NOEXCEPT;
194197

195198
/// Call to create a set of channel connectors.
196199
virtual connectors_ptr create_connectors(size_t count) NOEXCEPT;

include/bitcoin/network/settings.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ struct BCT_API settings
238238

239239
/// Helpers.
240240
virtual bool witness_node() const NOEXCEPT;
241-
virtual size_t maximum_payload() const NOEXCEPT;
242241
virtual steady_clock::duration retry_timeout() const NOEXCEPT;
243242
virtual steady_clock::duration connect_timeout() const NOEXCEPT;
244243
virtual steady_clock::duration channel_handshake() const NOEXCEPT;

src/channels/channel_peer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ void channel_peer::handle_read_heading(const code& ec, size_t) NOEXCEPT
219219
return;
220220
}
221221

222-
if (head->payload_size > settings().maximum_payload())
222+
if (head->payload_size > options().maximum_request)
223223
{
224224
LOGR("Oversized payload indicated by " << head->command
225225
<< " heading from [" << authority() << "] ("

src/net.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,32 +68,41 @@ net::~net() NOEXCEPT
6868
// I/O factories.
6969
// ----------------------------------------------------------------------------
7070

71-
acceptor::ptr net::create_acceptor() NOEXCEPT
71+
// inbound/server
72+
acceptor::ptr net::create_acceptor(size_t maximum) NOEXCEPT
7273
{
73-
return emplace_shared<acceptor>(log, strand(), service(),
74+
return emplace_shared<acceptor>(log, strand(), service(), maximum,
7475
accept_suspended_);
7576
}
7677

77-
connector::ptr net::create_connector(bool seed) NOEXCEPT
78-
{
79-
const auto timeout = seed ? settings_.outbound.seeding_timeout() :
80-
settings_.connect_timeout();
81-
82-
return emplace_shared<connector>(log, strand(), service(), timeout,
83-
connect_suspended_);
84-
}
85-
78+
// outbound (batch)
8679
connectors_ptr net::create_connectors(size_t count) NOEXCEPT
8780
{
8881
const auto connects = to_shared<connectors>();
8982
connects->reserve(count);
9083

84+
const auto maximum = settings_.outbound.maximum_request;
9185
for (size_t connect{}; connect < count; ++connect)
92-
connects->push_back(create_connector());
86+
connects->push_back(create_connector(maximum));
9387

9488
return connects;
9589
}
9690

91+
// manual/outbound
92+
connector::ptr net::create_connector(size_t maximum) NOEXCEPT
93+
{
94+
return emplace_shared<connector>(log, strand(), service(),
95+
settings_.connect_timeout(), maximum, connect_suspended_);
96+
}
97+
98+
// seed
99+
connector::ptr net::create_connector() NOEXCEPT
100+
{
101+
return emplace_shared<connector>(log, strand(), service(),
102+
settings_.outbound.seeding_timeout(),
103+
settings_.outbound.maximum_request, connect_suspended_);
104+
}
105+
97106
// Start sequence.
98107
// ----------------------------------------------------------------------------
99108

src/net/acceptor.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ using namespace std::placeholders;
4343
// Calls are stranded to protect the acceptor member.
4444

4545
acceptor::acceptor(const logger& log, asio::strand& strand,
46-
asio::io_context& service, std::atomic_bool& suspended) NOEXCEPT
47-
: service_(service),
46+
asio::io_context& service, size_t maximum_request,
47+
std::atomic_bool& suspended) NOEXCEPT
48+
: maximum_(maximum_request),
49+
service_(service),
4850
strand_(strand),
4951
suspended_(suspended),
5052
acceptor_(strand_),
@@ -144,7 +146,8 @@ void acceptor::accept(socket_handler&& handler) NOEXCEPT
144146
}
145147

146148
// Create the socket.
147-
const auto socket = std::make_shared<network::socket>(log, service_);
149+
const auto socket = std::make_shared<network::socket>(log, service_,
150+
maximum_);
148151

149152
// Posts handle_accept to the acceptor's strand.
150153
// Establishes a socket connection by waiting on the socket.

0 commit comments

Comments
 (0)