OpenDDS  Snapshot(2023/04/28-20:55)
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
OpenDDS::ICE::ServerReflexiveStateMachine Class Reference

#include <Ice.h>

Collaboration diagram for OpenDDS::ICE::ServerReflexiveStateMachine:
Collaboration graph
[legend]

Public Types

enum  StateChange { SRSM_None, SRSM_Set, SRSM_Unset, SRSM_Change }
 

Public Member Functions

 ServerReflexiveStateMachine ()
 
StateChange send (const ACE_INET_Addr &address, size_t indication_count_limit, const DCPS::GuidPrefix_t &guid_prefix)
 
StateChange receive (const STUN::Message &message)
 
const STUN::Messagemessage () const
 
const ACE_INET_Addrunset_stun_server_address () const
 
const ACE_INET_Addrstun_server_address () const
 
bool is_response (const STUN::Message &message) const
 
DCPS::TimeDuration latency () const
 
bool latency_available () const
 
void latency_available (bool flag)
 
bool connected () const
 

Private Member Functions

StateChange start (const ACE_INET_Addr &address, size_t indication_count_limit, const DCPS::GuidPrefix_t &guid_prefix)
 
StateChange stop ()
 
StateChange next_send (size_t indication_count_limit, const DCPS::GuidPrefix_t &guid_prefix)
 
StateChange success_response (const STUN::Message &message)
 
StateChange error_response (const STUN::Message &message)
 

Private Attributes

STUN::Class message_class_
 
STUN::Message message_
 
ACE_INET_Addr unset_stun_server_address_
 
ACE_INET_Addr stun_server_address_
 
ACE_INET_Addr server_reflexive_address_
 
size_t send_count_
 
DCPS::MonotonicTimePoint timestamp_
 
DCPS::TimeDuration latency_
 
bool latency_available_
 

Detailed Description

Definition at line 211 of file RTPS/ICE/Ice.h.

Member Enumeration Documentation

◆ StateChange

Constructor & Destructor Documentation

◆ ServerReflexiveStateMachine()

OpenDDS::ICE::ServerReflexiveStateMachine::ServerReflexiveStateMachine ( )
inline

Member Function Documentation

◆ connected()

bool OpenDDS::ICE::ServerReflexiveStateMachine::connected ( ) const
inline

Definition at line 261 of file RTPS/ICE/Ice.h.

◆ error_response()

ServerReflexiveStateMachine::StateChange OpenDDS::ICE::ServerReflexiveStateMachine::error_response ( const STUN::Message message)
private

Definition at line 289 of file Ice.cpp.

References ACE_ERROR, ACE_TEXT(), OpenDDS::STUN::BINDING, OpenDDS::DCPS::DCPS_debug_level, OpenDDS::STUN::Message::get_error_code(), OpenDDS::STUN::Message::get_error_reason(), OpenDDS::STUN::Message::get_unknown_attributes(), OpenDDS::STUN::Message::has_error_code(), OpenDDS::STUN::Message::has_unknown_attributes(), LM_WARNING, OpenDDS::STUN::Message::method, OPENDDS_END_VERSIONED_NAMESPACE_DECL, and OpenDDS::STUN::UNKNOWN_ATTRIBUTE.

290 {
291  if (message.method != STUN::BINDING) {
292  if (DCPS::DCPS_debug_level > 0) {
293  ACE_ERROR((LM_WARNING,
294  ACE_TEXT("(%P|%t) ServerReflexiveStateMachine::error_response: "
295  "WARNING Unsupported STUN method\n")));
296  }
297  return SRSM_None;
298  }
299 
300 
301  if (!message.has_error_code()) {
302  if (DCPS::DCPS_debug_level > 0) {
303  ACE_ERROR((LM_WARNING, ACE_TEXT("(%P|%t) ServerReflexiveStateMachine::error_response: "
304  "WARNING No error code\n")));
305  }
306  return SRSM_None;
307  }
308 
309  if (DCPS::DCPS_debug_level > 0) {
310  ACE_ERROR((LM_WARNING,
311  ACE_TEXT("(%P|%t) ServerReflexiveStateMachine::error_response: "
312  "WARNING STUN error response code=%d reason=%C\n"),
314  message.get_error_reason().c_str()));
315 
317  std::vector<STUN::AttributeType> unknown_attributes = message.get_unknown_attributes();
318 
319  for (std::vector<STUN::AttributeType>::const_iterator pos = unknown_attributes.begin(),
320  limit = unknown_attributes.end(); pos != limit; ++pos) {
321  ACE_ERROR((LM_WARNING,
322  ACE_TEXT("(%P|%t) ServerReflexiveStateMachine::error_response: "
323  "WARNING Unknown STUN attribute %d\n"),
324  *pos));
325  }
326  }
327  }
328 
329  return SRSM_None;
330 }
#define ACE_ERROR(X)
std::vector< AttributeType > get_unknown_attributes() const
Definition: Stun.cpp:786
const ACE_UINT16 UNKNOWN_ATTRIBUTE
Definition: Stun.h:53
bool has_unknown_attributes() const
Definition: Stun.cpp:775
ACE_UINT16 get_error_code() const
Definition: Stun.cpp:753
const STUN::Message & message() const
Definition: RTPS/ICE/Ice.h:237
bool has_error_code() const
Definition: Stun.cpp:742
ACE_TEXT("TCP_Factory")
OpenDDS_Dcps_Export unsigned int DCPS_debug_level
Definition: debug.cpp:30
std::string get_error_reason() const
Definition: Stun.cpp:764

◆ is_response()

bool OpenDDS::ICE::ServerReflexiveStateMachine::is_response ( const STUN::Message message) const
inline

Definition at line 241 of file RTPS/ICE/Ice.h.

References OpenDDS::STUN::Message::transaction_id.

Referenced by OpenDDS::RTPS::Spdp::SpdpTransport::handle_input().

242  {
244  }
const STUN::Message & message() const
Definition: RTPS/ICE/Ice.h:237
TransactionId transaction_id
Definition: Stun.h:186

◆ latency()

DCPS::TimeDuration OpenDDS::ICE::ServerReflexiveStateMachine::latency ( void  ) const
inline

◆ latency_available() [1/2]

bool OpenDDS::ICE::ServerReflexiveStateMachine::latency_available ( ) const
inline

◆ latency_available() [2/2]

void OpenDDS::ICE::ServerReflexiveStateMachine::latency_available ( bool  flag)
inline

Definition at line 256 of file RTPS/ICE/Ice.h.

257  {
258  latency_available_ = flag;
259  }

◆ message()

const STUN::Message& OpenDDS::ICE::ServerReflexiveStateMachine::message ( void  ) const
inline

◆ next_send()

ServerReflexiveStateMachine::StateChange OpenDDS::ICE::ServerReflexiveStateMachine::next_send ( size_t  indication_count_limit,
const DCPS::GuidPrefix_t guid_prefix 
)
private

Definition at line 209 of file Ice.cpp.

References OpenDDS::STUN::BINDING, OpenDDS::STUN::INDICATION, OpenDDS::STUN::make_fingerprint(), OpenDDS::STUN::make_guid_prefix(), and OpenDDS::STUN::REQUEST.

211 {
212  StateChange retval = SRSM_None;
213 
214  if (message_class_ == STUN::REQUEST &&
216  send_count_ == indication_count_limit) {
217  // Reset.
218  retval = SRSM_Unset;
221  }
222 
223  // indication_count_limit is offset by 1 to account for sending the request.
225  (message_class_ == STUN::INDICATION && send_count_ >= indication_count_limit + 1)) {
227  send_count_ = 0;
228  }
229 
230  message_ = STUN::Message();
236 
237  ++send_count_;
238 
239  return retval;
240 }
OpenDDS_Rtps_Export Attribute make_guid_prefix(const DCPS::GuidPrefix_t &guid_prefix)
Definition: Stun.cpp:163
void generate_transaction_id()
Definition: Stun.cpp:606
Attribute make_fingerprint()
Definition: Stun.cpp:139
void append_attribute(const Attribute &attribute)
Definition: Stun.h:195

◆ receive()

ServerReflexiveStateMachine::StateChange OpenDDS::ICE::ServerReflexiveStateMachine::receive ( const STUN::Message message)

Definition at line 156 of file Ice.cpp.

References ACE_ERROR, ACE_TEXT(), OpenDDS::STUN::Message::class_, OpenDDS::STUN::ERROR_RESPONSE, OpenDDS::STUN::INDICATION, LM_WARNING, OpenDDS::DCPS::TimePoint_T< MonotonicClock >::now(), OpenDDS::STUN::REQUEST, and OpenDDS::STUN::SUCCESS_RESPONSE.

Referenced by OpenDDS::RTPS::Spdp::SpdpTransport::handle_input().

157 {
159  latency_available_ = true;
160 
161  switch (message.class_) {
163  return success_response(message);
164 
166  return error_response(message);
167 
168  case STUN::REQUEST:
169  case STUN::INDICATION:
170  ACE_ERROR((LM_WARNING, ACE_TEXT("(%P|%t) ServerReflexiveStateMachine::receive: WARNING Unsupported STUN message class %d\n"), message.class_));
171  return SRSM_None;
172  }
173 
174  ACE_ERROR((LM_WARNING, ACE_TEXT("(%P|%t) ServerReflexiveStateMachine::receive: WARNING Unknown STUN message class %d\n"), message.class_));
175  return SRSM_None;
176 }
#define ACE_ERROR(X)
StateChange error_response(const STUN::Message &message)
Definition: Ice.cpp:289
StateChange success_response(const STUN::Message &message)
Definition: Ice.cpp:243
static TimePoint_T< MonotonicClock > now()
Definition: TimePoint_T.inl:41
const STUN::Message & message() const
Definition: RTPS/ICE/Ice.h:237
ACE_TEXT("TCP_Factory")

◆ send()

ServerReflexiveStateMachine::StateChange OpenDDS::ICE::ServerReflexiveStateMachine::send ( const ACE_INET_Addr address,
size_t  indication_count_limit,
const DCPS::GuidPrefix_t guid_prefix 
)

Definition at line 128 of file Ice.cpp.

References OpenDDS::DCPS::TimePoint_T< MonotonicClock >::now().

Referenced by OpenDDS::DCPS::RtpsUdpTransport::relay_stun_task(), and OpenDDS::RTPS::Spdp::SpdpTransport::relay_stun_task().

131 {
133 
135  address == ACE_INET_Addr()) {
136  // Do nothing.
137  return SRSM_None;
138  } else if (stun_server_address_ == ACE_INET_Addr() &&
139  address != ACE_INET_Addr()) {
140  return start(address, indication_count_limit, guid_prefix);
141  } else if (stun_server_address_ != ACE_INET_Addr() &&
142  address == ACE_INET_Addr()) {
143  return stop();
144  } else {
145  if (stun_server_address_ != address) {
146  const StateChange retval = stop();
147  start(address, indication_count_limit, guid_prefix);
148  return retval;
149  } else {
150  return next_send(indication_count_limit, guid_prefix);
151  }
152  }
153 }
StateChange start(const ACE_INET_Addr &address, size_t indication_count_limit, const DCPS::GuidPrefix_t &guid_prefix)
Definition: Ice.cpp:179
StateChange next_send(size_t indication_count_limit, const DCPS::GuidPrefix_t &guid_prefix)
Definition: Ice.cpp:209
static TimePoint_T< MonotonicClock > now()
Definition: TimePoint_T.inl:41

◆ start()

ServerReflexiveStateMachine::StateChange OpenDDS::ICE::ServerReflexiveStateMachine::start ( const ACE_INET_Addr address,
size_t  indication_count_limit,
const DCPS::GuidPrefix_t guid_prefix 
)
private

Definition at line 179 of file Ice.cpp.

References OPENDDS_ASSERT, and OpenDDS::STUN::REQUEST.

182 {
183  OPENDDS_ASSERT(address != ACE_INET_Addr());
185 
186  // Send a binding request.
188  send_count_ = 0;
189 
190  stun_server_address_ = address;
192 
193  return next_send(indication_count_limit, guid_prefix);
194 }
StateChange next_send(size_t indication_count_limit, const DCPS::GuidPrefix_t &guid_prefix)
Definition: Ice.cpp:209
#define OPENDDS_ASSERT(C)
Definition: Definitions.h:72

◆ stop()

ServerReflexiveStateMachine::StateChange OpenDDS::ICE::ServerReflexiveStateMachine::stop ( void  )
private

◆ stun_server_address()

const ACE_INET_Addr& OpenDDS::ICE::ServerReflexiveStateMachine::stun_server_address ( ) const
inline

◆ success_response()

ServerReflexiveStateMachine::StateChange OpenDDS::ICE::ServerReflexiveStateMachine::success_response ( const STUN::Message message)
private

Definition at line 243 of file Ice.cpp.

References ACE_ERROR, ACE_TEXT(), OpenDDS::DCPS::DCPS_debug_level, OpenDDS::STUN::Message::get_mapped_address(), OpenDDS::STUN::INDICATION, LM_WARNING, and OpenDDS::STUN::Message::unknown_comprehension_required_attributes().

244 {
245  std::vector<STUN::AttributeType> unknown_attributes = message.unknown_comprehension_required_attributes();
246 
247  if (!unknown_attributes.empty()) {
248  if (DCPS::DCPS_debug_level > 0) {
249  ACE_ERROR((LM_WARNING,
250  ACE_TEXT("(%P|%t) ServerReflexiveStateMachine::success_response: "
251  "WARNING Unknown comprehension required attributes\n")));
252  }
253  return SRSM_None;
254  }
255 
256  ACE_INET_Addr server_reflexive_address;
257 
258  if (!message.get_mapped_address(server_reflexive_address)) {
259  if (DCPS::DCPS_debug_level > 0) {
260  ACE_ERROR((LM_WARNING,
261  ACE_TEXT("(%P|%t) ServerReflexiveStateMachine::success_response: "
262  "WARNING No (XOR)_MAPPED_ADDRESS attribute\n")));
263  }
264  return SRSM_None;
265  }
266 
267  if (server_reflexive_address == ACE_INET_Addr()) {
268  if (DCPS::DCPS_debug_level > 0) {
269  ACE_ERROR((LM_WARNING,
270  ACE_TEXT("(%P|%t) ServerReflexiveStateMachine::success_response: "
271  "WARNING (XOR)_MAPPED_ADDRESS is not valid\n")));
272  }
273  return SRSM_None;
274  }
275 
277  if (server_reflexive_address == server_reflexive_address_) {
278  return SRSM_None;
279  } else if (server_reflexive_address_ == ACE_INET_Addr()) {
280  server_reflexive_address_ = server_reflexive_address;
281  return SRSM_Set;
282  } else {
283  server_reflexive_address_ = server_reflexive_address;
284  return SRSM_Change;
285  }
286 }
#define ACE_ERROR(X)
bool get_mapped_address(ACE_INET_Addr &address) const
Definition: Stun.cpp:643
const STUN::Message & message() const
Definition: RTPS/ICE/Ice.h:237
ACE_TEXT("TCP_Factory")
OpenDDS_Dcps_Export unsigned int DCPS_debug_level
Definition: debug.cpp:30
std::vector< AttributeType > unknown_comprehension_required_attributes() const
Definition: Stun.cpp:616

◆ unset_stun_server_address()

const ACE_INET_Addr& OpenDDS::ICE::ServerReflexiveStateMachine::unset_stun_server_address ( ) const
inline

Member Data Documentation

◆ latency_

DCPS::TimeDuration OpenDDS::ICE::ServerReflexiveStateMachine::latency_
private

Definition at line 280 of file RTPS/ICE/Ice.h.

◆ latency_available_

bool OpenDDS::ICE::ServerReflexiveStateMachine::latency_available_
private

Definition at line 281 of file RTPS/ICE/Ice.h.

◆ message_

STUN::Message OpenDDS::ICE::ServerReflexiveStateMachine::message_
private

Definition at line 274 of file RTPS/ICE/Ice.h.

◆ message_class_

STUN::Class OpenDDS::ICE::ServerReflexiveStateMachine::message_class_
private

Definition at line 273 of file RTPS/ICE/Ice.h.

◆ send_count_

size_t OpenDDS::ICE::ServerReflexiveStateMachine::send_count_
private

Definition at line 278 of file RTPS/ICE/Ice.h.

◆ server_reflexive_address_

ACE_INET_Addr OpenDDS::ICE::ServerReflexiveStateMachine::server_reflexive_address_
private

Definition at line 277 of file RTPS/ICE/Ice.h.

◆ stun_server_address_

ACE_INET_Addr OpenDDS::ICE::ServerReflexiveStateMachine::stun_server_address_
private

Definition at line 276 of file RTPS/ICE/Ice.h.

◆ timestamp_

DCPS::MonotonicTimePoint OpenDDS::ICE::ServerReflexiveStateMachine::timestamp_
private

Definition at line 279 of file RTPS/ICE/Ice.h.

◆ unset_stun_server_address_

ACE_INET_Addr OpenDDS::ICE::ServerReflexiveStateMachine::unset_stun_server_address_
private

Definition at line 275 of file RTPS/ICE/Ice.h.


The documentation for this class was generated from the following files: