aboutsummaryrefslogtreecommitdiff
path: root/client/cmixclient.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'client/cmixclient.cpp')
-rw-r--r--client/cmixclient.cpp17
1 files changed, 11 insertions, 6 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;