Kea 3.3.1
dhcp6/client_handler.h
Go to the documentation of this file.
1// Copyright (C) 2020 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 CLIENT_HANDLER_H
8#define CLIENT_HANDLER_H
9
10#include <dhcp/pkt6.h>
11#include <boost/noncopyable.hpp>
12#include <boost/multi_index_container.hpp>
13#include <boost/multi_index/hashed_index.hpp>
14#include <boost/multi_index/member.hpp>
15#include <boost/shared_ptr.hpp>
16#include <functional>
17#include <mutex>
18#include <thread>
19
20namespace isc {
21namespace dhcp {
22
24typedef std::function<void()> Continuation;
25
27typedef boost::shared_ptr<Continuation> ContinuationPtr;
28
33 return (boost::make_shared<Continuation>(cont));
34}
35
37class ClientHandler : public boost::noncopyable {
38public:
39
41
43 struct Client {
44
50 Client(Pkt6Ptr query, DuidPtr client_id);
51
53
55 std::vector<uint8_t> duid_;
56
58 uint8_t msg_type_;
59
61 uint32_t transid_;
62
65
67 std::thread::id thread_;
68
74
80 };
81
83 typedef boost::shared_ptr<Client> ClientPtr;
84
85private:
87 typedef boost::multi_index_container<
88
89 // This container stores pointers to client objects.
91
92 // Start specification of indexes here.
93 boost::multi_index::indexed_by<
94
95 // First index is used to search by Duid.
96 boost::multi_index::hashed_unique<
97
98 // Client ID binary content as a member of the Client object.
99 boost::multi_index::member<
100 Client, std::vector<uint8_t>, &Client::duid_
101 >
102 >
103 >
104 > ClientContainer;
105
112 static ClientPtr lookup(const DuidPtr& duid);
113
119 static void add(const ClientPtr& client);
120
126 static void del(const DuidPtr& duid);
127
131 static std::mutex mutex_;
132
134 static ClientContainer clients_;
135
136public:
137
139
142
146 virtual ~ClientHandler();
147
159 bool tryLock(Pkt6Ptr query, ContinuationPtr cont = ContinuationPtr());
160
161private:
162
164
168 void lock();
169
176 void unLock();
177
179 ClientPtr client_;
180
182 DuidPtr locked_;
183};
184
185} // namespace isc
186} // namespace dhcp
187
188#endif // CLIENT_HANDLER_H
Client race avoidance RAII handler.
boost::shared_ptr< Client > ClientPtr
The type of shared pointers to clients.
virtual ~ClientHandler()
Destructor.
bool tryLock(Pkt4Ptr query, ContinuationPtr cont=ContinuationPtr())
Tries to acquires a client.
ClientHandler()
Public interface.
std::function< void()> Continuation
Define the type of packet processing continuation.
boost::shared_ptr< DUID > DuidPtr
Definition duid.h:136
ContinuationPtr makeContinuation(Continuation &&cont)
Continuation factory.
boost::shared_ptr< Continuation > ContinuationPtr
Define the type of shared pointers to continuations.
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
Definition pkt6.h:31
Defines the logger used by the top-level component of kea-lfc.
Class (aka static) types, methods and members.
uint32_t transid_
Cached transaction ID.
Client(Pkt4Ptr query, ClientIdPtr client_id, HWAddrPtr hwaddr)
Constructor.
std::vector< uint8_t > duid_
Cached binary client ID.
ContinuationPtr cont_
The continuation to process next query for the client.
uint8_t msg_type_
Cached message type.
std::thread::id thread_
The ID of the thread processing the query.