7#ifndef LEASE_QUERY_CONNECTION_H
8#define LEASE_QUERY_CONNECTION_H
18#include <boost/multi_index/indexed_by.hpp>
19#include <boost/multi_index/member.hpp>
20#include <boost/multi_index_container.hpp>
21#include <boost/multi_index/mem_fun.hpp>
22#include <boost/multi_index/sequenced_index.hpp>
23#include <boost/multi_index/ordered_index.hpp>
24#include <boost/multi_index/tag.hpp>
36template <
class QueryType>
43 typedef boost::multi_index_container<
46 boost::multi_index::indexed_by<
47 boost::multi_index::sequenced<>,
48 boost::multi_index::ordered_unique<
49 boost::multi_index::const_mem_fun<QueryType,
60 std::lock_guard<std::mutex> lck(mutex_);
61 queries_.push_back(query);
70 std::lock_guard<std::mutex> lck(mutex_);
71 if (!queries_.empty()) {
72 query = queries_.front();
83 std::lock_guard<std::mutex> lck(mutex_);
84 return (queries_.empty());
91 std::lock_guard<std::mutex> lck(mutex_);
92 return (queries_.size());
101 std::lock_guard<std::mutex> lck(mutex_);
102 return (findInternal(xid));
109 auto& xid_index = queries_.template
get<1>();
110 auto query = xid_index.find(xid);
111 if (query != xid_index.end()) {
112 xid_index.erase(query);
118 std::lock_guard<std::mutex> lck(mutex_);
131 auto const& xid_index = queries_.template
get<1>();
132 auto const query = xid_index.find(xid);
133 if (query != xid_index.end()) {
143 mutable std::mutex mutex_;
180 const long idle_timeout,
181 const uint16_t family,
182 const size_t max_concurrent_queries,
183 const size_t read_max = 32768);
193 virtual void close();
236 ptr->sendNextResponse();
350 return (ptr->pushToSend(response));
386 ptr->queryComplete(xid);
The IOAddress class represents an IP addresses (version agnostic)
Derivation of TcpConnection used for Bulk LeaseQuery.
LeaseQueryConnection(const asiolink::IOServicePtr &io_service, const tcp::TcpConnectionAcceptorPtr &acceptor, const asiolink::TlsContextPtr &tls_context, tcp::TcpConnectionPool &connection_pool, const tcp::TcpConnectionAcceptorCallback &acceptor_callback, const tcp::TcpConnectionFilterCallback &filter_callback, const long idle_timeout, const uint16_t family, const size_t max_concurrent_queries, const size_t read_max=32768)
Constructor.
size_t max_concurrent_queries_
Maximum number of concurrent queries allowed.
size_t getNumResponses() const
Returns the number of responses in the response queue.
virtual bool responseSent(tcp::TcpResponsePtr response)
Processes a response once it has been sent.
bool stopping_
Stopping flag.
bool findQuery(const Xid &xid) const
Find queries based on Xid in the query list and queue.
virtual tcp::TcpRequestPtr createRequest()
Creates a new empty request ready to receive data.
bool canSend() const
Can send (aka stopped) flag.
size_t getNumRunningQueries() const
Returns the number of queries in the in-progress list.
virtual void processNextQuery()
Process next waiting query.
bool noPendingQuery() const
Returns True if the queue of waiting queries is empty.
virtual void requestReceived(tcp::TcpRequestPtr request)
Processes a completely received request.
virtual void sendNextResponse()
Sends the next response in the response queue.
BlqQueryPtr unpackQuery6(const uint8_t *buffer, size_t length) const
Unpacks a DHCPv6 packet from a data buffer.
XidQueue< BlqMsg > pending_queries_
Queue of queries waiting to enter processing.
virtual void close()
Closes the socket.
BlqResponseList responses_
List of responses waiting to be sent.
virtual ~LeaseQueryConnection()
Destructor.
static bool doPushToSend(LeaseQueryConnectionWPtr wptr, BlqResponsePtr response)
Class/static version of pushToSend.
uint16_t family_
Protocol family AF_INET or AF_INET6.
BlqQueryPtr popPendingQuery()
Pops a query from the queue of waiting queries.
XidQueue< BulkLeaseQuery > running_queries_
List of in-process queries.
virtual void stopThisConnection()
Stops current connection.
virtual void shutdown()
Shutdown the socket.
tcp::TcpResponsePtr makeTcpResponse(BlqResponsePtr blq_response) const
Constructs a ready to send TcpResponse from and BlqResponse.
std::mutex responses_mutex_
Mutex used to lock during responses access.
BlqResponsePtr response_to_send_
Tracks the response currently being sent.
void removeRunningQuery(const Xid &xid)
Removes a query from the in-progress query list.
static void doSendNextResponse(LeaseQueryConnectionWPtr wptr)
Class/static version of sendNextResponse.
void addPendingQuery(BlqQueryPtr query)
Queues a query to the end of the queue of waiting queries.
void startQuery(BlqQueryPtr query_msg)
Start query processing.
asiolink::IOServicePtr io_service_
IOService that drives the connection events.
bool can_send_
Can send flag.
virtual void queryComplete(const Xid &xid)
Finishes up when a query has been completed (e.g.
virtual void post(const BlqPostCbArg &callback)
Posts an event callback to the connection's IOService.
static void doPost(LeaseQueryConnectionWPtr wptr, const BlqPostCbArg &callback)
Class/static version of post.
BlqQueryPtr unpackQuery4(const uint8_t *buffer, size_t length) const
Unpacks a DHCPv4 packet from a data buffer.
asiolink::IOAddress getRequesterAddress() const
Returns the requester's ip address.
bool isStopping() const
Stopping flag.
static void doQueryComplete(LeaseQueryConnectionWPtr wptr, const Xid &xid)
Class/static version of queryComplete.
void addRunningQuery(BulkLeaseQueryPtr query)
Adds a query to the end of the list of in-progress queries.
virtual bool pushToSend(BlqResponsePtr response)
Adds a response to the connection's outbound queue of responses.
Wrapper around a chronological list of queries, uniquely keyed by transaction id.
void remove(const Xid &xid)
Removes a query from the queue for a given transaction id.
bool empty() const
Empty predicate.
void clear()
Removes all queries from the queue.
void add(QueryPtrType query)
Adds a query to the end of the queue.
boost::shared_ptr< QueryType > QueryPtrType
Type of pointers to QueryType.
QueryPtrType pop()
Pops a query to the beginning of the queue.
boost::multi_index_container< QueryPtrType, boost::multi_index::indexed_by< boost::multi_index::sequenced<>, boost::multi_index::ordered_unique< boost::multi_index::const_mem_fun< QueryType, Xid, &QueryType::getXid > > > > XidQueueContainer
Multi-index container for storing bulk lease queries.
QueryPtrType find(const Xid &xid) const
Fetches the query for a given transaction id.
size_t size() const
Fetches the number of entries in the queue.
Pool of active TCP connections.
Accepts and handles a single TCP connection.
std::string getRemoteEndpointAddressAsText() const
returns remote address in textual form
int get(CalloutHandle &handle)
The gss-tsig-get command.
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.
boost::shared_ptr< LeaseQueryConnection > LeaseQueryConnectionPtr
Defines a shared pointer to a LeaseQueryConnection.
boost::shared_ptr< BlqResponse > BlqResponsePtr
Defines a shared pointer to an BlqResponse.
std::function< void()> BlqPostCbArg
Type of BLQ post callback argument..
uint32_t Xid
Defines a Bulk LeaseQuery transaction id.
boost::weak_ptr< LeaseQueryConnection > LeaseQueryConnectionWPtr
Defines a weak pointer to a LeaseQueryConnection.
std::list< BlqResponsePtr > BlqResponseList
Contains a list of BlqResponse pointers.
boost::shared_ptr< BlqQuery > BlqQueryPtr
Defines a shared pointer to an BlqQuery.
boost::shared_ptr< BulkLeaseQuery > BulkLeaseQueryPtr
Defines a shared pointer to a BulkLeaseQuery object.
std::function< bool(const boost::asio::ip::tcp::endpoint &)> TcpConnectionFilterCallback
Type of the callback for filtering new connections by ip address.
boost::shared_ptr< TcpConnectionAcceptor > TcpConnectionAcceptorPtr
Type of shared pointer to TCP acceptors.
boost::shared_ptr< TcpRequest > TcpRequestPtr
Defines a smart pointer to a TcpRequest.
boost::shared_ptr< TcpResponse > TcpResponsePtr
std::function< void(const boost::system::error_code &)> TcpConnectionAcceptorCallback
Type of the callback for the TCP acceptor used in this library.
Defines the logger used by the top-level component of kea-lfc.