diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2016-09-28 10:55:58 +0200 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2016-09-28 10:55:58 +0200 |
| commit | 85d25eebd38bb278ad598a291a007938854945a4 (patch) | |
| tree | b6f26a8f5a301c9a18d7ab6de5805de7d660cade /node/node.cpp | |
| parent | fa0b4963e977c59586b41e146ea13f44bda714ab (diff) | |
| download | cmix-85d25eebd38bb278ad598a291a007938854945a4.tar.gz cmix-85d25eebd38bb278ad598a291a007938854945a4.tar.bz2 cmix-85d25eebd38bb278ad598a291a007938854945a4.zip | |
Made changes so we can have a 1 Node cmix network.
Diffstat (limited to 'node/node.cpp')
| -rw-r--r-- | node/node.cpp | 52 |
1 files changed, 46 insertions, 6 deletions
diff --git a/node/node.cpp b/node/node.cpp index 4b4bc2b..b33f8a5 100644 --- a/node/node.cpp +++ b/node/node.cpp @@ -1,17 +1,31 @@ #include "node.hpp" -#include "connect.hpp" + +#include "logging.hpp" + +using namespace boost::asio::ip; Node::Node(ListenSettings const& listen_settings, NodeNetworkSettings network_settings) : io_service() , server(io_service, listen_settings, [this](boost::asio::ip::tcp::socket&& socket){accept_handler(std::move(socket));}) , clients() -, next_node(connect(network_settings.next_host, network_settings.next_port, io_service)) +, network_settings(network_settings) +, next_node(tcp::socket(io_service)) , api(get_curve25519_implementation()) , keypair(api.create_key_pair()) +, network_pub_key() { - if(network_settings.is_first) { - start_initialisation(); - } + auto on_connect = [this, network_settings](){ + BOOST_LOG_TRIVIAL(trace) << "is first: " << std::boolalpha << network_settings.is_first; + if(network_settings.is_first) { + start_initialisation(); + } + }; + + next_node.connect(network_settings.next_host, network_settings.next_port, on_connect); +} + +Node::~Node() { + api.free_key_pair(keypair); } void Node::accept_handler(boost::asio::ip::tcp::socket&& socket) @@ -24,6 +38,32 @@ void Node::accept_handler(boost::asio::ip::tcp::socket&& socket) clients.erase(it); } ); +} + +void Node::start_initialisation() { + initialization init; + init.set_public_share(keypair.pub, keypair.pub_len); + + BOOST_LOG_TRIVIAL(trace) << "length of keypair.pub: " << keypair.pub_len; + + std::string message; + init.SerializeToString(&message); + BOOST_LOG_TRIVIAL(trace) << init.DebugString(); + next_node.send(message); + + auto f = [this](std::vector<uint8_t> bytes) { + network_pub_key = bytes; + + if(network_settings.is_first) { + start_precomputation(); + } + }; + + BOOST_LOG_TRIVIAL(trace) << "number of clients: " << clients.size(); + for(auto&& client : clients) { + client.receive(f); + } +} - clients.back().receive(); +void Node::start_precomputation() { } |
