OpenDDS  Snapshot(2021/10/17-20:09)
RTPS/ICE/Ice.h
Go to the documentation of this file.
1 /*
2  *
3  *
4  * Distributed under the OpenDDS License.
5  * See: http://www.opendds.org/license.html
6  */
7 
8 #ifdef OPENDDS_SECURITY
9 #ifndef OPENDDS_DCPS_RTPS_ICE_ICE_H
10 #define OPENDDS_DCPS_RTPS_ICE_ICE_H
11 
12 #include "dds/DCPS/Ice.h"
13 #include "Stun.h"
14 #include "dds/DCPS/TimeTypes.h"
15 
16 #if !defined (ACE_LACKS_PRAGMA_ONCE)
17 #pragma once
18 #endif /* ACE_LACKS_PRAGMA_ONCE */
19 
21 
22 namespace OpenDDS {
23 namespace ICE {
24 
25 typedef OPENDDS_VECTOR(ACE_INET_Addr) AddressListType;
26 
27 bool candidates_equal(const Candidate& x, const Candidate& y);
28 bool candidates_sorted(const Candidate& x, const Candidate& y);
29 
30 ACE_UINT32 local_priority(const ACE_INET_Addr& addr);
31 
32 Candidate make_host_candidate(const ACE_INET_Addr& address);
33 Candidate make_server_reflexive_candidate(const ACE_INET_Addr& address, const ACE_INET_Addr& base, const ACE_INET_Addr& server_address);
34 Candidate make_peer_reflexive_candidate(const ACE_INET_Addr& address, const ACE_INET_Addr& base, const ACE_INET_Addr& server_address, ACE_UINT32 priority);
35 Candidate make_peer_reflexive_candidate(const ACE_INET_Addr& address, ACE_UINT32 priority, size_t q);
36 
40 
41  GuidPair(const DCPS::RepoId& a_local, const DCPS::RepoId& a_remote) : local(a_local), remote(a_remote) {}
42 
43  bool operator<(const GuidPair& a_other) const
44  {
45  if (DCPS::GUID_tKeyLessThan()(this->local, a_other.local)) return true;
46 
47  if (DCPS::GUID_tKeyLessThan()(a_other.local, this->local)) return false;
48 
49  if (DCPS::GUID_tKeyLessThan()(this->remote, a_other.remote)) return true;
50 
51  if (DCPS::GUID_tKeyLessThan()(a_other.remote, this->remote)) return false;
52 
53  return false;
54  }
55 };
56 
57 typedef std::set<GuidPair> GuidSetType;
58 
60 public:
61  virtual ~Endpoint() {}
62  virtual AddressListType host_addresses() const = 0;
63  virtual void send(const ACE_INET_Addr& address, const STUN::Message& message) = 0;
64  virtual ACE_INET_Addr stun_server_address() const = 0;
65  virtual void ice_connect(const GuidSetType&, const ACE_INET_Addr&) {}
66  virtual void ice_disconnect(const GuidSetType&, const ACE_INET_Addr&) {}
67 };
68 
70 public:
71  virtual ~AgentInfoListener() {}
72  virtual void update_agent_info(const DCPS::RepoId& a_local_guid,
73  const AgentInfo& a_agent_info) = 0;
74  virtual void remove_agent_info(const DCPS::RepoId& a_local_guid) = 0;
75 };
76 
78 public:
80  T_a_(0, 50000),
81  connectivity_check_ttl_(5 * 60),
82  checklist_period_(10),
83  indication_period_(15),
84  nominated_ttl_(5 * 60),
85  server_reflexive_address_period_(30),
86  server_reflexive_indication_count_(10),
87  deferred_triggered_check_ttl_(5 * 60),
88  change_password_period_(5 * 60)
89  {}
90 
91  void T_a(const DCPS::TimeDuration& x)
92  {
93  T_a_ = x;
94  }
96  {
97  return T_a_;
98  }
99 
101  {
102  connectivity_check_ttl_ = x;
103  }
105  {
106  return connectivity_check_ttl_;
107  }
108 
110  {
111  checklist_period_ = x;
112  }
114  {
115  return checklist_period_;
116  }
117 
119  {
120  indication_period_ = x;
121  }
123  {
124  return indication_period_;
125  }
126 
128  {
129  nominated_ttl_ = x;
130  }
132  {
133  return nominated_ttl_;
134  }
135 
137  {
138  server_reflexive_address_period_ = x;
139  }
141  {
142  return server_reflexive_address_period_;
143  }
144 
146  {
147  server_reflexive_indication_count_ = x;
148  }
150  {
151  return server_reflexive_indication_count_;
152  }
153 
155  {
156  deferred_triggered_check_ttl_ = x;
157  }
159  {
160  return deferred_triggered_check_ttl_;
161  }
162 
164  {
165  change_password_period_ = x;
166  }
168  {
169  return change_password_period_;
170  }
171 
172  static Configuration* instance();
173 
174 private:
175  // Mininum time between consecutive sends.
176  // RFC 8445 Section 14.2
178  // Repeat a check for this long before failing it.
180  // Run all of the ordinary checks in a checklist in this amount of time.
182  // Send an indication at this interval once an address is selected.
184  // The nominated pair will still be valid if an indication has been received within this amount of time.
186  // Perform server-reflexive candidate gathering this often.
188  // Send this many binding indications to the STUN server before sending a binding request.
190  // Lifetime of a deferred triggered check.
192  // Change the password this often.
194 };
195 
197 public:
198  virtual ~Agent() {}
199  virtual void add_endpoint(Endpoint* a_endpoint) = 0;
200  virtual void remove_endpoint(Endpoint* a_endpoint) = 0;
201  virtual AgentInfo get_local_agent_info(Endpoint* a_endpoint) const = 0;
202  virtual void add_local_agent_info_listener(Endpoint* a_endpoint,
203  const DCPS::RepoId& a_local_guid,
204  AgentInfoListener* a_agent_info_listener) = 0;
205  virtual void remove_local_agent_info_listener(Endpoint* a_endpoint,
206  const DCPS::RepoId& a_local_guid) = 0;
207  virtual void start_ice(Endpoint* a_endpoint,
208  const DCPS::RepoId& a_local_guid,
209  const DCPS::RepoId& a_remote_guid,
210  const AgentInfo& a_remote_agent_info) = 0;
211  virtual void stop_ice(Endpoint* a_endpoint,
212  const DCPS::RepoId& a_local_guid,
213  const DCPS::RepoId& a_remote_guid) = 0;
214  virtual ACE_INET_Addr get_address(Endpoint* a_endpoint,
215  const DCPS::RepoId& a_local_guid,
216  const DCPS::RepoId& a_remote_guid) const = 0;
217 
218  // Receive a STUN message.
219  virtual void receive(Endpoint* a_endpoint,
220  const ACE_INET_Addr& a_local_address,
221  const ACE_INET_Addr& a_remote_address,
222  const STUN::Message& a_message) = 0;
223 
224  virtual void shutdown() = 0;
225 
226  static Agent* instance();
227 };
228 
230 public:
231  enum StateChange {
235  SRSM_Change
236  };
237 
239  : message_class_(STUN::REQUEST)
240  , send_count_(0)
241  {}
242 
243  // Return Unset if transitioning from a determined SRA to an undetermined SRA.
244  // Return None otherwise.
245  StateChange send(const ACE_INET_Addr& address,
246  size_t indication_count_limit,
247  const DCPS::GuidPrefix_t& guid_prefix);
248 
249  // Return Set if transitioning from an undetermined SRA to a determined SRA.
250  // Return Change if transitioning from a determined SRA to a different SRA.
251  // Return None otherwise.
252  StateChange receive(const STUN::Message& message);
253 
254  const STUN::Message& message() const { return message_; }
255  const ACE_INET_Addr& unset_stun_server_address() const { return unset_stun_server_address_; }
256  const ACE_INET_Addr& stun_server_address() const { return stun_server_address_; }
257 
258  bool is_response(const STUN::Message& message) const
259  {
260  return message.transaction_id == message_.transaction_id;
261  }
262 
263 private:
264  StateChange start(const ACE_INET_Addr& address, size_t indication_count_limit, const DCPS::GuidPrefix_t& guid_prefix);
265  StateChange stop();
266  StateChange next_send(size_t indication_count_limit, const DCPS::GuidPrefix_t& guid_prefix);
267  StateChange success_response(const STUN::Message& message);
268  StateChange error_response(const STUN::Message& message);
269 
275  size_t send_count_;
276  };
277 
278 } // namespace ICE
279 } // namespace OpenDDS
280 
282 
283 #endif /* OPENDDS_RTPS_ICE_H */
284 #endif /* OPENDDS_SECURITY */
const STUN::Message & message() const
Definition: RTPS/ICE/Ice.h:254
bool is_response(const STUN::Message &message) const
Definition: RTPS/ICE/Ice.h:258
DCPS::TimeDuration connectivity_check_ttl() const
Definition: RTPS/ICE/Ice.h:104
DCPS::TimeDuration change_password_period_
Definition: RTPS/ICE/Ice.h:193
Candidate make_host_candidate(const ACE_INET_Addr &address)
Definition: Ice.cpp:64
DCPS::TimeDuration checklist_period_
Definition: RTPS/ICE/Ice.h:181
size_t server_reflexive_indication_count() const
Definition: RTPS/ICE/Ice.h:149
ACE_UINT32 local_priority(const ACE_INET_Addr &addr)
Definition: Ice.cpp:56
Candidate make_server_reflexive_candidate(const ACE_INET_Addr &address, const ACE_INET_Addr &base, const ACE_INET_Addr &server_address)
Definition: Ice.cpp:76
TransactionId transaction_id
Definition: Stun.h:185
ssize_t send(ACE_HANDLE handle, const void *buf, size_t len, int flags, const ACE_Time_Value *timeout=0)
std::set< GuidPair > GuidSetType
Definition: RTPS/ICE/Ice.h:57
void nominated_ttl(const DCPS::TimeDuration &x)
Definition: RTPS/ICE/Ice.h:127
DCPS::TimeDuration change_password_period() const
Definition: RTPS/ICE/Ice.h:167
DCPS::TimeDuration T_a() const
Definition: RTPS/ICE/Ice.h:95
void T_a(const DCPS::TimeDuration &x)
Definition: RTPS/ICE/Ice.h:91
typedef OPENDDS_VECTOR(ACE_INET_Addr) AddressListType
octet GuidPrefix_t[12]
Definition: DdsDcpsGuid.idl:19
bool candidates_equal(const Candidate &x, const Candidate &y)
Definition: Ice.cpp:34
void server_reflexive_address_period(const DCPS::TimeDuration &x)
Definition: RTPS/ICE/Ice.h:136
virtual void ice_connect(const GuidSetType &, const ACE_INET_Addr &)
Definition: RTPS/ICE/Ice.h:65
GuidPair(const DCPS::RepoId &a_local, const DCPS::RepoId &a_remote)
Definition: RTPS/ICE/Ice.h:41
DCPS::TimeDuration deferred_triggered_check_ttl() const
Definition: RTPS/ICE/Ice.h:158
DCPS::TimeDuration connectivity_check_ttl_
Definition: RTPS/ICE/Ice.h:179
void server_reflexive_indication_count(size_t x)
Definition: RTPS/ICE/Ice.h:145
DCPS::TimeDuration indication_period() const
Definition: RTPS/ICE/Ice.h:122
DCPS::TimeDuration T_a_
Definition: RTPS/ICE/Ice.h:177
bool operator<(const GuidPair &a_other) const
Definition: RTPS/ICE/Ice.h:43
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
DCPS::TimeDuration nominated_ttl_
Definition: RTPS/ICE/Ice.h:185
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:27
DCPS::TimeDuration indication_period_
Definition: RTPS/ICE/Ice.h:183
void change_password_period(const DCPS::TimeDuration &x)
Definition: RTPS/ICE/Ice.h:163
#define OpenDDS_Rtps_Export
Definition: rtps_export.h:23
DCPS::TimeDuration server_reflexive_address_period() const
Definition: RTPS/ICE/Ice.h:140
const ACE_INET_Addr & unset_stun_server_address() const
Definition: RTPS/ICE/Ice.h:255
DCPS::TimeDuration deferred_triggered_check_ttl_
Definition: RTPS/ICE/Ice.h:191
void deferred_triggered_check_ttl(const DCPS::TimeDuration &x)
Definition: RTPS/ICE/Ice.h:154
void checklist_period(const DCPS::TimeDuration &x)
Definition: RTPS/ICE/Ice.h:109
virtual void ice_disconnect(const GuidSetType &, const ACE_INET_Addr &)
Definition: RTPS/ICE/Ice.h:66
DCPS::TimeDuration checklist_period() const
Definition: RTPS/ICE/Ice.h:113
void indication_period(const DCPS::TimeDuration &x)
Definition: RTPS/ICE/Ice.h:118
const ACE_INET_Addr & stun_server_address() const
Definition: RTPS/ICE/Ice.h:256
DCPS::TimeDuration server_reflexive_address_period_
Definition: RTPS/ICE/Ice.h:187
int shutdown(ACE_HANDLE handle, int how)
DCPS::TimeDuration nominated_ttl() const
Definition: RTPS/ICE/Ice.h:131
void connectivity_check_ttl(const DCPS::TimeDuration &x)
Definition: RTPS/ICE/Ice.h:100
Candidate make_peer_reflexive_candidate(const ACE_INET_Addr &address, const ACE_INET_Addr &base, const ACE_INET_Addr &server_address, ACE_UINT32 priority)
Definition: Ice.cpp:88
bool candidates_sorted(const Candidate &x, const Candidate &y)
Definition: Ice.cpp:21