aboutsummaryrefslogtreecommitdiff
path: root/node/node.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'node/node.cpp')
-rw-r--r--node/node.cpp42
1 files changed, 31 insertions, 11 deletions
diff --git a/node/node.cpp b/node/node.cpp
index 1fe0b44..db18253 100644
--- a/node/node.cpp
+++ b/node/node.cpp
@@ -15,7 +15,7 @@ Node::Node(ListenSettings const& listen_settings, NodeNetworkSettings network_se
, network_settings(network_settings)
, prev_node(Client(tcp::socket(io_service)))
, next_node(tcp::socket(io_service))
-, api(get_curve25519_implementation())
+, api(get_implementation())
, keypair(api.create_key_pair())
, network_pub_key()
{
@@ -100,11 +100,6 @@ void Node::handle_initialization(const cmix_proto::Initialization& init)
free_bignum(&shared);
free_bignum(&mod);
free_bignum(&new_shared);
-
- io_service.post([this]{
- clients.clear();
- io_service.stop();
- });
}
}
@@ -116,28 +111,54 @@ void Node::handle_node_message(const std::vector<uint8_t>& message_buffer)
handle_initialization(message.initialization());
break;
}
+ case cmix_proto::CMixMessage::ContentsCase::kBye: {
+ prev_node.close();
+ return;
+ }
default: {
- BOOST_LOG_TRIVIAL(error) << "CMixMessage contains unknown contents.";
+ BOOST_LOG_TRIVIAL(error) << "handle_node_message: CMixMessage contains unknown contents.";
}
}
+ prev_node.receive([this](std::vector<uint8_t> const& buffer) {
+ handle_node_message(buffer);
+ });
}
void Node::handle_client_message(std::list<Client>::iterator handle, const std::vector<uint8_t>& message_buffer)
{
cmix_proto::CMixMessage message = parse_cmix_message(message_buffer);
+ BOOST_LOG_TRIVIAL(trace) << "case: " << message.contents_case();
switch(message.contents_case()) {
+ case cmix_proto::CMixMessage::ContentsCase::kKeyexchange: {
+ BOOST_LOG_TRIVIAL(trace) << "Deriving shared key";
+ api.derive_shared_key(keypair, reinterpret_cast<uint8_t const*>(message.keyexchange().public_key().c_str()), true);
+
+ handle->receive([this, handle](std::vector<uint8_t> const& buffer){
+ handle_client_message(handle, buffer);
+ });
+ return;
+ }
case cmix_proto::CMixMessage::ContentsCase::kBye: {
+ BOOST_LOG_TRIVIAL(trace) << "Handling bye";
+
handle->close();
clients.erase(handle);
if(clients.size() == 0) {
- io_service.stop();
+ cmix_proto::Bye bye;
+ next_node.send(bye);
+
+ io_service.post([this]{
+ BOOST_LOG_TRIVIAL(trace) << "Shutting down";
+ io_service.stop();
+ });
+
}
return;
}
default: {
- BOOST_LOG_TRIVIAL(error) << "CMixMessage contains unknown contents.";
+ BOOST_LOG_TRIVIAL(error) << "handle_client_message: CMixMessage contains unknown contents.";
}
}
handle->close();
@@ -184,7 +205,7 @@ void Node::handle_message(std::list<Client>::iterator handle, const std::vector<
return;
}
default: {
- BOOST_LOG_TRIVIAL(error) << "CMixMessage contains unknown contents.";
+ BOOST_LOG_TRIVIAL(error) << "handle_message: CMixMessage contains unknown contents.";
}
}
@@ -192,5 +213,4 @@ void Node::handle_message(std::list<Client>::iterator handle, const std::vector<
}
void Node::start_precomputation() {
-
}