97 << config->getPosition() <<
")");
100 for (
auto const& socket : config->listValue()) {
105 for (
auto const& data :
copy) {
106 if (data.second->usable_) {
110 data.second->usable_ =
false;
126 IOAddress server_address = cmd_config->getSocketAddress();
127 uint16_t server_port = cmd_config->getSocketPort();
130 auto it =
sockets_.find(std::make_pair(server_address, server_port));
132 auto listener = it->second->listener_;
135 if (listener->getTlsContext()) {
136 if (cmd_config->getTrustAnchor().empty()) {
139 .arg(server_address.
toText())
142 "Can not switch from HTTPS to HTTP sockets using the same address and port.");
146 TlsContext::configure(tls_context,
148 cmd_config->getTrustAnchor(),
149 cmd_config->getCertFile(),
150 cmd_config->getKeyFile(),
151 cmd_config->getCertRequired());
154 it->second->config_->setAuthConfig(cmd_config->getAuthConfig());
155 it->second->config_->setHttpHeaders(cmd_config->getHttpHeaders());
156 it->second->config_->setEmulateAgentResponse(cmd_config->getEmulateAgentResponse());
157 listener->setTlsContext(tls_context);
159 .arg(server_address.
toText())
163 if (!cmd_config->getTrustAnchor().empty()) {
166 .arg(server_address.
toText())
169 "Can not switch from HTTP to HTTPS sockets using the same address and port.");
173 it->second->config_->setAuthConfig(cmd_config->getAuthConfig());
174 it->second->config_->setHttpHeaders(cmd_config->getHttpHeaders());
175 it->second->config_->setEmulateAgentResponse(cmd_config->getEmulateAgentResponse());
177 .arg(server_address.
toText())
183 it->second->usable_ =
true;
189 bool use_https =
false;
191 if (!cmd_config->getCertFile().empty()) {
192 TlsContext::configure(tls_context,
194 cmd_config->getTrustAnchor(),
195 cmd_config->getCertFile(),
196 cmd_config->getKeyFile(),
197 cmd_config->getCertRequired());
222 http_listener->start();
225 socket_info->config_ = cmd_config;
226 socket_info->listener_ = http_listener;
228 sockets_[std::make_pair(server_address, server_port)] = socket_info;
232 .arg(use_https ?
"HTTPS" :
"HTTP")
233 .arg(server_address.
toText())
239 bool use_https =
false;
242 use_https = !
info->config_->getCertFile().empty();
243 ep <<
"bound to address " <<
info->config_->getSocketAddress()
244 <<
" port " <<
info->config_->getSocketPort();
247 .arg(use_https ?
"HTTPS" :
"HTTP")
249 info->listener_->stop();
251 auto it =
sockets_.find(std::make_pair(
info->config_->getSocketAddress(),
info->config_->getSocketPort()));
270 for (
auto const& data :
copy) {
279 auto it =
sockets_.find(std::make_pair(
info->config_->getSocketAddress(),
info->config_->getSocketPort()));
281 return (it->second->listener_);
284 return (
sockets_.begin()->second->listener_);
292 return (http_cmd_mgr);
300 impl_->io_service_ = io_service;
305 impl_->timeout_ = timeout;
310 impl_->idle_timeout_ = timeout;
315 impl_->use_external_ = use_external;
320 impl_->openCommandSocket(config);
325 impl_->openCommandSockets(config);
330 impl_->closeCommandSocket(
info, remove);
335 impl_->closeCommandSockets();
340 return (impl_->getHttpListener(
info));
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
The IOAddress class represents an IP addresses (version agnostic)
std::string toText() const
Convert the address to a string.
An exception indicating that specified socket parameters are invalid.
HTTP command config aka HTTP control socket info class.
Implementation of the HttpCommandMgr.
bool use_external_
Use external sockets flag.
std::map< std::pair< IOAddress, uint16_t >, HttpSocketInfoPtr > sockets_
The HTTP/HTTPS socket data (configuration, listener, etc.).
void openCommandSockets(const isc::data::ConstElementPtr config)
Open http control sockets using configuration.
long idle_timeout_
Idle connection timeout.
IOServicePtr io_service_
Pointer to the IO service.
void closeCommandSockets(bool remove=true)
Close control socket.
HttpCommandMgrImpl()
Constructor.
void closeCommandSocket(HttpSocketInfoPtr info, bool remove)
Close control socket.
void openCommandSocket(const isc::data::ConstElementPtr config)
Open http control socket using configuration.
long timeout_
Connection timeout.
ConstHttpListenerPtr getHttpListener(HttpSocketInfoPtr info) const
Returns a const pointer to the HTTP listener.
HTTP Commands Manager implementation for the Kea servers.
void openCommandSocket(const isc::data::ConstElementPtr config)
Open http control socket using configuration.
void setIdleConnectionTimeout(const long timeout)
Override default idle connection timeout.
isc::http::ConstHttpListenerPtr getHttpListener(HttpSocketInfoPtr info=HttpSocketInfoPtr()) const
Returns a const pointer to the HTTP listener.
void closeCommandSockets()
Close http control sockets.
void setConnectionTimeout(const long timeout)
Override default connection timeout.
void addExternalSockets(bool use_external=true)
Use external sockets flag.
static HttpCommandMgr & instance()
HttpCommandMgr is a singleton class.
void setIOService(const asiolink::IOServicePtr &io_service)
Sets IO service to be used by the http command manager.
void openCommandSockets(const isc::data::ConstElementPtr config)
Open http control sockets using configuration.
void closeCommandSocket(HttpSocketInfoPtr info=HttpSocketInfoPtr(), bool remove=true)
Close http control socket.
HTTP response creator factory for HTTP control socket.
To be removed. Please use ConfigError instead.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
boost::shared_ptr< TlsContext > TlsContextPtr
The type of shared pointers to TlsContext objects.
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
const isc::log::MessageID HTTP_COMMAND_MGR_HTTPS_SERVICE_UPDATED
constexpr long TIMEOUT_AGENT_IDLE_CONNECTION_TIMEOUT
Timeout for the idle connection to be closed.
const isc::log::MessageID HTTP_COMMAND_MGR_SERVICE_STARTED
boost::shared_ptr< HttpSocketInfo > HttpSocketInfoPtr
Pointer to a HttpSocketInfo object.
const isc::log::MessageID HTTP_COMMAND_MGR_SERVICE_STOPPING
const isc::log::MessageID HTTP_COMMAND_MGR_HTTP_SERVICE_REUSE_FAILED
const isc::log::MessageID HTTP_COMMAND_MGR_HTTP_SERVICE_UPDATED
boost::shared_ptr< HttpCommandConfig > HttpCommandConfigPtr
Pointer to a HttpCommandConfig object.
isc::log::Logger command_logger("commands")
Command processing Logger.
const isc::log::MessageID HTTP_COMMAND_MGR_HTTPS_SERVICE_REUSE_FAILED
constexpr long TIMEOUT_AGENT_RECEIVE_COMMAND
Timeout for the Control Agent to receive command over the RESTful interface.
ElementPtr copy(ConstElementPtr from, int level)
Copy the data up to a nesting level.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< const HttpListener > ConstHttpListenerPtr
Pointer to the const HttpListener.
boost::shared_ptr< HttpListener > HttpListenerPtr
Pointer to the HttpListener.
boost::shared_ptr< HttpResponseCreatorFactory > HttpResponseCreatorFactoryPtr
Pointer to the HttpResponseCreatorFactory.
Defines the logger used by the top-level component of kea-lfc.
Structure used to store HTTP/HTTPS connection data.
HTTP request timeout value.