-
Notifications
You must be signed in to change notification settings - Fork 795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Respond to keepalive messages within a TCP socket #1742
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2062,7 +2062,7 @@ receive_buffer (std::make_shared<std::vector<uint8_t>> ()), | |
socket (socket_a), | ||
node (node_a) | ||
{ | ||
receive_buffer->resize (128); | ||
receive_buffer->resize (512); | ||
} | ||
|
||
void nano::bootstrap_server::receive () | ||
|
@@ -2119,6 +2119,14 @@ void nano::bootstrap_server::receive_header_action (boost::system::error_code co | |
add_request (std::unique_ptr<nano::message> (new nano::bulk_push (header))); | ||
break; | ||
} | ||
case nano::message_type::keepalive: | ||
{ | ||
auto this_l (shared_from_this ()); | ||
socket->async_read (receive_buffer, header.payload_length_bytes (), [this_l, header](boost::system::error_code const & ec, size_t size_a) { | ||
this_l->receive_keepalive_action (ec, size_a, header); | ||
}); | ||
break; | ||
} | ||
default: | ||
{ | ||
if (node->config.logging.network_logging ()) | ||
|
@@ -2178,6 +2186,28 @@ void nano::bootstrap_server::receive_bulk_pull_account_action (boost::system::er | |
} | ||
} | ||
|
||
void nano::bootstrap_server::receive_keepalive_action (boost::system::error_code const & ec, size_t size_a, nano::message_header const & header_a) | ||
{ | ||
if (!ec) | ||
{ | ||
auto error (false); | ||
nano::bufferstream stream (receive_buffer->data (), header_a.payload_length_bytes ()); | ||
std::unique_ptr<nano::keepalive> request (new nano::keepalive (error, stream, header_a)); | ||
if (!error) | ||
{ | ||
add_request (std::unique_ptr<nano::message> (request.release ())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can't this just be: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, a lot of these need to be fixed to use c++13 semantics. |
||
receive (); | ||
} | ||
} | ||
else | ||
{ | ||
if (node->config.logging.network_keepalive_logging ()) | ||
{ | ||
BOOST_LOG (node->log) << boost::str (boost::format ("Error receiving keepalive from: %1%") % ec.message ()); | ||
} | ||
} | ||
} | ||
|
||
void nano::bootstrap_server::receive_frontier_req_action (boost::system::error_code const & ec, size_t size_a, nano::message_header const & header_a) | ||
{ | ||
if (!ec) | ||
|
@@ -2235,9 +2265,35 @@ class request_response_visitor : public nano::message_visitor | |
{ | ||
} | ||
virtual ~request_response_visitor () = default; | ||
void keepalive (nano::keepalive const &) override | ||
void keepalive (nano::keepalive const & message_a) override | ||
{ | ||
assert (false); | ||
if (connection->node->config.logging.network_keepalive_logging ()) | ||
{ | ||
BOOST_LOG (connection->node->log) << boost::str (boost::format ("Received keepalive message from %1%") % connection->socket->remote_endpoint ()); | ||
} | ||
connection->node->stats.inc (nano::stat::type::message, nano::stat::detail::keepalive, nano::stat::dir::in); | ||
connection->node->network.merge_peers (message_a.peers); | ||
nano::keepalive message; | ||
connection->node->peers.random_fill (message.peers); | ||
auto bytes = message.to_bytes (); | ||
if (connection->node->config.logging.network_keepalive_logging ()) | ||
{ | ||
BOOST_LOG (connection->node->log) << boost::str (boost::format ("Keepalive req sent to %1%") % connection->socket->remote_endpoint ()); | ||
} | ||
connection->socket->async_write (bytes, [connection = connection](boost::system::error_code const & ec, size_t size_a) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. connection = connection (?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. connection is a member variable, so if you want to pass it in without passing |
||
if (ec) | ||
{ | ||
if (connection->node->config.logging.network_keepalive_logging ()) | ||
{ | ||
BOOST_LOG (connection->node->log) << boost::str (boost::format ("Error sending keepalive to %1%: %2%") % connection->socket->remote_endpoint () % ec.message ()); | ||
} | ||
} | ||
else | ||
{ | ||
connection->node->stats.inc (nano::stat::type::message, nano::stat::detail::keepalive, nano::stat::dir::out); | ||
connection->finish_request (); | ||
} | ||
}); | ||
} | ||
void publish (nano::publish const &) override | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should be atomic ?