OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_P2P_BASE_CANDIDATE_H_ | 11 #ifndef WEBRTC_P2P_BASE_CANDIDATE_H_ |
12 #define WEBRTC_P2P_BASE_CANDIDATE_H_ | 12 #define WEBRTC_P2P_BASE_CANDIDATE_H_ |
13 | 13 |
14 #include <limits.h> | 14 #include <limits.h> |
15 #include <math.h> | 15 #include <math.h> |
16 | 16 |
17 #include <algorithm> | 17 #include <algorithm> |
18 #include <iomanip> | 18 #include <iomanip> |
19 #include <sstream> | 19 #include <sstream> |
20 #include <string> | 20 #include <string> |
21 | 21 |
22 #include "webrtc/p2p/base/p2pconstants.h" | 22 #include "webrtc/p2p/base/p2pconstants.h" |
23 #include "webrtc/base/basictypes.h" | 23 #include "webrtc/base/basictypes.h" |
24 #include "webrtc/base/helpers.h" | 24 #include "webrtc/base/helpers.h" |
25 #include "webrtc/base/network.h" | 25 #include "webrtc/base/network.h" |
26 #include "webrtc/base/socketaddress.h" | 26 #include "webrtc/base/socketaddress.h" |
27 | 27 |
28 namespace cricket { | 28 namespace cricket { |
29 | 29 |
30 const uint32_t kMaxNetworkCost = 999; | 30 const uint16_t kMaxNetworkCost = 999; |
31 | 31 |
32 // Candidate for ICE based connection discovery. | 32 // Candidate for ICE based connection discovery. |
33 | 33 |
34 class Candidate { | 34 class Candidate { |
35 public: | 35 public: |
36 // TODO: Match the ordering and param list as per RFC 5245 | 36 // TODO: Match the ordering and param list as per RFC 5245 |
37 // candidate-attribute syntax. http://tools.ietf.org/html/rfc5245#section-15.1 | 37 // candidate-attribute syntax. http://tools.ietf.org/html/rfc5245#section-15.1 |
38 Candidate() | 38 Candidate() |
39 : id_(rtc::CreateRandomString(8)), | 39 : id_(rtc::CreateRandomString(8)), |
40 component_(0), | 40 component_(0), |
41 priority_(0), | 41 priority_(0), |
42 network_type_(rtc::ADAPTER_TYPE_UNKNOWN), | 42 network_type_(rtc::ADAPTER_TYPE_UNKNOWN), |
43 generation_(0) {} | 43 generation_(0), |
| 44 network_id_(0), |
| 45 network_cost_(0) {} |
44 | 46 |
45 Candidate(int component, | 47 Candidate(int component, |
46 const std::string& protocol, | 48 const std::string& protocol, |
47 const rtc::SocketAddress& address, | 49 const rtc::SocketAddress& address, |
48 uint32_t priority, | 50 uint32_t priority, |
49 const std::string& username, | 51 const std::string& username, |
50 const std::string& password, | 52 const std::string& password, |
51 const std::string& type, | 53 const std::string& type, |
52 uint32_t generation, | 54 uint32_t generation, |
53 const std::string& foundation) | 55 const std::string& foundation, |
| 56 uint16_t network_id = 0, |
| 57 uint16_t network_cost = 0) |
54 : id_(rtc::CreateRandomString(8)), | 58 : id_(rtc::CreateRandomString(8)), |
55 component_(component), | 59 component_(component), |
56 protocol_(protocol), | 60 protocol_(protocol), |
57 address_(address), | 61 address_(address), |
58 priority_(priority), | 62 priority_(priority), |
59 username_(username), | 63 username_(username), |
60 password_(password), | 64 password_(password), |
61 type_(type), | 65 type_(type), |
62 network_type_(rtc::ADAPTER_TYPE_UNKNOWN), | 66 network_type_(rtc::ADAPTER_TYPE_UNKNOWN), |
63 generation_(generation), | 67 generation_(generation), |
64 foundation_(foundation) {} | 68 foundation_(foundation), |
| 69 network_id_(network_id), |
| 70 network_cost_(network_cost) {} |
65 | 71 |
66 const std::string & id() const { return id_; } | 72 const std::string & id() const { return id_; } |
67 void set_id(const std::string & id) { id_ = id; } | 73 void set_id(const std::string & id) { id_ = id; } |
68 | 74 |
69 int component() const { return component_; } | 75 int component() const { return component_; } |
70 void set_component(int component) { component_ = component; } | 76 void set_component(int component) { component_ = component; } |
71 | 77 |
72 const std::string & protocol() const { return protocol_; } | 78 const std::string & protocol() const { return protocol_; } |
73 void set_protocol(const std::string & protocol) { protocol_ = protocol; } | 79 void set_protocol(const std::string & protocol) { protocol_ = protocol; } |
74 | 80 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 return ost.str(); | 142 return ost.str(); |
137 } | 143 } |
138 void set_generation_str(const std::string& str) { | 144 void set_generation_str(const std::string& str) { |
139 std::istringstream ist(str); | 145 std::istringstream ist(str); |
140 ist >> generation_; | 146 ist >> generation_; |
141 } | 147 } |
142 | 148 |
143 // |network_cost| measures the cost/penalty of using this candidate. A network | 149 // |network_cost| measures the cost/penalty of using this candidate. A network |
144 // cost of 0 indicates this candidate can be used freely. A value of | 150 // cost of 0 indicates this candidate can be used freely. A value of |
145 // |kMaxNetworkCost| indicates it should be used only as the last resort. | 151 // |kMaxNetworkCost| indicates it should be used only as the last resort. |
146 void set_network_cost(uint32_t network_cost) { | 152 void set_network_cost(uint16_t network_cost) { |
147 ASSERT(network_cost <= kMaxNetworkCost); | 153 ASSERT(network_cost <= kMaxNetworkCost); |
148 network_cost_ = network_cost; | 154 network_cost_ = network_cost; |
149 } | 155 } |
150 uint32_t network_cost() const { return network_cost_; } | 156 uint16_t network_cost() const { return network_cost_; } |
| 157 |
| 158 // An ID assigned to the network hosting the candidate. |
| 159 uint16_t network_id() const { return network_id_; } |
| 160 void set_network_id(uint16_t network_id) { network_id_ = network_id; } |
151 | 161 |
152 const std::string& foundation() const { | 162 const std::string& foundation() const { |
153 return foundation_; | 163 return foundation_; |
154 } | 164 } |
155 | 165 |
156 void set_foundation(const std::string& foundation) { | 166 void set_foundation(const std::string& foundation) { |
157 foundation_ = foundation; | 167 foundation_ = foundation; |
158 } | 168 } |
159 | 169 |
160 const rtc::SocketAddress & related_address() const { | 170 const rtc::SocketAddress & related_address() const { |
(...skipping 10 matching lines...) Expand all Loading... |
171 | 181 |
172 // The name of the transport channel of this candidate. | 182 // The name of the transport channel of this candidate. |
173 const std::string& transport_name() const { return transport_name_; } | 183 const std::string& transport_name() const { return transport_name_; } |
174 void set_transport_name(const std::string& transport_name) { | 184 void set_transport_name(const std::string& transport_name) { |
175 transport_name_ = transport_name; | 185 transport_name_ = transport_name; |
176 } | 186 } |
177 | 187 |
178 // Determines whether this candidate is equivalent to the given one. | 188 // Determines whether this candidate is equivalent to the given one. |
179 bool IsEquivalent(const Candidate& c) const { | 189 bool IsEquivalent(const Candidate& c) const { |
180 // We ignore the network name, since that is just debug information, and | 190 // We ignore the network name, since that is just debug information, and |
181 // the priority, since that should be the same if the rest is (and it's | 191 // the priority and the network cost, since they should be the same if the |
182 // a float so equality checking is always worrisome). | 192 // rest are. |
183 return (component_ == c.component_) && (protocol_ == c.protocol_) && | 193 return (component_ == c.component_) && (protocol_ == c.protocol_) && |
184 (address_ == c.address_) && (username_ == c.username_) && | 194 (address_ == c.address_) && (username_ == c.username_) && |
185 (password_ == c.password_) && (type_ == c.type_) && | 195 (password_ == c.password_) && (type_ == c.type_) && |
186 (generation_ == c.generation_) && (foundation_ == c.foundation_) && | 196 (generation_ == c.generation_) && (foundation_ == c.foundation_) && |
187 (related_address_ == c.related_address_); | 197 (related_address_ == c.related_address_) && |
| 198 (network_id_ == c.network_id_); |
188 } | 199 } |
189 | 200 |
190 // Determines whether this candidate can be considered equivalent to the | 201 // Determines whether this candidate can be considered equivalent to the |
191 // given one when looking for a matching candidate to remove. | 202 // given one when looking for a matching candidate to remove. |
192 bool MatchesForRemoval(const Candidate& c) const { | 203 bool MatchesForRemoval(const Candidate& c) const { |
193 return component_ == c.component_ && protocol_ == c.protocol_ && | 204 return component_ == c.component_ && protocol_ == c.protocol_ && |
194 address_ == c.address_; | 205 address_ == c.address_; |
195 } | 206 } |
196 | 207 |
197 std::string ToString() const { | 208 std::string ToString() const { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 } | 242 } |
232 | 243 |
233 private: | 244 private: |
234 std::string ToStringInternal(bool sensitive) const { | 245 std::string ToStringInternal(bool sensitive) const { |
235 std::ostringstream ost; | 246 std::ostringstream ost; |
236 std::string address = sensitive ? address_.ToSensitiveString() : | 247 std::string address = sensitive ? address_.ToSensitiveString() : |
237 address_.ToString(); | 248 address_.ToString(); |
238 ost << "Cand[" << transport_name_ << ":" << foundation_ << ":" << component_ | 249 ost << "Cand[" << transport_name_ << ":" << foundation_ << ":" << component_ |
239 << ":" << protocol_ << ":" << priority_ << ":" << address << ":" | 250 << ":" << protocol_ << ":" << priority_ << ":" << address << ":" |
240 << type_ << ":" << related_address_ << ":" << username_ << ":" | 251 << type_ << ":" << related_address_ << ":" << username_ << ":" |
241 << password_ << ":" << network_cost_ << "]"; | 252 << password_ << ":" << network_id_ << ":" << network_cost_ << "]"; |
242 return ost.str(); | 253 return ost.str(); |
243 } | 254 } |
244 | 255 |
245 std::string id_; | 256 std::string id_; |
246 int component_; | 257 int component_; |
247 std::string protocol_; | 258 std::string protocol_; |
248 std::string relay_protocol_; | 259 std::string relay_protocol_; |
249 rtc::SocketAddress address_; | 260 rtc::SocketAddress address_; |
250 uint32_t priority_; | 261 uint32_t priority_; |
251 std::string username_; | 262 std::string username_; |
252 std::string password_; | 263 std::string password_; |
253 std::string type_; | 264 std::string type_; |
254 std::string network_name_; | 265 std::string network_name_; |
255 rtc::AdapterType network_type_; | 266 rtc::AdapterType network_type_; |
256 uint32_t generation_; | 267 uint32_t generation_; |
257 std::string foundation_; | 268 std::string foundation_; |
258 rtc::SocketAddress related_address_; | 269 rtc::SocketAddress related_address_; |
259 std::string tcptype_; | 270 std::string tcptype_; |
260 uint32_t network_cost_ = 0; | |
261 std::string transport_name_; | 271 std::string transport_name_; |
| 272 uint16_t network_id_; |
| 273 uint16_t network_cost_; |
262 }; | 274 }; |
263 | 275 |
264 // Used during parsing and writing to map component to channel name | 276 // Used during parsing and writing to map component to channel name |
265 // and back. This is primarily for converting old G-ICE candidate | 277 // and back. This is primarily for converting old G-ICE candidate |
266 // signalling to new ICE candidate classes. | 278 // signalling to new ICE candidate classes. |
267 class CandidateTranslator { | 279 class CandidateTranslator { |
268 public: | 280 public: |
269 virtual ~CandidateTranslator() {} | 281 virtual ~CandidateTranslator() {} |
270 virtual bool GetChannelNameFromComponent( | 282 virtual bool GetChannelNameFromComponent( |
271 int component, std::string* channel_name) const = 0; | 283 int component, std::string* channel_name) const = 0; |
272 virtual bool GetComponentFromChannelName( | 284 virtual bool GetComponentFromChannelName( |
273 const std::string& channel_name, int* component) const = 0; | 285 const std::string& channel_name, int* component) const = 0; |
274 }; | 286 }; |
275 | 287 |
276 } // namespace cricket | 288 } // namespace cricket |
277 | 289 |
278 #endif // WEBRTC_P2P_BASE_CANDIDATE_H_ | 290 #endif // WEBRTC_P2P_BASE_CANDIDATE_H_ |
OLD | NEW |