aboutsummaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/cmixclient.cpp17
-rw-r--r--client/cmixclient.hpp6
2 files changed, 16 insertions, 7 deletions
diff --git a/client/cmixclient.cpp b/client/cmixclient.cpp
index 06994bf..5c94750 100644
--- a/client/cmixclient.cpp
+++ b/client/cmixclient.cpp
@@ -3,19 +3,19 @@
void CMixClient::key_exchange(int i) {
BOOST_LOG_TRIVIAL(trace) << "Sending KeyExchange for node: " << i;
- shared_keys.resize(network_details.size());
cmix_proto::KeyExchange ke;
ke.set_public_key(keypair.pub, keypair.pub_len);
- network_connections[i].async_send(ke);
-
- cmix_proto::Bye bye;
- network_connections[i].async_send(bye);
+ network_connections.at(i).async_send(ke);
+ network_connections.at(i).async_receive([i, this](cmix_proto::CMixMessage message) {
+ handle_message(i, message);
+ });
}
void CMixClient::initialize_connections() {
network_connections.reserve(network_details.size());
+ data.resize(network_details.size());
for(int i = 0; i < network_details.size(); ++i) {
auto handler = [this, i]() mutable {
@@ -34,17 +34,22 @@ void CMixClient::initialize_connections() {
void CMixClient::handle_key_exchange(int node_id, cmix_proto::KeyExchange const& ke)
{
- shared_keys[node_id] = api.derive_shared_key(keypair, reinterpret_cast<uint8_t const*>(ke.public_key().c_str()), false);
+ data.at(node_id).shared_value = api.derive_shared_key(keypair, reinterpret_cast<uint8_t const*>(ke.public_key().c_str()), false);
+
+ cmix_proto::Bye bye;
+ network_connections.at(node_id).async_send(bye);
}
void CMixClient::handle_message(int node_id, cmix_proto::CMixMessage message)
{
switch(message.contents_case()) {
case cmix_proto::CMixMessage::ContentsCase::kKeyexchange: {
+ BOOST_LOG_TRIVIAL(trace) << "handling keyexchange";
handle_key_exchange(node_id, *message.mutable_keyexchange());
return;
}
case cmix_proto::CMixMessage::ContentsCase::kBye: {
+ BOOST_LOG_TRIVIAL(trace) << "handling bye";
network_connections.at(node_id).close();
if(std::all_of(network_connections.begin(), network_connections.end(), [](SenderReceiver const& c) { return c.is_open(); })) {
break;
diff --git a/client/cmixclient.hpp b/client/cmixclient.hpp
index 71be7c9..1edb08e 100644
--- a/client/cmixclient.hpp
+++ b/client/cmixclient.hpp
@@ -18,14 +18,18 @@ struct NodeDetails {
class CMixClient {
+ struct NodeData {
+ SharedKey shared_value;
+ };
+
boost::asio::io_service io_service;
std::vector<NodeDetails> network_details;
std::vector<SenderReceiver> network_connections;
+ std::vector<NodeData> data;
Api api;
KeyPair keypair;
- std::vector<SharedKey> shared_keys;
void key_exchange(int i);