aboutsummaryrefslogtreecommitdiff
path: root/node
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
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')
-rw-r--r--node/main.cpp9
-rw-r--r--node/node.cpp42
-rw-r--r--node/node.hpp1
3 files changed, 36 insertions, 16 deletions
diff --git a/node/main.cpp b/node/main.cpp
index 7425f00..527e3c5 100644
--- a/node/main.cpp
+++ b/node/main.cpp
@@ -10,10 +10,6 @@
int main(int argc, char* argv[]) {
namespace po = boost::program_options;
- init_logging(boost::log::trivial::severity_level::trace, "node");
-
- BOOST_LOG_TRIVIAL(info) << "Started node";
-
po::options_description desc("Allowed options");
desc.add_options()
("help,h", "produce help message.")
@@ -41,6 +37,11 @@ int main(int argc, char* argv[]) {
std::string if6 = vm["interface6"].as<std::string>();
uint16_t port = vm["port"].as<uint16_t>();
+ init_logging(boost::log::trivial::severity_level::trace, "node_" + std::to_string(port));
+
+ BOOST_LOG_TRIVIAL(info) << "Started node";
+
+
ListenSettings lsettings{en4, if4, en6, if6, port};
bool is_first = bool(vm.count("first"));
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() {
-
}
diff --git a/node/node.hpp b/node/node.hpp
index fa0cb37..44e379f 100644
--- a/node/node.hpp
+++ b/node/node.hpp
@@ -6,7 +6,6 @@
#include "nextnode.hpp"
#include "api.h"
-#include "curve25519.h"
#include "cmix.pb.h"