]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3106] Convenience functions in HAService
authorMarcin Siodelski <marcin@isc.org>
Wed, 29 Nov 2023 11:29:06 +0000 (12:29 +0100)
committerMarcin Siodelski <marcin@isc.org>
Wed, 29 Nov 2023 19:58:56 +0000 (20:58 +0100)
src/hooks/dhcp/high_availability/ha_impl.h
src/hooks/dhcp/high_availability/ha_service.cc
src/hooks/dhcp/high_availability/ha_service.h

index 7045b7d61b459791f919ec67c25889b19610d0c7..9b26f9dfa2aca379646fd4089c3ba5b3d3bc29dd 100644 (file)
@@ -57,8 +57,6 @@ public:
     /// @brief Destructor.
     ~HAImpl();
 
-public:
-
     /// @brief Returns a configuration for the first relationship.
     ///
     /// This function is held here for historical reasons and it is currently
index 4c570931d5baa28348b5dae2465e5fc87f91ed89..013ea7a2ebbb68e29caad8b839fda5c25ec70209 100644 (file)
@@ -87,7 +87,7 @@ HAService::HAService(const unsigned int id, const IOServicePtr& io_service,
         communication_state_.reset(new CommunicationState6(io_service_, config));
     }
 
-    network_state_->enableService(NetworkState::HA_LOCAL_COMMAND+id_);
+    network_state_->enableService(getLocalOrigin());
 
     startModel(HA_WAITING_ST);
 
@@ -146,7 +146,7 @@ HAService::~HAService() {
     // Stop client and/or listener.
     stopClientAndListener();
 
-    network_state_->enableService(NetworkState::HA_LOCAL_COMMAND+id_);
+    network_state_->enableService(getLocalOrigin());
 }
 
 void
@@ -1081,7 +1081,7 @@ HAService::adjustNetworkState() {
         LOG_INFO(ha_logger, HA_LOCAL_DHCP_DISABLE)
             .arg(config_->getThisServerName())
             .arg(current_state_name);
-        network_state_->disableService(NetworkState::HA_LOCAL_COMMAND+id_);
+        network_state_->disableService(getLocalOrigin());
 
     } else if (should_enable && !network_state_->isServiceEnabled()) {
         std::string current_state_name = getStateLabel(getCurrState());
@@ -1089,7 +1089,7 @@ HAService::adjustNetworkState() {
         LOG_INFO(ha_logger, HA_LOCAL_DHCP_ENABLE)
             .arg(config_->getThisServerName())
             .arg(current_state_name);
-        network_state_->enableService(NetworkState::HA_LOCAL_COMMAND+id_);
+        network_state_->enableService(getLocalOrigin());
     }
 }
 
@@ -1879,7 +1879,7 @@ HAService::asyncDisableDHCPService(HttpClient& http_client,
          HostHttpHeader(remote_config->getUrl().getStrippedHostname()));
 
     remote_config->addBasicAuthHttpHeader(request);
-    request->setBodyAsJson(CommandCreator::createDHCPDisable(NetworkState::HA_REMOTE_COMMAND+id_,
+    request->setBodyAsJson(CommandCreator::createDHCPDisable(getRemoteOrigin(),
                                                              max_period,
                                                              server_type_));
     request->finalize();
@@ -1960,7 +1960,7 @@ HAService::asyncEnableDHCPService(HttpClient& http_client,
         (HttpRequest::Method::HTTP_POST, "/", HttpVersion::HTTP_11(),
          HostHttpHeader(remote_config->getUrl().getStrippedHostname()));
     remote_config->addBasicAuthHttpHeader(request);
-    request->setBodyAsJson(CommandCreator::createDHCPEnable(NetworkState::HA_REMOTE_COMMAND+id_,
+    request->setBodyAsJson(CommandCreator::createDHCPEnable(getRemoteOrigin(),
                                                             server_type_));
     request->finalize();
 
@@ -2031,12 +2031,12 @@ HAService::asyncEnableDHCPService(HttpClient& http_client,
 
 void
 HAService::localDisableDHCPService() {
-    network_state_->disableService(NetworkState::HA_LOCAL_COMMAND+id_);
+    network_state_->disableService(getLocalOrigin());
 }
 
 void
 HAService::localEnableDHCPService() {
-    network_state_->enableService(NetworkState::HA_LOCAL_COMMAND+id_);
+    network_state_->enableService(getLocalOrigin());
 }
 
 void
@@ -2919,7 +2919,7 @@ HAService::asyncSyncCompleteNotify(HttpClient& http_client,
          HostHttpHeader(remote_config->getUrl().getStrippedHostname()));
 
     remote_config->addBasicAuthHttpHeader(request);
-    request->setBodyAsJson(CommandCreator::createSyncCompleteNotify(NetworkState::HA_REMOTE_COMMAND+id_,
+    request->setBodyAsJson(CommandCreator::createSyncCompleteNotify(getRemoteOrigin(),
                                                                     config_->getThisServerName(),
                                                                     server_type_));
     request->finalize();
index 93b2a6caea1afec53c006e32e1afdf66f945ae70..48b325d4ca7922c56e732ae2d0ec15fc1a5eeb56 100644 (file)
@@ -129,6 +129,24 @@ public:
         return (server_type_);
     }
 
+private:
+
+    /// @brief Returns the network state origin associated with this
+    /// @c HAService instance.
+    ///
+    /// @return The service's origin value.
+    unsigned int getLocalOrigin() const {
+        return (dhcp::NetworkState::HA_LOCAL_COMMAND + id_);
+    }
+
+    /// @brief Returns the network state origin associated with the
+    /// remote @c HAService instance.
+    ///
+    /// @return The remote service's origin value.
+    unsigned int getRemoteOrigin() const {
+        return (dhcp::NetworkState::HA_REMOTE_COMMAND + id_);
+    }
+
     /// @brief Defines events used by the HA service.
     virtual void defineEvents();