Kea 2.7.5
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 {
38private:
39
41
43 struct Client {
44
50 Client(Pkt6Ptr query, DuidPtr client_id);
51
53 Pkt6Ptr query_;
54
56 std::vector<uint8_t> duid_;
57
59 std::thread::id thread_;
60
65 Pkt6Ptr next_query_;
66
71 ContinuationPtr cont_;
72 };
73
75 typedef boost::shared_ptr<Client> ClientPtr;
76
78 typedef boost::multi_index_container<
79
80 // This container stores pointers to client objects.
81 ClientPtr,
82
83 // Start specification of indexes here.
84 boost::multi_index::indexed_by<
85
86 // First index is used to search by Duid.
87 boost::multi_index::hashed_unique<
88
89 // Client ID binary content as a member of the Client object.
90 boost::multi_index::member<
91 Client, std::vector<uint8_t>, &Client::duid_
92 >
93 >
94 >
95 > ClientContainer;
96
103 static ClientPtr lookup(const DuidPtr& duid);
104
110 static void add(const ClientPtr& client);
111
117 static void del(const DuidPtr& duid);
118
122 static std::mutex mutex_;
123
125 static ClientContainer clients_;
126
127public:
128
130
133
137 virtual ~ClientHandler();
138
150 bool tryLock(Pkt6Ptr query, ContinuationPtr cont = ContinuationPtr());
151
152private:
153
155
159 void lock();
160
167 void unLock();
168
170 ClientPtr client_;
171
173 DuidPtr locked_;
174};
175
176} // namespace isc
177} // namespace dhcp
178
179#endif // CLIENT_HANDLER_H
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.