aboutsummaryrefslogtreecommitdiff
path: root/node/node.cpp
diff options
context:
space:
mode:
authorDennis Brentjes <d.brentjes@gmail.com>2016-10-11 12:39:05 +0200
committerDennis Brentjes <d.brentjes@gmail.com>2016-10-11 12:39:05 +0200
commit0fb433690c0ca5f9561fe9e2e973e2cd61b873ba (patch)
tree9422a034b09d1e0b46144f35a1f9bcf7860156d6 /node/node.cpp
parentd8e48c32f8435076382543edfafbf81c223f9e87 (diff)
downloadcmix-0fb433690c0ca5f9561fe9e2e973e2cd61b873ba.tar.gz
cmix-0fb433690c0ca5f9561fe9e2e973e2cd61b873ba.tar.bz2
cmix-0fb433690c0ca5f9561fe9e2e973e2cd61b873ba.zip
Commit introducing Client keyexchange, triggering bugs.
Clients now send their public key to each node and the node calculates the shared secret. The node does not yet respond with it's public key. To keep this commit smaller. Nodes now disconnect from each other in a better way. Getting the relevant crypto api is now done with a generic function. What crypto algorithm and implemenation is beign used can be selected in the cmake cache (use cmake-gui or ccmake) Clients now connect correctly to multiple nodes.
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() {
-
}