diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2016-09-29 17:23:22 +0200 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2016-09-29 17:23:22 +0200 |
| commit | 37effc3e136c73afd4d6ba37d23a91766795d0f7 (patch) | |
| tree | e5a1684231df52f48088dd053d57132d390e5a02 /node/nextnode.cpp | |
| parent | f7f0e8c53bc8231264346ef91e2f533164a25562 (diff) | |
| download | cmix-37effc3e136c73afd4d6ba37d23a91766795d0f7.tar.gz cmix-37effc3e136c73afd4d6ba37d23a91766795d0f7.tar.bz2 cmix-37effc3e136c73afd4d6ba37d23a91766795d0f7.zip | |
This changset triggered a storm of changes.
Added the behaviour for receiving a public_share message from our
previous node when not being the first node ourselves. This
triggered the whitespace bug below, which sparked the network
rewrite.
Rewrote network protocol to first send the size of the message it's
sending in a 32bit integer in network byte order.
Fixed a bug where whitespace in the received buffer would be skipped.
leading to broken protobuf messages.
NextNode no longers inherits from client but owns one, and some
functions needed to be forwarded.
Diffstat (limited to 'node/nextnode.cpp')
| -rw-r--r-- | node/nextnode.cpp | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/node/nextnode.cpp b/node/nextnode.cpp index d38200d..f6c4454 100644 --- a/node/nextnode.cpp +++ b/node/nextnode.cpp @@ -1,34 +1,24 @@ #include "nextnode.hpp" -#include "connect.hpp" - #include "logging.hpp" using namespace boost::asio::ip; NextNode::NextNode(tcp::socket&& socket) -: Client(std::move(socket)) +: client(std::move(socket)) {} void NextNode::send(std::string message) { - auto handler = [](boost::system::error_code const& ec, std::size_t bytes_transferred) { - BOOST_LOG_TRIVIAL(trace) << "sent message"; - if(ec) { - BOOST_LOG_TRIVIAL(fatal) << ec; - throw std::runtime_error("unable to send message"); - } - }; - - socket.async_send(boost::asio::buffer(message), 0, handler); + client.send(message); } -void NextNode::connect(std::string next_host, std::string next_port, std::function<void ()> on_connect) +void NextNode::async_connect(std::string next_host, std::string next_port, std::function<void ()> on_connect) { - async_connect(socket, next_host, next_port, on_connect); + client.async_connect(next_host, next_port, on_connect); } void NextNode::close() { - socket.close(); + client.close(); } |
