Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: webrtc/p2p/base/candidate.h

Issue 1668073002: Add network cost as part of the connection comparison. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // A candidate with the maximum cost indicates it should be used only as the
31 // last resort.
32 const uint32_t kMaxNetworkCost = 99;
pthatcher1 2016/02/04 23:16:20 I'd prefer to make this an enum.
honghaiz3 2016/02/05 01:36:46 Acknowledged.
33
30 // Candidate for ICE based connection discovery. 34 // Candidate for ICE based connection discovery.
31 35
32 class Candidate { 36 class Candidate {
33 public: 37 public:
34 // TODO: Match the ordering and param list as per RFC 5245 38 // TODO: Match the ordering and param list as per RFC 5245
35 // candidate-attribute syntax. http://tools.ietf.org/html/rfc5245#section-15.1 39 // candidate-attribute syntax. http://tools.ietf.org/html/rfc5245#section-15.1
36 Candidate() 40 Candidate()
37 : id_(rtc::CreateRandomString(8)), 41 : id_(rtc::CreateRandomString(8)),
38 component_(0), 42 component_(0),
39 priority_(0), 43 priority_(0),
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 const std::string generation_str() const { 135 const std::string generation_str() const {
132 std::ostringstream ost; 136 std::ostringstream ost;
133 ost << generation_; 137 ost << generation_;
134 return ost.str(); 138 return ost.str();
135 } 139 }
136 void set_generation_str(const std::string& str) { 140 void set_generation_str(const std::string& str) {
137 std::istringstream ist(str); 141 std::istringstream ist(str);
138 ist >> generation_; 142 ist >> generation_;
139 } 143 }
140 144
145 // |network_cost| measures the cost/penalty of using this candidate. A cost of
146 // 0 indicates this candidate can be used freely.
147 void set_network_cost(uint32_t network_cost) {
148 ASSERT(network_cost <= kMaxNetworkCost);
149 network_cost_ = network_cost;
150 }
151 uint32_t network_cost() const { return network_cost_; }
152
141 const std::string& foundation() const { 153 const std::string& foundation() const {
142 return foundation_; 154 return foundation_;
143 } 155 }
144 156
145 void set_foundation(const std::string& foundation) { 157 void set_foundation(const std::string& foundation) {
146 foundation_ = foundation; 158 foundation_ = foundation;
147 } 159 }
148 160
149 const rtc::SocketAddress & related_address() const { 161 const rtc::SocketAddress & related_address() const {
150 return related_address_; 162 return related_address_;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 } 219 }
208 220
209 private: 221 private:
210 std::string ToStringInternal(bool sensitive) const { 222 std::string ToStringInternal(bool sensitive) const {
211 std::ostringstream ost; 223 std::ostringstream ost;
212 std::string address = sensitive ? address_.ToSensitiveString() : 224 std::string address = sensitive ? address_.ToSensitiveString() :
213 address_.ToString(); 225 address_.ToString();
214 ost << "Cand[" << foundation_ << ":" << component_ << ":" 226 ost << "Cand[" << foundation_ << ":" << component_ << ":"
215 << protocol_ << ":" << priority_ << ":" 227 << protocol_ << ":" << priority_ << ":"
216 << address << ":" << type_ << ":" << related_address_ << ":" 228 << address << ":" << type_ << ":" << related_address_ << ":"
217 << username_ << ":" << password_ << "]"; 229 << username_ << ":" << password_ << ":" << network_cost_ << "]";
218 return ost.str(); 230 return ost.str();
219 } 231 }
220 232
221 std::string id_; 233 std::string id_;
222 int component_; 234 int component_;
223 std::string protocol_; 235 std::string protocol_;
224 std::string relay_protocol_; 236 std::string relay_protocol_;
225 rtc::SocketAddress address_; 237 rtc::SocketAddress address_;
226 uint32_t priority_; 238 uint32_t priority_;
227 std::string username_; 239 std::string username_;
228 std::string password_; 240 std::string password_;
229 std::string type_; 241 std::string type_;
230 std::string network_name_; 242 std::string network_name_;
231 rtc::AdapterType network_type_; 243 rtc::AdapterType network_type_;
232 uint32_t generation_; 244 uint32_t generation_;
233 std::string foundation_; 245 std::string foundation_;
234 rtc::SocketAddress related_address_; 246 rtc::SocketAddress related_address_;
235 std::string tcptype_; 247 std::string tcptype_;
248 uint32_t network_cost_ = 0;
236 }; 249 };
237 250
238 // Used during parsing and writing to map component to channel name 251 // Used during parsing and writing to map component to channel name
239 // and back. This is primarily for converting old G-ICE candidate 252 // and back. This is primarily for converting old G-ICE candidate
240 // signalling to new ICE candidate classes. 253 // signalling to new ICE candidate classes.
241 class CandidateTranslator { 254 class CandidateTranslator {
242 public: 255 public:
243 virtual ~CandidateTranslator() {} 256 virtual ~CandidateTranslator() {}
244 virtual bool GetChannelNameFromComponent( 257 virtual bool GetChannelNameFromComponent(
245 int component, std::string* channel_name) const = 0; 258 int component, std::string* channel_name) const = 0;
246 virtual bool GetComponentFromChannelName( 259 virtual bool GetComponentFromChannelName(
247 const std::string& channel_name, int* component) const = 0; 260 const std::string& channel_name, int* component) const = 0;
248 }; 261 };
249 262
250 } // namespace cricket 263 } // namespace cricket
251 264
252 #endif // WEBRTC_P2P_BASE_CANDIDATE_H_ 265 #endif // WEBRTC_P2P_BASE_CANDIDATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698