From: Marcin Siodelski Date: Wed, 29 Nov 2023 11:29:06 +0000 (+0100) Subject: [#3106] Convenience functions in HAService X-Git-Tag: Kea-2.5.5~118 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=5a6560574be1530ca464731ee50ce3868900dc23;p=thirdparty%2Fkea.git [#3106] Convenience functions in HAService --- diff --git a/src/hooks/dhcp/high_availability/ha_impl.h b/src/hooks/dhcp/high_availability/ha_impl.h index 7045b7d61b..9b26f9dfa2 100644 --- a/src/hooks/dhcp/high_availability/ha_impl.h +++ b/src/hooks/dhcp/high_availability/ha_impl.h @@ -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 diff --git a/src/hooks/dhcp/high_availability/ha_service.cc b/src/hooks/dhcp/high_availability/ha_service.cc index 4c570931d5..013ea7a2eb 100644 --- a/src/hooks/dhcp/high_availability/ha_service.cc +++ b/src/hooks/dhcp/high_availability/ha_service.cc @@ -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(); diff --git a/src/hooks/dhcp/high_availability/ha_service.h b/src/hooks/dhcp/high_availability/ha_service.h index 93b2a6caea..48b325d4ca 100644 --- a/src/hooks/dhcp/high_availability/ha_service.h +++ b/src/hooks/dhcp/high_availability/ha_service.h @@ -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();