Transaction
Transaction
#include <icy/stun/transaction.h>class TransactionDefined in src/stun/include/icy/stun/transaction.h:31
Inherits:
Transaction< Message >
STUN request/response transaction with timeout and retry logic. Extends the generic net::Transaction with STUN-specific transaction ID matching and response class inference (Success, Error, or Indication).
Lifetime is managed by IntrusivePtr. Create via makeIntrusive or wrap in IntrusivePtr immediately after construction.
List of all members
| Name | Kind | Owner |
|---|---|---|
IntrusivePtr | friend | Declared here |
Transaction | function | Declared here |
checkResponse | function | Declared here |
onResponse | function | Declared here |
~Transaction | function | Declared here |
Ptr | typedef | Declared here |
IntrusivePtr | friend | Inherited from Transaction |
Transaction | function | Inherited from Transaction |
send | function | Inherited from Transaction |
cancel | function | Inherited from Transaction |
dispose | function | Inherited from Transaction |
peerAddress | function | Inherited from Transaction |
_peerAddress | variable | Inherited from Transaction |
~Transaction | function | Inherited from Transaction |
onPacket | function | Inherited from Transaction |
onResponse | function | Inherited from Transaction |
checkResponse | function | Inherited from Transaction |
BaseT | typedef | Inherited from Transaction |
IntrusivePtr | friend | Inherited from PacketTransaction |
PacketTransaction | function | Inherited from PacketTransaction |
PacketTransaction | function | Inherited from PacketTransaction |
send | function | Inherited from PacketTransaction |
cancel | function | Inherited from PacketTransaction |
cancelled | function | Inherited from PacketTransaction |
dispose | function | Inherited from PacketTransaction |
disposed | function | Inherited from PacketTransaction |
canResend | function | Inherited from PacketTransaction |
attempts | function | Inherited from PacketTransaction |
retries | function | Inherited from PacketTransaction |
request | function | Inherited from PacketTransaction |
request | function | Inherited from PacketTransaction |
response | function | Inherited from PacketTransaction |
response | function | Inherited from PacketTransaction |
_request | variable | Inherited from PacketTransaction |
_response | variable | Inherited from PacketTransaction |
_timer | variable | Inherited from PacketTransaction |
_retries | variable | Inherited from PacketTransaction |
_attempts | variable | Inherited from PacketTransaction |
_disposed | variable | Inherited from PacketTransaction |
~PacketTransaction | function | Inherited from PacketTransaction |
onStateChange | function | Inherited from PacketTransaction |
handlePotentialResponse | function | Inherited from PacketTransaction |
checkResponse | function | Inherited from PacketTransaction |
onResponse | function | Inherited from PacketTransaction |
onTimeout | function | Inherited from PacketTransaction |
Ptr | typedef | Inherited from PacketTransaction |
send | function | Inherited from Sendable |
cancel | function | Inherited from Sendable |
StateChange | variable | Inherited from Stateful |
Stateful | function | Inherited from Stateful |
~Stateful | function | Inherited from Stateful |
stateEquals | function | Inherited from Stateful |
stateBetween | function | Inherited from Stateful |
state | function | Inherited from Stateful |
state | function | Inherited from Stateful |
_state | variable | Inherited from Stateful |
beforeStateChange | function | Inherited from Stateful |
onStateChange | function | Inherited from Stateful |
setState | function | Inherited from Stateful |
setState | function | Inherited from Stateful |
RefCounted | function | Inherited from RefCounted |
RefCounted | function | Inherited from RefCounted |
operator= | function | Inherited from RefCounted |
addRef | function | Inherited from RefCounted |
releaseRef | function | Inherited from RefCounted |
refCount | function | Inherited from RefCounted |
~RefCounted | function | Inherited from RefCounted |
_refCount | variable | Inherited from RefCounted |
factory | variable | Inherited from PacketSocketEmitter |
PacketSocketEmitter | function | Inherited from PacketSocketEmitter |
~PacketSocketEmitter | function | Inherited from PacketSocketEmitter |
onSocketRecv | function | Inherited from PacketSocketEmitter |
onPacket | function | Inherited from PacketSocketEmitter |
Connect | variable | Inherited from SocketEmitter |
Recv | variable | Inherited from SocketEmitter |
Error | variable | Inherited from SocketEmitter |
Close | variable | Inherited from SocketEmitter |
impl | variable | Inherited from SocketEmitter |
SocketEmitter | function | Inherited from SocketEmitter |
SocketEmitter | function | Inherited from SocketEmitter |
~SocketEmitter | function | Inherited from SocketEmitter |
addReceiver | function | Inherited from SocketEmitter |
removeReceiver | function | Inherited from SocketEmitter |
swap | function | Inherited from SocketEmitter |
as | function | Inherited from SocketEmitter |
operator-> | function | Inherited from SocketEmitter |
onSocketConnect | function | Inherited from SocketEmitter |
onSocketRecv | function | Inherited from SocketEmitter |
onSocketError | function | Inherited from SocketEmitter |
onSocketClose | function | Inherited from SocketEmitter |
priority | variable | Inherited from SocketAdapter |
SocketAdapter | function | Inherited from SocketAdapter |
~SocketAdapter | function | Inherited from SocketAdapter |
send | function | Inherited from SocketAdapter |
send | function | Inherited from SocketAdapter |
sendOwned | function | Inherited from SocketAdapter |
sendOwned | function | Inherited from SocketAdapter |
sendPacket | function | Inherited from SocketAdapter |
sendPacket | function | Inherited from SocketAdapter |
sendPacket | function | Inherited from SocketAdapter |
setSender | function | Inherited from SocketAdapter |
sender | function | Inherited from SocketAdapter |
addReceiver | function | Inherited from SocketAdapter |
removeReceiver | function | Inherited from SocketAdapter |
hasReceiver | function | Inherited from SocketAdapter |
receivers | function | Inherited from SocketAdapter |
onSocketConnect | function | Inherited from SocketAdapter |
onSocketRecv | function | Inherited from SocketAdapter |
onSocketError | function | Inherited from SocketAdapter |
onSocketClose | function | Inherited from SocketAdapter |
_sender | variable | Inherited from SocketAdapter |
_receivers | variable | Inherited from SocketAdapter |
_dirty | variable | Inherited from SocketAdapter |
cleanupReceivers | function | Inherited from SocketAdapter |
Inherited from Transaction
| Kind | Name | Description |
|---|---|---|
friend | IntrusivePtr | |
function | Transaction inline | Constructs a Transaction on the given socket targeting peerAddress. |
function | send virtual inline override | Sends the request packet to the peer address and starts the timeout timer. Sets state to Failed and returns false if the packet could not be sent. |
function | cancel virtual inline override | Cancels the transaction and stops the timeout timer. |
function | dispose virtual inline override | Stops the timer and unregisters callbacks. |
function | peerAddress const inline | Returns the remote peer address used for this transaction. |
variable | _peerAddress | |
function | ~Transaction virtual | Defaulted destructor. |
function | onPacket virtual inline override | Checks whether packet is a matching response for the pending request. If it matches, the transaction completes; socket data propagation stops. |
function | onResponse virtual inline override | Called when a confirmed response is received; emits the response via PacketSignal. |
function | checkResponse virtual inline override | Returns true if packet is a valid response for this transaction. |
typedef | BaseT |
Inherited from PacketTransaction
| Kind | Name | Description |
|---|---|---|
friend | IntrusivePtr | |
function | PacketTransaction inline | |
function | PacketTransaction inline | |
function | send virtual inline override | Starts the transaction timer and sends the request. Overriding classes should implement send logic here. |
function | cancel virtual inline override | Cancellation means that the agent will not retransmit the request, will not treat the lack of response to be a failure, but will wait the duration of the transaction timeout for a response. Transitions the transaction to the Cancelled state. |
function | cancelled const inline | |
function | dispose virtual inline | Stops the timer and unregisters callbacks. Does NOT delete the object; the IntrusivePtr destructor handles deletion when the last reference is released. Safe to call multiple times. |
function | disposed const inline | |
function | canResend virtual inline | |
function | attempts const inline | |
function | retries const inline | |
function | request inline | |
function | request const inline | |
function | response inline | |
function | response const inline | |
variable | _request | |
variable | _response | |
variable | _timer | The request timeout callback. |
variable | _retries | The maximum number of attempts before the transaction is considered failed. |
variable | _attempts | The number of times the transaction has been sent. |
variable | _disposed | |
function | ~PacketTransaction virtual inline | |
function | onStateChange virtual inline override | Post state change hook. Calls dispose() on terminal states to stop the timer, but does not delete the object; IntrusivePtr handles that. |
function | handlePotentialResponse virtual inline | Processes a potential response candidate and updates the state accordingly. |
function | checkResponse virtual | Checks a potential response candidate and returns true on successful match. |
function | onResponse virtual inline | Called when a successful response is received. |
function | onTimeout virtual inline | Called by the timer when the transaction timeout elapses. Retransmits if retries remain, otherwise transitions to Failed. |
typedef | Ptr |
Inherited from Sendable
| Kind | Name | Description |
|---|---|---|
function | send virtual | Initiates the send operation. |
function | cancel virtual | Cancels a pending send operation. |
Inherited from Stateful
| Kind | Name | Description |
|---|---|---|
variable | StateChange | Signals when the state changes. |
function | Stateful inline | |
function | ~Stateful virtual inline | |
function | stateEquals virtual const inline | Returns true if the current state ID equals the given ID. |
function | stateBetween virtual const inline | Returns true if the current state ID is in the inclusive range [lid, rid]. |
function | state virtual inline | Returns a mutable reference to the current state. |
function | state virtual const inline | Returns a copy of the current state. |
variable | _state | |
function | beforeStateChange virtual inline | Override to handle pre state change logic. Return false to prevent state change. |
function | onStateChange virtual inline | Override to handle post state change logic. |
function | setState virtual inline | Sets the state and sends the state signal if the state change was successful. |
function | setState virtual inline | Sets the state and sends the state signal if the state change was successful. |
Inherited from RefCounted
| Kind | Name | Description |
|---|---|---|
function | RefCounted | Defaulted constructor. |
function | RefCounted inline noexcept | |
function | operator= inline noexcept | |
function | addRef const inline noexcept | Increments the reference count. Called by IntrusivePtr on acquisition. |
function | releaseRef const inline noexcept | Decrements the reference count. |
function | refCount const inline noexcept | Returns the current reference count. |
function | ~RefCounted | Defaulted destructor. |
variable | _refCount |
Inherited from PacketSocketEmitter
| Kind | Name | Description |
|---|---|---|
variable | factory | The packet factory. |
function | PacketSocketEmitter | Creates the PacketSocketEmitter and attaches it to the given socket. |
function | ~PacketSocketEmitter virtual noexcept | |
function | onSocketRecv virtual override | Parses raw received data into packets via the factory and forwards each parsed packet to onPacket(). Returns true if propagation should stop. |
function | onPacket virtual | Process a parsed packet. Returns true to stop propagation. |
Inherited from SocketEmitter
| Kind | Name | Description |
|---|---|---|
variable | Connect | Signals that the socket is connected. |
variable | Recv | Signals when data is received by the socket. |
variable | Error | Signals that the socket is closed in error. This signal will be sent just before the Closed signal. |
variable | Close | Signals that the underlying socket is closed. |
variable | impl | Pointer to the underlying socket. Sent data will be proxied to this socket. |
function | SocketEmitter | Creates the SocketEmitter and optionally attaches it to a socket. If socket is provided, this emitter registers itself as a receiver. |
function | SocketEmitter | Copy constructor; copies all signal connections and attaches to the same socket. |
function | ~SocketEmitter virtual noexcept | Destroys the SocketAdapter. |
function | addReceiver virtual override | Attaches a SocketAdapter as a receiver; wires it to all four socket signals. |
function | removeReceiver virtual override | Detaches a SocketAdapter from all four socket signals. |
function | swap virtual | Replaces the underlying socket with socket. |
function | as inline | Returns the underlying socket cast to type T, or nullptr if the cast fails. |
function | operator-> const inline | Returns a raw pointer to the underlying socket for direct method access. Follows shared_ptr semantics; the caller must not delete the returned pointer. |
function | onSocketConnect virtual override | Forwards the connect event to chained adapters, then fires the Connect signal. |
function | onSocketRecv virtual override | Forwards the recv event to chained adapters, then fires the Recv signal. |
function | onSocketError virtual override | Forwards the error event to chained adapters, then fires the Error signal. |
function | onSocketClose virtual override | Forwards the close event to chained adapters, then fires the Close signal. |
Inherited from SocketAdapter
| Kind | Name | Description |
|---|---|---|
variable | priority | The priority of this adapter for STL sort operations. |
function | SocketAdapter | Creates the SocketAdapter. |
function | ~SocketAdapter virtual noexcept | Destroys the SocketAdapter. |
function | send virtual | Sends the given data buffer to the connected peer. Returns the number of bytes sent or -1 on error. No exception will be thrown. For TCP sockets the given peer address must match the connected peer address. |
function | send virtual | |
function | sendOwned virtual | Sends an owned payload buffer to the connected peer. |
function | sendOwned virtual | |
function | sendPacket virtual | Sends the given packet to the connected peer. Returns the number of bytes sent or -1 on error. No exception will be thrown. For TCP sockets the given peer address must match the connected peer address. |
function | sendPacket virtual | |
function | sendPacket virtual | Sends the given packet to the connected peer. This method provides delegate compatibility, and unlike other send methods throws an exception if the underlying socket is closed. |
function | setSender virtual | Sets the pointer to the outgoing data adapter. Send methods proxy data to this adapter by default. |
function | sender | Returns the output SocketAdapter pointer. |
function | addReceiver virtual | Sets the pointer to the incoming data adapter. Events proxy data to this adapter by default. |
function | removeReceiver virtual | Remove the given receiver. |
function | hasReceiver virtual | Returns true if the given receiver is connected. |
function | receivers | Returns all currently registered input SocketAdapter pointers. Dead (removed) entries are excluded from the returned list. |
function | onSocketConnect virtual | Called when the socket establishes a connection. Forwards the event to all registered receivers in priority order. Override to intercept before the application sees the event. |
function | onSocketRecv virtual | Called when data is received from the socket. Forwards the event to all registered receivers in priority order. |
function | onSocketError virtual | Called when the socket encounters an error. Forwards the event to all registered receivers in priority order. |
function | onSocketClose virtual | Called when the socket is closed. Forwards the event to all registered receivers in priority order. |
variable | _sender | |
variable | _receivers | |
variable | _dirty | |
function | cleanupReceivers virtual |
Friends
| Name | Description |
|---|---|
icy::IntrusivePtr |
icy::IntrusivePtr
template<typename U> friend class icy::IntrusivePtrDefined in src/stun/include/icy/stun/transaction.h:57
Public Methods
| Return | Name | Description |
|---|---|---|
Transaction | Constructs a STUN transaction bound to a specific socket and peer. | |
bool | checkResponse override | Checks that message is a valid response for the pending request. In addition to the base class check, verifies that the transaction IDs match. |
void | onResponse virtual override | Called when a valid response is received. Infers the response class (SuccessResponse, ErrorResponse, or Indication) from the response attributes and delegates to the base class handler. |
Transaction
Transaction(const net::Socket::Ptr & socket, const net::Address & peerAddress, long timeout = 10000, int retries = 1)Defined in src/stun/include/icy/stun/transaction.h:41
Constructs a STUN transaction bound to a specific socket and peer.
Parameters
socketSocket used to send the request and receive the response.peerAddressRemote address of the STUN/TURN server.timeoutResponse timeout in milliseconds (default 10 s).retriesNumber of send retries before declaring failure (default 1).
checkResponse
override
bool checkResponse(const Message & message) overrideDefined in src/stun/include/icy/stun/transaction.h:48
Checks that message is a valid response for the pending request. In addition to the base class check, verifies that the transaction IDs match.
Parameters
messageIncoming STUN message to evaluate.
Returns
true if message is the expected response.
onResponse
virtual override
virtual void onResponse() overrideDefined in src/stun/include/icy/stun/transaction.h:53
Called when a valid response is received. Infers the response class (SuccessResponse, ErrorResponse, or Indication) from the response attributes and delegates to the base class handler.
Reimplements
Public Types
| Name | Description |
|---|---|
Ptr |
Ptr
using Ptr = IntrusivePtr< Transaction >