Skip to content

Commit 9d21a7f

Browse files
authored
Merge pull request #746 from evoskuil/master
Restore implementation of send proxy logging.
2 parents 26eaca4 + 434553a commit 9d21a7f

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

include/bitcoin/network/channels/channel_peer.hpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,26 @@ class BCT_API channel_peer
5858
inline void send(const Message& message, result_handler&& handler) NOEXCEPT
5959
{
6060
BC_ASSERT(stranded());
61+
using namespace messages::peer;
6162

6263
// TODO: move to serializer.
6364
const auto magic = settings().identifier;
6465
const auto version = negotiated_version();
65-
const auto ptr = messages::peer::serialize(message, magic, version);
66+
const auto payload = serialize(message, magic, version);
67+
68+
LOGX("Sent " << heading::get_command(*payload) << " to ["
69+
<< endpoint() << "] (" << system::floored_subtract(payload->size(),
70+
heading::command_size) << " bytes)");
6671

6772
using namespace std::placeholders;
6873
count_handler complete = std::bind(&channel_peer::handle_send,
69-
shared_from_base<channel_peer>(), _1, _2, ptr, std::move(handler));
74+
shared_from_base<channel_peer>(), _1, _2, payload,
75+
std::move(handler));
7076

71-
if (!ptr)
77+
if (!payload)
7278
complete(error::bad_alloc, {});
7379
else
74-
write({ ptr->data(), ptr->size() }, std::move(complete));
80+
write({ payload->data(), payload->size() }, std::move(complete));
7581
}
7682

7783
/// Construct a p2p channel to encapsulate and communicate on the socket.
@@ -138,7 +144,8 @@ class BCT_API channel_peer
138144

139145
private:
140146
void log_message(const std::string_view& name, size_t size) const NOEXCEPT;
141-
void handle_send(const code& ec, size_t size, const system::chunk_cptr&,
147+
void handle_send(const code& ec, size_t size,
148+
const system::chunk_cptr& payload,
142149
const result_handler& handler) NOEXCEPT;
143150

144151
// Only passes static member get_area(), so safe to use statically.

src/channels/channel_peer.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,21 @@ void channel_peer::handle_read_payload(const code& ec, size_t payload_size,
317317
}
318318

319319
void channel_peer::handle_send(const code& ec, size_t,
320-
const system::chunk_cptr&, const result_handler& handler) NOEXCEPT
320+
const system::chunk_cptr& payload, const result_handler& handler) NOEXCEPT
321321
{
322322
if (ec)
323323
stop(ec);
324324

325+
if (ec &&
326+
ec != error::peer_disconnect &&
327+
ec != error::operation_canceled &&
328+
ec != error::connect_failed)
329+
{
330+
LOGF("Send failure " << heading::get_command(*payload) << " to ["
331+
<< endpoint() << "] (" << system::floored_subtract(payload->size(),
332+
heading::command_size) << " bytes) " << ec.message());
333+
}
334+
325335
handler(ec);
326336
}
327337

src/net/proxy.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ void proxy::do_write(const asio::const_buffer& payload,
283283
total_ = ceilinged_add(total_.load(), payload.size());
284284
backlog_ = ceilinged_add(backlog_.load(), payload.size());
285285

286-
LOGX("Queue for [" << endpoint() << "]: " << queue_.size()
286+
LOGV("Queue for [" << endpoint() << "]: " << queue_.size()
287287
<< " (" << backlog_.load() << " of " << total_.load() << " bytes)");
288288

289289
// Start the loop if it wasn't already started.
@@ -322,7 +322,7 @@ void proxy::handle_write(const code& ec, size_t bytes,
322322
backlog_ = floored_subtract(backlog_.load(), queue_.front().first.size());
323323
queue_.pop_front();
324324

325-
LOGX("Dequeue for [" << endpoint() << "]: " << queue_.size()
325+
LOGV("Dequeue for [" << endpoint() << "]: " << queue_.size()
326326
<< " (" << backlog_.load() << " backlog)");
327327

328328
// All handlers must be invoked, so continue regardless of error state.
@@ -346,11 +346,6 @@ void proxy::handle_write(const code& ec, size_t bytes,
346346
return;
347347
}
348348

349-
// BUGBUG: payload changed from data_chunk_ptr to const_buffer.
350-
// TODO: messages dependency, move to channel.
351-
////LOGX("Sent " << heading::get_command(*payload) << " to ["
352-
//// << endpoint() << "] (" << payload->size() << " bytes)");
353-
354349
handler(ec, bytes);
355350
}
356351

0 commit comments

Comments
 (0)