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/constants.h" | 22 #include "webrtc/p2p/base/constants.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 = 0xFFFF; | |
pthatcher1
2016/02/12 00:07:12
Can we make it something that is going to look rea
honghaiz3
2016/02/12 19:28:43
Changed to 999. (digit 9 is a better convention to
pthatcher1
2016/02/12 20:05:26
Sounds good.
| |
31 | |
30 // Candidate for ICE based connection discovery. | 32 // Candidate for ICE based connection discovery. |
31 | 33 |
32 class Candidate { | 34 class Candidate { |
33 public: | 35 public: |
34 // TODO: Match the ordering and param list as per RFC 5245 | 36 // TODO: Match the ordering and param list as per RFC 5245 |
35 // 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 |
36 Candidate() | 38 Candidate() |
37 : id_(rtc::CreateRandomString(8)), | 39 : id_(rtc::CreateRandomString(8)), |
38 component_(0), | 40 component_(0), |
39 priority_(0), | 41 priority_(0), |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 const std::string generation_str() const { | 133 const std::string generation_str() const { |
132 std::ostringstream ost; | 134 std::ostringstream ost; |
133 ost << generation_; | 135 ost << generation_; |
134 return ost.str(); | 136 return ost.str(); |
135 } | 137 } |
136 void set_generation_str(const std::string& str) { | 138 void set_generation_str(const std::string& str) { |
137 std::istringstream ist(str); | 139 std::istringstream ist(str); |
138 ist >> generation_; | 140 ist >> generation_; |
139 } | 141 } |
140 | 142 |
143 // |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 | |
145 // |kMaxNetworkCost| indicates it should be used only as the last resort. | |
146 void set_network_cost(uint32_t network_cost) { | |
147 ASSERT(network_cost <= kMaxNetworkCost); | |
148 network_cost_ = network_cost; | |
149 } | |
150 uint32_t network_cost() const { return network_cost_; } | |
151 | |
141 const std::string& foundation() const { | 152 const std::string& foundation() const { |
142 return foundation_; | 153 return foundation_; |
143 } | 154 } |
144 | 155 |
145 void set_foundation(const std::string& foundation) { | 156 void set_foundation(const std::string& foundation) { |
146 foundation_ = foundation; | 157 foundation_ = foundation; |
147 } | 158 } |
148 | 159 |
149 const rtc::SocketAddress & related_address() const { | 160 const rtc::SocketAddress & related_address() const { |
150 return related_address_; | 161 return related_address_; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 return (type_preference << 24) | | 215 return (type_preference << 24) | |
205 (local_preference << 8) | | 216 (local_preference << 8) | |
206 (256 - component_); | 217 (256 - component_); |
207 } | 218 } |
208 | 219 |
209 private: | 220 private: |
210 std::string ToStringInternal(bool sensitive) const { | 221 std::string ToStringInternal(bool sensitive) const { |
211 std::ostringstream ost; | 222 std::ostringstream ost; |
212 std::string address = sensitive ? address_.ToSensitiveString() : | 223 std::string address = sensitive ? address_.ToSensitiveString() : |
213 address_.ToString(); | 224 address_.ToString(); |
214 ost << "Cand[" << foundation_ << ":" << component_ << ":" | 225 ost << "Cand[" << foundation_ << ":" << component_ << ":" << protocol_ |
215 << protocol_ << ":" << priority_ << ":" | 226 << ":" << priority_ << ":" << address << ":" << type_ << ":" |
216 << address << ":" << type_ << ":" << related_address_ << ":" | 227 << related_address_ << ":" << username_ << ":" << password_ << ":" |
217 << username_ << ":" << password_ << "]"; | 228 << network_cost_ << "]"; |
218 return ost.str(); | 229 return ost.str(); |
219 } | 230 } |
220 | 231 |
221 std::string id_; | 232 std::string id_; |
222 int component_; | 233 int component_; |
223 std::string protocol_; | 234 std::string protocol_; |
224 std::string relay_protocol_; | 235 std::string relay_protocol_; |
225 rtc::SocketAddress address_; | 236 rtc::SocketAddress address_; |
226 uint32_t priority_; | 237 uint32_t priority_; |
227 std::string username_; | 238 std::string username_; |
228 std::string password_; | 239 std::string password_; |
229 std::string type_; | 240 std::string type_; |
230 std::string network_name_; | 241 std::string network_name_; |
231 rtc::AdapterType network_type_; | 242 rtc::AdapterType network_type_; |
232 uint32_t generation_; | 243 uint32_t generation_; |
233 std::string foundation_; | 244 std::string foundation_; |
234 rtc::SocketAddress related_address_; | 245 rtc::SocketAddress related_address_; |
235 std::string tcptype_; | 246 std::string tcptype_; |
247 uint32_t network_cost_ = 0; | |
236 }; | 248 }; |
237 | 249 |
238 // Used during parsing and writing to map component to channel name | 250 // Used during parsing and writing to map component to channel name |
239 // and back. This is primarily for converting old G-ICE candidate | 251 // and back. This is primarily for converting old G-ICE candidate |
240 // signalling to new ICE candidate classes. | 252 // signalling to new ICE candidate classes. |
241 class CandidateTranslator { | 253 class CandidateTranslator { |
242 public: | 254 public: |
243 virtual ~CandidateTranslator() {} | 255 virtual ~CandidateTranslator() {} |
244 virtual bool GetChannelNameFromComponent( | 256 virtual bool GetChannelNameFromComponent( |
245 int component, std::string* channel_name) const = 0; | 257 int component, std::string* channel_name) const = 0; |
246 virtual bool GetComponentFromChannelName( | 258 virtual bool GetComponentFromChannelName( |
247 const std::string& channel_name, int* component) const = 0; | 259 const std::string& channel_name, int* component) const = 0; |
248 }; | 260 }; |
249 | 261 |
250 } // namespace cricket | 262 } // namespace cricket |
251 | 263 |
252 #endif // WEBRTC_P2P_BASE_CANDIDATE_H_ | 264 #endif // WEBRTC_P2P_BASE_CANDIDATE_H_ |
OLD | NEW |