diff options
Diffstat (limited to 'node/nextnode.cpp')
| -rw-r--r-- | node/nextnode.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/node/nextnode.cpp b/node/nextnode.cpp index 3045462..d38200d 100644 --- a/node/nextnode.cpp +++ b/node/nextnode.cpp @@ -1,7 +1,34 @@ #include "nextnode.hpp" +#include "connect.hpp" + +#include "logging.hpp" + using namespace boost::asio::ip; NextNode::NextNode(tcp::socket&& 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); +} + +void NextNode::connect(std::string next_host, std::string next_port, std::function<void ()> on_connect) +{ + async_connect(socket, next_host, next_port, on_connect); +} + +void NextNode::close() +{ + socket.close(); +} |
