![]() |
Kea 3.1.1
|
#include <client_exchange.h>
Public Types | |
typedef std::function< void(const ExchangePtr ex)> | Handler |
Termination handler. | |
typedef asiolink::UDPSocket< const SocketCallback > | RadiusSocket |
Type of RADIUS UDP sockets. | |
typedef std::function< void(const boost::system::error_code ec, const size_t size)> | SocketCallback |
Type of UDP socket callback functions. | |
Public Member Functions | |
Exchange (const asiolink::IOServicePtr io_service, const MessagePtr &request, unsigned maxretries, const Servers &servers, Handler handler) | |
Constructor. | |
Exchange (const MessagePtr &request, unsigned maxretries, const Servers &servers) | |
Constructor. | |
virtual | ~Exchange () |
Destructor. | |
const std::string & | getId () const |
Get identifier. | |
int | getRC () const |
Get the error code. | |
MessagePtr | getRequest () const |
Get the request. | |
MessagePtr | getResponse () const |
Get the response. | |
void | logReplyMessages () const |
Log reply messages. | |
virtual void | shutdown () |
Shutdown. | |
virtual void | start () |
Start. | |
Static Public Attributes | |
static constexpr size_t | BUF_LEN = 8192 |
Receive buffer size. | |
Protected Member Functions | |
void | buildRequest () |
Build request. | |
void | cancelTimer () |
Cancel timer. | |
void | createIdentifier () |
Create identifier. | |
void | open () |
Instance open. | |
void | setTimer () |
Set timer. | |
virtual void | shutdownInternal () |
Shutdown. | |
void | terminate () |
Terminate. | |
Static Protected Member Functions | |
static void | openNext (ExchangePtr ex) |
Class open / open next. | |
static void | receivedHandler (ExchangePtr ex, const boost::system::error_code ec, const size_t size) |
Received handler. | |
static void | sentHandler (ExchangePtr ex, const boost::system::error_code ec, const size_t size) |
Sent handler. | |
static void | timeoutHandler (ExchangePtr ex) |
Timeout handler. | |
Protected Attributes | |
std::vector< uint8_t > | buffer_ |
Buffer. | |
boost::scoped_ptr< asiolink::UDPEndpoint > | ep_ |
UDP endpoint. | |
Handler | handler_ |
Termination handler. | |
std::string | identifier_ |
The identifier (random value in hexadecimal). | |
size_t | idx_ |
Current server index. | |
asiolink::IOServicePtr | io_service_ |
IO service (argument for async or internal for sync). | |
unsigned | maxretries_ |
Maximum number of retries for a server. | |
boost::scoped_ptr< std::mutex > | mutex_ |
State change mutex. | |
std::list< size_t > | postponed_ |
List of postponed server indexes. | |
int | rc_ |
Error/return code. | |
MessagePtr | received_ |
Received message. | |
MessagePtr | request_ |
Request message. | |
unsigned | retries_ |
Retry counter. | |
MessagePtr | sent_ |
Sent message. | |
ServerPtr | server_ |
Current server. | |
Servers | servers_ |
Servers (a copy which is what we need). | |
size_t | size_ |
Number of transmitted octests;. | |
boost::scoped_ptr< RadiusSocket > | socket_ |
Socket. | |
std::chrono::steady_clock::time_point | start_time_ |
Start time. | |
bool | started_ |
Started flag. | |
bool | sync_ |
Sync / async flag. | |
bool | terminated_ |
Terminated flag. | |
asiolink::IntervalTimerPtr | timer_ |
Interval timer. | |
RADIUS Exchange.
Definition at line 58 of file client_exchange.h.
typedef std::function<void(const ExchangePtr ex)> isc::radius::Exchange::Handler |
Termination handler.
Definition at line 71 of file client_exchange.h.
typedef asiolink::UDPSocket<const SocketCallback> isc::radius::Exchange::RadiusSocket |
Type of RADIUS UDP sockets.
Definition at line 68 of file client_exchange.h.
typedef std::function<void(const boost::system::error_code ec, const size_t size)> isc::radius::Exchange::SocketCallback |
Type of UDP socket callback functions.
Definition at line 65 of file client_exchange.h.
isc::radius::Exchange::Exchange | ( | const asiolink::IOServicePtr | io_service, |
const MessagePtr & | request, | ||
unsigned | maxretries, | ||
const Servers & | servers, | ||
Handler | handler ) |
Constructor.
Async version.
io_service | Reference to the IO service. |
request | request message to send. |
maxretries | maximum number of retries for a server. |
servers | Servers. |
handler | Termination handler. |
Definition at line 58 of file client_exchange.cc.
References buffer_, createIdentifier(), ep_, isc::radius::ERROR_RC, handler_, identifier_, idx_, if(), io_service_, isc_throw, maxretries_, mutex_, postponed_, rc_, received_, request_, retries_, sent_, server_, servers_, size_, socket_, start_time_, started_, sync_, terminated_, and timer_.
isc::radius::Exchange::Exchange | ( | const MessagePtr & | request, |
unsigned | maxretries, | ||
const Servers & | servers ) |
Constructor.
Sync version.
request | request message to send. |
maxretries | maximum number of retries for a server. |
servers | Servers. |
Definition at line 85 of file client_exchange.cc.
References buffer_, createIdentifier(), ep_, isc::radius::ERROR_RC, handler_, identifier_, idx_, io_service_, isc_throw, maxretries_, mutex_, postponed_, rc_, received_, request_, retries_, sent_, server_, servers_, size_, socket_, start_time_, started_, sync_, terminated_, and timer_.
|
virtual |
Destructor.
Definition at line 105 of file client_exchange.cc.
References io_service_, mutex_, shutdownInternal(), socket_, sync_, and timer_.
|
protected |
Build request.
Definition at line 208 of file client_exchange.cc.
References isc::radius::Attribute::fromInt(), isc::radius::Attribute::fromIpAddr(), isc::radius::Attribute::fromIpv6Addr(), isc::asiolink::IOAddress::getFamily(), isc_throw, isc::radius::PW_ACCESS_REQUEST, isc::radius::PW_ACCOUNTING_REQUEST, isc::radius::PW_ACCT_DELAY_TIME, isc::radius::PW_NAS_IP_ADDRESS, isc::radius::PW_NAS_IPV6_ADDRESS, request_, sent_, server_, and start_time_.
Referenced by open().
|
protected |
Cancel timer.
Definition at line 697 of file client_exchange.cc.
References timer_.
Referenced by open(), setTimer(), shutdownInternal(), and terminate().
|
protected |
Create identifier.
Definition at line 118 of file client_exchange.cc.
References identifier_, isc_throw, and isc::cryptolink::random().
Referenced by Exchange(), and Exchange().
|
inline |
Get identifier.
Definition at line 105 of file client_exchange.h.
References identifier_.
|
inline |
Get the error code.
Definition at line 112 of file client_exchange.h.
References rc_.
|
inline |
Get the request.
Definition at line 119 of file client_exchange.h.
References request_.
|
inline |
Get the response.
Definition at line 126 of file client_exchange.h.
References received_.
void isc::radius::Exchange::logReplyMessages | ( | ) | const |
Log reply messages.
Definition at line 131 of file client_exchange.cc.
References identifier_, LOG_INFO, isc::radius::PW_REPLY_MESSAGE, isc::radius::radius_logger, isc::radius::RADIUS_REPLY_MESSAGE_ATTRIBUTE, and received_.
|
protected |
Instance open.
Definition at line 264 of file client_exchange.cc.
References buffer_, buildRequest(), cancelTimer(), ep_, isc::radius::ERROR_RC, identifier_, idx_, io_service_, isc_throw, LOG_DEBUG, LOG_ERROR, maxretries_, openNext(), postponed_, isc::radius::RADIUS_DBG_TRACE, isc::radius::RADIUS_EXCHANGE_OPEN_FAILED, isc::radius::RADIUS_EXCHANGE_SEND_NEW, isc::radius::RADIUS_EXCHANGE_SEND_RETRY, isc::radius::radius_logger, rc_, retries_, sent_, sentHandler(), server_, servers_, setTimer(), isc::radius::RadiusImpl::shutdown_, shutdownInternal(), size_, socket_, start_time_, terminate(), terminated_, isc::radius::TIMEOUT_RC, and isc::Exception::what().
Referenced by start().
|
inlinestaticprotected |
Class open / open next.
ex | the exchange. |
Definition at line 228 of file client_exchange.h.
Referenced by open(), receivedHandler(), and sentHandler().
|
staticprotected |
Received handler.
ex | the exchange. |
ec | Boost ASIO error code. |
size | number of received octets. |
Definition at line 522 of file client_exchange.cc.
References isc::radius::BADRESP_RC, isc::radius::exchangeRCtoText(), isc_throw, LOG_DEBUG, LOG_ERROR, isc::radius::msgCodeToText(), isc::radius::OK_RC, openNext(), isc::radius::PW_ACCESS_ACCEPT, isc::radius::PW_ACCESS_REJECT, isc::radius::PW_ACCESS_REQUEST, isc::radius::PW_ACCOUNTING_REQUEST, isc::radius::PW_ACCOUNTING_RESPONSE, isc::radius::RADIUS_DBG_TRACE, isc::radius::RADIUS_EXCHANGE_RECEIVE_FAILED, isc::radius::RADIUS_EXCHANGE_RECEIVED, isc::radius::RADIUS_EXCHANGE_RECEIVED_ACCESS_ACCEPT, isc::radius::RADIUS_EXCHANGE_RECEIVED_ACCESS_REJECT, isc::radius::RADIUS_EXCHANGE_RECEIVED_ACCOUNTING_RESPONSE, isc::radius::RADIUS_EXCHANGE_RECEIVED_BAD_RESPONSE, isc::radius::RADIUS_EXCHANGE_RECEIVED_MISMATCH, isc::radius::RADIUS_EXCHANGE_RECEIVED_RESPONSE, isc::radius::RADIUS_EXCHANGE_RECEIVED_UNEXPECTED, isc::radius::radius_logger, isc::radius::REJECT_RC, isc::radius::RadiusImpl::shutdown_, terminate(), and isc::Exception::what().
Referenced by sentHandler().
|
staticprotected |
Sent handler.
ex | the exchange. |
ec | Boost ASIO error code. |
size | number of sent octets. |
Definition at line 476 of file client_exchange.cc.
References BUF_LEN, isc_throw, LOG_DEBUG, LOG_ERROR, openNext(), isc::radius::RADIUS_DBG_TRACE, isc::radius::RADIUS_EXCHANGE_SEND_FAILED, isc::radius::RADIUS_EXCHANGE_SENT, isc::radius::radius_logger, receivedHandler(), and isc::radius::RadiusImpl::shutdown_.
Referenced by open().
|
protected |
Set timer.
Definition at line 689 of file client_exchange.cc.
References cancelTimer(), io_service_, isc::asiolink::IntervalTimer::ONE_SHOT, server_, timeoutHandler(), and timer_.
Referenced by open().
|
virtual |
Shutdown.
Definition at line 178 of file client_exchange.cc.
References mutex_, and shutdownInternal().
|
protectedvirtual |
Shutdown.
Definition at line 185 of file client_exchange.cc.
References cancelTimer(), handler_, io_service_, socket_, sync_, and terminated_.
Referenced by ~Exchange(), open(), and shutdown().
|
virtual |
Start.
Definition at line 151 of file client_exchange.cc.
References identifier_, io_service_, LOG_DEBUG, mutex_, open(), isc::radius::RADIUS_DBG_TRACE, isc::radius::RADIUS_EXCHANGE_START, isc::radius::RADIUS_EXCHANGE_SYNC_RETURN, isc::radius::radius_logger, rc_, started_, and sync_.
|
protected |
Terminate.
Definition at line 639 of file client_exchange.cc.
References cancelTimer(), isc::radius::exchangeRCtoText(), handler_, identifier_, isc::util::MultiThreadingMgr::instance(), io_service_, LOG_DEBUG, LOG_ERROR, mutex_, isc::radius::OK_RC, isc::radius::RADIUS_DBG_TRACE, isc::radius::RADIUS_EXCHANGE_FAILED, isc::radius::RADIUS_EXCHANGE_TERMINATE, isc::radius::radius_logger, rc_, isc::radius::REJECT_RC, socket_, sync_, and terminated_.
Referenced by open(), and receivedHandler().
|
staticprotected |
Timeout handler.
ex | the exchange. |
Definition at line 705 of file client_exchange.cc.
References LOG_ERROR, isc::radius::RADIUS_EXCHANGE_TIMEOUT, isc::radius::radius_logger, and isc::radius::TIMEOUT_RC.
Referenced by setTimer().
|
staticconstexpr |
|
protected |
Buffer.
Definition at line 189 of file client_exchange.h.
Referenced by Exchange(), Exchange(), and open().
|
protected |
UDP endpoint.
Definition at line 165 of file client_exchange.h.
Referenced by Exchange(), Exchange(), and open().
|
protected |
Termination handler.
Definition at line 208 of file client_exchange.h.
Referenced by Exchange(), Exchange(), shutdownInternal(), and terminate().
|
protected |
The identifier (random value in hexadecimal).
Definition at line 141 of file client_exchange.h.
Referenced by Exchange(), Exchange(), createIdentifier(), getId(), logReplyMessages(), open(), start(), and terminate().
|
protected |
Current server index.
The current server is either the server indexed by this in the table or when greater than the table size the first postponed server.
Definition at line 177 of file client_exchange.h.
Referenced by Exchange(), Exchange(), and open().
|
protected |
IO service (argument for async or internal for sync).
Definition at line 144 of file client_exchange.h.
Referenced by Exchange(), Exchange(), ~Exchange(), open(), setTimer(), shutdownInternal(), start(), and terminate().
|
protected |
Maximum number of retries for a server.
Definition at line 199 of file client_exchange.h.
Referenced by Exchange(), Exchange(), and open().
|
protected |
State change mutex.
Definition at line 211 of file client_exchange.h.
Referenced by Exchange(), Exchange(), ~Exchange(), shutdown(), start(), and terminate().
|
protected |
List of postponed server indexes.
Definition at line 205 of file client_exchange.h.
Referenced by Exchange(), Exchange(), and open().
|
protected |
Error/return code.
Definition at line 156 of file client_exchange.h.
Referenced by Exchange(), Exchange(), getRC(), open(), start(), and terminate().
|
protected |
Received message.
Definition at line 186 of file client_exchange.h.
Referenced by Exchange(), Exchange(), getResponse(), and logReplyMessages().
|
protected |
Request message.
Definition at line 180 of file client_exchange.h.
Referenced by Exchange(), Exchange(), buildRequest(), and getRequest().
|
protected |
Retry counter.
Definition at line 195 of file client_exchange.h.
Referenced by Exchange(), Exchange(), and open().
|
protected |
Sent message.
Definition at line 183 of file client_exchange.h.
Referenced by Exchange(), Exchange(), buildRequest(), and open().
|
protected |
Current server.
Definition at line 171 of file client_exchange.h.
Referenced by Exchange(), Exchange(), buildRequest(), open(), and setTimer().
|
protected |
Servers (a copy which is what we need).
Definition at line 202 of file client_exchange.h.
Referenced by Exchange(), Exchange(), and open().
|
protected |
Number of transmitted octests;.
Definition at line 192 of file client_exchange.h.
Referenced by Exchange(), Exchange(), and open().
|
protected |
Socket.
Definition at line 162 of file client_exchange.h.
Referenced by Exchange(), Exchange(), ~Exchange(), open(), shutdownInternal(), and terminate().
|
protected |
Start time.
Definition at line 159 of file client_exchange.h.
Referenced by Exchange(), Exchange(), buildRequest(), and open().
|
protected |
Started flag.
Definition at line 150 of file client_exchange.h.
Referenced by Exchange(), Exchange(), and start().
|
protected |
Sync / async flag.
Definition at line 147 of file client_exchange.h.
Referenced by Exchange(), Exchange(), ~Exchange(), shutdownInternal(), start(), and terminate().
|
protected |
Terminated flag.
Definition at line 153 of file client_exchange.h.
Referenced by Exchange(), Exchange(), open(), shutdownInternal(), and terminate().
|
protected |
Interval timer.
Definition at line 168 of file client_exchange.h.
Referenced by Exchange(), Exchange(), ~Exchange(), cancelTimer(), and setTimer().