change the configuration to handle the new ZMQ-REQ-REP-protocol and the RestAPI-Update protocol

This commit is contained in:
Sven Czarnian
2021-11-21 08:53:58 +01:00
parent 0acb45dd27
commit b309e86ec6
4 changed files with 27 additions and 10 deletions

View File

@@ -17,9 +17,10 @@ namespace aman {
*/ */
struct Communication { struct Communication {
bool valid; /**< Marks if the configuration is valid */ bool valid; /**< Marks if the configuration is valid */
bool httpsProtocol; /**< Marks if the server uses HTTPS */
std::string address; /**< The address of the backend */ std::string address; /**< The address of the backend */
std::uint16_t portReporter; /**< The reported port of the backend */ std::uint16_t portBackend; /**< The reported port of the backend */
std::uint16_t portNotification; /**< The notification port of the backend */ std::uint16_t portRestAPI; /**< The notification port of the backend */
std::string serverPublicIdentifier; /**< The server's public identifier */ std::string serverPublicIdentifier; /**< The server's public identifier */
std::string clientPublicIdentifier; /**< The client's public identifier */ std::string clientPublicIdentifier; /**< The client's public identifier */
std::string clientPrivateIdentifier; /**< The client's private identifier */ std::string clientPrivateIdentifier; /**< The client's private identifier */
@@ -29,9 +30,10 @@ namespace aman {
*/ */
Communication() : Communication() :
valid(false), valid(false),
httpsProtocol(false),
address(), address(),
portReporter(0), portBackend(0),
portNotification(0), portRestAPI(0),
serverPublicIdentifier(), serverPublicIdentifier(),
clientPublicIdentifier(), clientPublicIdentifier(),
clientPrivateIdentifier() { } clientPrivateIdentifier() { }

View File

@@ -95,7 +95,19 @@ PlugIn::~PlugIn() noexcept {
} }
void PlugIn::validateBackendData() { void PlugIn::validateBackendData() {
std::string url = "http://" + this->m_configuration.address + ":5000/aman/airports"; if (false == this->m_configuration.valid) {
this->m_compatible = false;
return;
}
/* set up the URL */
std::string url;
if (true == this->m_configuration.httpsProtocol)
url += "https://";
else
url += "http://";
url += this->m_configuration.address + ":" + std::to_string(this->m_configuration.portRestAPI) + "/aman/airports";
CURL* curl = curl_easy_init(); CURL* curl = curl_easy_init();
CURLcode result; CURLcode result;

View File

@@ -37,7 +37,7 @@ bool Backend::initialize(const Communication& configuration) {
/* connect to the server */ /* connect to the server */
try { try {
this->m_socket->connect("tcp://" + configuration.address + ":" + std::to_string(configuration.portReporter)); this->m_socket->connect("tcp://" + configuration.address + ":" + std::to_string(configuration.portBackend));
} }
catch (zmq::error_t&) { catch (zmq::error_t&) {
this->m_socket = std::unique_ptr<zmq::socket_t>(); this->m_socket = std::unique_ptr<zmq::socket_t>();

View File

@@ -75,11 +75,14 @@ bool CommunicationFileFormat::parse(const std::string& filename, Communication&
if ("Address" == gsl::at(entry, 0)) { if ("Address" == gsl::at(entry, 0)) {
config.address = gsl::at(entry, 1); config.address = gsl::at(entry, 1);
} }
else if ("PortReporter" == gsl::at(entry, 0)) { else if ("HttpsProtocol" == gsl::at(entry, 0)) {
config.portReporter = static_cast<std::uint16_t>(std::atoi(gsl::at(entry, 1).c_str())); config.httpsProtocol = "0" != gsl::at(entry, 1);
} }
else if ("PortNotification" == gsl::at(entry, 0)) { else if ("PortBackend" == gsl::at(entry, 0)) {
config.portNotification = static_cast<std::uint16_t>(std::atoi(gsl::at(entry, 1).c_str())); config.portBackend = static_cast<std::uint16_t>(std::atoi(gsl::at(entry, 1).c_str()));
}
else if ("PortRestAPI" == gsl::at(entry, 0)) {
config.portRestAPI = static_cast<std::uint16_t>(std::atoi(gsl::at(entry, 1).c_str()));
} }
else { else {
this->m_errorLine = lineOffset; this->m_errorLine = lineOffset;