Kea 3.2.1-git
d2_update_mgr.h
Go to the documentation of this file.
1// Copyright (C) 2013-2026 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef D2_UPDATE_MGR_H
8#define D2_UPDATE_MGR_H
9
11
12#include <asiolink/io_service.h>
13#include <d2/d2_queue_mgr.h>
14#include <d2srv/nc_trans.h>
15#include <d2srv/d2_cfg_mgr.h>
16#include <d2srv/d2_log.h>
18
19#include <boost/multi_index_container.hpp>
20#include <boost/multi_index/hashed_index.hpp>
21#include <boost/multi_index/indexed_by.hpp>
22#include <boost/multi_index/member.hpp>
23#include <boost/multi_index/mem_fun.hpp>
24#include <boost/multi_index/sequenced_index.hpp>
25#include <boost/noncopyable.hpp>
26#include <boost/shared_ptr.hpp>
27#include <map>
28
29namespace isc {
30namespace d2 {
31
34public:
35 D2UpdateMgrError(const char* file, size_t line, const char* what) :
36 isc::Exception(file, line, what) { }
37};
38
40struct SequenceTag { };
41
43struct AddressTag { };
44
46struct FqdnTag { };
47
52typedef boost::multi_index_container<
53 // It holds pointers to NameChangeTransactions.
55 boost::multi_index::indexed_by<
56 // Index by insertion order
57 boost::multi_index::sequenced<
58 boost::multi_index::tag<SequenceTag>
59 >,
60
61 // Index by FQDN as dns::Name for case insensitive comparison.
62 boost::multi_index::hashed_unique<
63 boost::multi_index::tag<FqdnTag>,
64 boost::multi_index::const_mem_fun<NameChangeTransaction, std::string,
66 >,
67
68 // Index by lease address
69 boost::multi_index::hashed_unique<
70 boost::multi_index::tag<AddressTag>,
71 boost::multi_index::const_mem_fun<NameChangeTransaction, const asiolink::IOAddress&,
73 >
74 >
76
77typedef TransactionStore::index<SequenceTag>::type TransactionSequenceIndex;
78
79typedef TransactionStore::index<FqdnTag>::type TransactionFqdnIndex;
80
81typedef TransactionStore::index<AddressTag>::type TransactionAddressIndex;
82
112class D2UpdateMgr : public boost::noncopyable {
113public:
117 static const size_t MAX_TRANSACTIONS_DEFAULT = 32;
118
129 D2UpdateMgr(D2QueueMgrPtr& queue_mgr, D2CfgMgrPtr& cfg_mgr,
130 asiolink::IOServicePtr& io_service,
131 const size_t max_transactions = MAX_TRANSACTIONS_DEFAULT);
132
134 virtual ~D2UpdateMgr();
135
150 void sweep();
151
152protected:
159
175 void pickNextJob();
176
206
207public:
212 return (io_service_);
213 }
214
216 size_t getMaxTransactions() const {
217 return (max_transactions_);
218 }
219
227 void setMaxTransactions(const size_t max_transactions);
228
235 bool hasTransaction(const dhcp_ddns::NameChangeRequestPtr& ncr) const;
236
241 void clearTransactions();
242
244 size_t getQueueCount() const;
245
247 size_t getTransactionCount() const;
248
250 TransactionSequenceIndex::iterator transactionSequenceBegin();
251
253 TransactionSequenceIndex::iterator transactionSequenceEnd();
254
261 TransactionFqdnIndex::iterator
262 findTransactionByFqdn(const std::string& fqdn) const;
263
265 TransactionFqdnIndex::iterator transactionFqdnBegin();
266
268 TransactionFqdnIndex::iterator transactionFqdnEnd();
269
276 TransactionAddressIndex::iterator
277 findTransactionByAddress( const asiolink::IOAddress& address) const;
278
280 TransactionAddressIndex::iterator transactionAddressBegin();
281
283 TransactionAddressIndex::iterator transactionAddressEnd();
284
285private:
287 D2QueueMgrPtr queue_mgr_;
288
290 D2CfgMgrPtr cfg_mgr_;
291
298 asiolink::IOServicePtr io_service_;
299
301 size_t max_transactions_;
302
304 TransactionStore transaction_store_;
305};
306
308typedef boost::shared_ptr<D2UpdateMgr> D2UpdateMgrPtr;
309
310} // namespace isc::d2
311} // namespace isc
312#endif
This is a base class for exceptions thrown from the DNS library module.
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
D2UpdateMgrError(const char *file, size_t line, const char *what)
TransactionFqdnIndex::iterator transactionFqdnBegin()
Returns the transaction store begin iterator, ordered by FQDN.
TransactionAddressIndex::iterator transactionAddressEnd()
Returns the transaction store end iterator, ordered by address.
const asiolink::IOServicePtr & getIOService()
Gets the D2UpdateMgr's IOService.
bool makeTransaction(isc::dhcp_ddns::NameChangeRequestPtr &ncr)
Create a new transaction for the given request.
TransactionFqdnIndex::iterator transactionFqdnEnd()
Returns the transaction store end iterator, ordered by FQDN.
TransactionAddressIndex::iterator transactionAddressBegin()
Returns the transaction store begin iterator, ordered by address.
TransactionSequenceIndex::iterator transactionSequenceEnd()
Returns the transaction store sequence end position.
void checkFinishedTransactions()
Performs post-completion cleanup on completed transactions.
void setMaxTransactions(const size_t max_transactions)
Sets the maximum number of entries allowed in the queue.
void sweep()
Check current transactions; start transactions for new requests.
TransactionAddressIndex::iterator findTransactionByAddress(const asiolink::IOAddress &address) const
Search the transaction store for a given address.
size_t getMaxTransactions() const
Returns the maximum number of concurrent transactions.
size_t getQueueCount() const
Convenience method that returns the number of requests queued.
bool hasTransaction(const dhcp_ddns::NameChangeRequestPtr &ncr) const
Checks if there is an active transaction matching the FQDN or ip address of an NCR.
D2UpdateMgr(D2QueueMgrPtr &queue_mgr, D2CfgMgrPtr &cfg_mgr, asiolink::IOServicePtr &io_service, const size_t max_transactions=MAX_TRANSACTIONS_DEFAULT)
Constructor.
size_t getTransactionCount() const
Returns the current number of transactions.
void pickNextJob()
Starts a transaction for the next eligible request in the queue.
void clearTransactions()
Immediately discards all entries in the transaction list.
TransactionFqdnIndex::iterator findTransactionByFqdn(const std::string &fqdn) const
Search the transaction store for an FQDN.
static const size_t MAX_TRANSACTIONS_DEFAULT
Maximum number of concurrent transactions NOTE that 32 is an arbitrary choice picked for the initial ...
TransactionSequenceIndex::iterator transactionSequenceBegin()
Returns the transaction store sequence begin position.
Embodies the "life-cycle" required to carry out a DDNS update.
Definition nc_trans.h:78
const asiolink::IOAddress & getIOAddress() const
Fetches the request IP address.
Definition nc_trans.cc:446
std::string getFqdnLower() const
Fetches the request FQDN converted to lower-case.
Definition nc_trans.cc:441
This file defines the class D2QueueMgr.
TransactionStore::index< AddressTag >::type TransactionAddressIndex
boost::shared_ptr< D2CfgMgr > D2CfgMgrPtr
Defines a shared pointer to D2CfgMgr.
Definition d2_cfg_mgr.h:367
TransactionStore::index< SequenceTag >::type TransactionSequenceIndex
TransactionStore::index< FqdnTag >::type TransactionFqdnIndex
boost::shared_ptr< D2UpdateMgr > D2UpdateMgrPtr
Defines a pointer to a D2UpdateMgr instance.
boost::shared_ptr< NameChangeTransaction > NameChangeTransactionPtr
Defines a pointer to a NameChangeTransaction.
Definition nc_trans.h:615
boost::shared_ptr< D2QueueMgr > D2QueueMgrPtr
Defines a pointer for manager instances.
boost::multi_index_container< NameChangeTransactionPtr, boost::multi_index::indexed_by< boost::multi_index::sequenced< boost::multi_index::tag< SequenceTag > >, boost::multi_index::hashed_unique< boost::multi_index::tag< FqdnTag >, boost::multi_index::const_mem_fun< NameChangeTransaction, std::string, &NameChangeTransaction::getFqdnLower > >, boost::multi_index::hashed_unique< boost::multi_index::tag< AddressTag >, boost::multi_index::const_mem_fun< NameChangeTransaction, const asiolink::IOAddress &, &NameChangeTransaction::getIOAddress > > > > TransactionStore
A multi index container holding NameChangeTransaction pointers.
boost::shared_ptr< NameChangeRequest > NameChangeRequestPtr
Defines a pointer to a NameChangeRequest.
Definition ncr_msg.h:242
Defines the logger used by the top-level component of kea-lfc.
This file defines the class NameChangeTransaction.
Tag for index by ip-address.
Tag for index by Fqdn.
Tag for insertion order index.