Browse Source

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

Sven Czarnian 3 years ago
parent
commit
b309e86ec6
4 changed files with 27 additions and 10 deletions
  1. 6 4
      include/aman/types/Communication.h
  2. 13 1
      src/PlugIn.cpp
  3. 1 1
      src/com/Backend.cpp
  4. 7 4
      src/config/CommunicationFileFormat.cpp

+ 6 - 4
include/aman/types/Communication.h

@@ -17,9 +17,10 @@ namespace aman {
      */
     struct Communication {
         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::uint16_t portReporter;            /**< The reported port of the backend */
-        std::uint16_t portNotification;        /**< The notification port of the backend */
+        std::uint16_t portBackend;             /**< The reported port of the backend */
+        std::uint16_t portRestAPI;             /**< The notification port of the backend */
         std::string   serverPublicIdentifier;  /**< The server's public identifier */
         std::string   clientPublicIdentifier;  /**< The client's public identifier */
         std::string   clientPrivateIdentifier; /**< The client's private identifier */
@@ -29,9 +30,10 @@ namespace aman {
          */
         Communication() :
                 valid(false),
+                httpsProtocol(false),
                 address(),
-                portReporter(0),
-                portNotification(0),
+                portBackend(0),
+                portRestAPI(0),
                 serverPublicIdentifier(),
                 clientPublicIdentifier(),
                 clientPrivateIdentifier() { }

+ 13 - 1
src/PlugIn.cpp

@@ -95,7 +95,19 @@ PlugIn::~PlugIn() noexcept {
 }
 
 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();
     CURLcode result;
 

+ 1 - 1
src/com/Backend.cpp

@@ -37,7 +37,7 @@ bool Backend::initialize(const Communication& configuration) {
 
     /* connect to the server */
     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&) {
         this->m_socket = std::unique_ptr<zmq::socket_t>();

+ 7 - 4
src/config/CommunicationFileFormat.cpp

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