aboutsummaryrefslogtreecommitdiff
path: root/node/node.cpp
diff options
context:
space:
mode:
authorDennis Brentjes <d.brentjes@gmail.com>2016-09-29 17:23:22 +0200
committerDennis Brentjes <d.brentjes@gmail.com>2016-09-29 17:23:22 +0200
commit37effc3e136c73afd4d6ba37d23a91766795d0f7 (patch)
treee5a1684231df52f48088dd053d57132d390e5a02 /node/node.cpp
parentf7f0e8c53bc8231264346ef91e2f533164a25562 (diff)
downloadcmix-37effc3e136c73afd4d6ba37d23a91766795d0f7.tar.gz
cmix-37effc3e136c73afd4d6ba37d23a91766795d0f7.tar.bz2
cmix-37effc3e136c73afd4d6ba37d23a91766795d0f7.zip
This changset triggered a storm of changes.
Added the behaviour for receiving a public_share message from our previous node when not being the first node ourselves. This triggered the whitespace bug below, which sparked the network rewrite. Rewrote network protocol to first send the size of the message it's sending in a 32bit integer in network byte order. Fixed a bug where whitespace in the received buffer would be skipped. leading to broken protobuf messages. NextNode no longers inherits from client but owns one, and some functions needed to be forwarded.
Diffstat (limited to 'node/node.cpp')
-rw-r--r--node/node.cpp56
1 files changed, 51 insertions, 5 deletions
diff --git a/node/node.cpp b/node/node.cpp
index 045eb13..92c51ec 100644
--- a/node/node.cpp
+++ b/node/node.cpp
@@ -2,6 +2,10 @@
#include "logging.hpp"
+#include "gmpxx.h"
+
+#include <iostream>
+
using namespace boost::asio::ip;
Node::Node(ListenSettings const& listen_settings, NodeNetworkSettings network_settings)
@@ -21,7 +25,7 @@ Node::Node(ListenSettings const& listen_settings, NodeNetworkSettings network_se
}
};
- next_node.connect(network_settings.next_host, network_settings.next_port, on_connect);
+ next_node.async_connect(network_settings.next_host, network_settings.next_port, on_connect);
}
Node::~Node() {
@@ -52,18 +56,60 @@ void Node::start_initialisation() {
std::string message;
init.SerializeToString(&message);
- BOOST_LOG_TRIVIAL(trace) << init.DebugString();
+ BOOST_LOG_TRIVIAL(trace) << "init: " << init.DebugString();
+ BOOST_LOG_TRIVIAL(trace) << "size: " << message.size();
+ BOOST_LOG_TRIVIAL(trace) << "raw: " << message;
next_node.send(message);
auto f = [this](std::vector<uint8_t> bytes) {
- network_pub_key = bytes;
-
if(network_settings.is_first) {
+ BOOST_LOG_TRIVIAL(trace) << "bytes.size(): " << bytes.size();
+ BOOST_LOG_TRIVIAL(trace) << "raw2: " << std::string(bytes.begin(), bytes.end());
+ initialization init;
+ init.ParseFromArray(bytes.data(), bytes.size());
+ std::string share = init.public_share();
+
+ network_pub_key = std::vector<uint8_t>(share.begin(), share.end());
+
+ BOOST_LOG_TRIVIAL(trace) << "The network pub_key: " << init.DebugString();
+
start_precomputation();
+ } else {
+ mpz_t shared;
+ mpz_init(shared);
+ mpz_import(shared, bytes.size(), -1, 1, 0, 0, bytes.data());
+
+ mpz_t my_share;
+ mpz_init(my_share);
+ mpz_import(my_share, keypair.pub_len, -1, 1, 0, 0, keypair.pub);
+
+ mpz_mul(shared, shared, my_share);
+
+ mpz_t mod;
+ mpz_init(mod);
+ mpz_set_ui(mod, 2);
+ mpz_pow_ui(mod, mod, 255);
+ mpz_sub_ui(mod, mod, 19);
+
+ mpz_mod(shared, shared, mod);
+
+ std::vector<uint8_t> new_shared(keypair.pub_len, '\0');
+ size_t size;
+ mpz_export(new_shared.data(), &size, -1, 1, 0, 0, shared);
+
+ initialization init;
+ init.set_public_share(new_shared.data(), new_shared.size());
+
+ std::string message;
+ init.SerializeToString(&message);
+ next_node.send(message);
+
+ mpz_clear(shared);
+ mpz_clear(my_share);
+ mpz_clear(mod);
}
};
- BOOST_LOG_TRIVIAL(trace) << "number of clients: " << clients.size();
for(auto&& client : clients) {
client.receive(f);
}