Leosac  0.8.0
Open Source Access Control
GetRemoteConfigVersion.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
21 #include "core/kernel.hpp"
22 #include "tools/log.hpp"
23 #include <zmqpp/curve.hpp>
24 
25 using namespace Leosac;
26 
28  const std::string &pubkey)
29  : config_version_(0)
30  , endpoint_(endpoint)
31  , pubkey_(pubkey)
32 {
33  INFO("Creating GetRemoteConfigVersion task. Guid = " << get_guid());
34 }
35 
37 {
38  zmqpp::context ctx;
39  zmqpp::socket sock(ctx, zmqpp::socket_type::dealer);
40  auto kp = zmqpp::curve::generate_keypair();
41 
42  sock.set(zmqpp::socket_option::curve_secret_key, kp.secret_key);
43  sock.set(zmqpp::socket_option::curve_public_key, kp.public_key);
44  sock.set(zmqpp::socket_option::curve_server_key, pubkey_);
45  sock.set(zmqpp::socket_option::linger, 0);
46  sock.connect(endpoint_);
47 
48  sock.send("CONFIG_VERSION");
49 
50  zmqpp::message response;
51  zmqpp::poller p;
52  p.add(sock);
53 
54  p.poll(timeout);
55  if (p.has_input(sock))
56  {
57  sock.receive(response);
58  response >> config_version_;
59  INFO("Remote configuration version = " << config_version_);
60  return true;
61  }
62  ERROR("Failed to receive response from remote server in due time");
63  return false;
64 }
ERROR
@ ERROR
Definition: log.hpp:32
INFO
@ INFO
Definition: log.hpp:34
GetRemoteConfigVersion.hpp
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
kernel.hpp
Leosac::Tasks::GetRemoteConfigVersion::do_run
virtual bool do_run() override
Definition: GetRemoteConfigVersion.cpp:36
Leosac::Tasks::GetRemoteConfigVersion::GetRemoteConfigVersion
GetRemoteConfigVersion(const std::string &endpoint, const std::string &pubkey)
Definition: GetRemoteConfigVersion.cpp:27
log.hpp
Leosac::Tasks::Task::get_guid
const std::string & get_guid() const
Definition: Task.cpp:98