diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2016-10-10 15:52:14 +0200 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2016-10-10 15:52:14 +0200 |
| commit | d8e48c32f8435076382543edfafbf81c223f9e87 (patch) | |
| tree | 575f0f7f452c4c8800e77c7fd79b4354fed8a81c /client/cmixclient.cpp | |
| parent | fa35c9c3c71243a7f8537e5a81f7a09fa05a382e (diff) | |
| download | cmix-d8e48c32f8435076382543edfafbf81c223f9e87.tar.gz cmix-d8e48c32f8435076382543edfafbf81c223f9e87.tar.bz2 cmix-d8e48c32f8435076382543edfafbf81c223f9e87.zip | |
Added a Client so we can start finishing up the setup phase of cMix.
Diffstat (limited to 'client/cmixclient.cpp')
| -rw-r--r-- | client/cmixclient.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/client/cmixclient.cpp b/client/cmixclient.cpp new file mode 100644 index 0000000..e3f5ac4 --- /dev/null +++ b/client/cmixclient.cpp @@ -0,0 +1,42 @@ + +#include "cmixclient.hpp" + +void CMixClient::initialized() { + BOOST_LOG_TRIVIAL(trace) << "Client connections were made"; + for(auto&& connection : network_connections) { + cmix_proto::Bye bye; + connection.send(bye); + } + io_service.stop(); +} + +void CMixClient::initialize_connections() { + network_connections.reserve(network_details.size()); + + int i = network_details.size(); + auto handler = [this, i]() mutable { + cmix_proto::ImAClient imaclient; + network_connections.at(network_details.size() - i).send(imaclient); + + if(--i == 0) { + initialized(); + } + }; + + for(auto&& details : network_details) { + network_connections.emplace_back(boost::asio::ip::tcp::socket(io_service)); + network_connections.back().async_connect(details.host, details.port, handler); + } +} + +CMixClient::CMixClient(std::vector<NodeDetails> details) +: io_service() +, network_details(details) +, network_connections() +{ + initialize_connections(); +} + +void CMixClient::run() { + io_service.run(); +} |
