| 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 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 Candidate() | 36 Candidate() |
| 37 : id_(rtc::CreateRandomString(8)), | 37 : id_(rtc::CreateRandomString(8)), |
| 38 component_(0), | 38 component_(0), |
| 39 priority_(0), | 39 priority_(0), |
| 40 network_type_(rtc::ADAPTER_TYPE_UNKNOWN), | 40 network_type_(rtc::ADAPTER_TYPE_UNKNOWN), |
| 41 generation_(0) {} | 41 generation_(0) {} |
| 42 | 42 |
| 43 Candidate(int component, | 43 Candidate(int component, |
| 44 const std::string& protocol, | 44 const std::string& protocol, |
| 45 const rtc::SocketAddress& address, | 45 const rtc::SocketAddress& address, |
| 46 uint32 priority, | 46 uint32_t priority, |
| 47 const std::string& username, | 47 const std::string& username, |
| 48 const std::string& password, | 48 const std::string& password, |
| 49 const std::string& type, | 49 const std::string& type, |
| 50 uint32 generation, | 50 uint32_t generation, |
| 51 const std::string& foundation) | 51 const std::string& foundation) |
| 52 : id_(rtc::CreateRandomString(8)), | 52 : id_(rtc::CreateRandomString(8)), |
| 53 component_(component), | 53 component_(component), |
| 54 protocol_(protocol), | 54 protocol_(protocol), |
| 55 address_(address), | 55 address_(address), |
| 56 priority_(priority), | 56 priority_(priority), |
| 57 username_(username), | 57 username_(username), |
| 58 password_(password), | 58 password_(password), |
| 59 type_(type), | 59 type_(type), |
| 60 network_type_(rtc::ADAPTER_TYPE_UNKNOWN), | 60 network_type_(rtc::ADAPTER_TYPE_UNKNOWN), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 74 const std::string& relay_protocol() const { return relay_protocol_; } | 74 const std::string& relay_protocol() const { return relay_protocol_; } |
| 75 void set_relay_protocol(const std::string& protocol) { | 75 void set_relay_protocol(const std::string& protocol) { |
| 76 relay_protocol_ = protocol; | 76 relay_protocol_ = protocol; |
| 77 } | 77 } |
| 78 | 78 |
| 79 const rtc::SocketAddress & address() const { return address_; } | 79 const rtc::SocketAddress & address() const { return address_; } |
| 80 void set_address(const rtc::SocketAddress & address) { | 80 void set_address(const rtc::SocketAddress & address) { |
| 81 address_ = address; | 81 address_ = address; |
| 82 } | 82 } |
| 83 | 83 |
| 84 uint32 priority() const { return priority_; } | 84 uint32_t priority() const { return priority_; } |
| 85 void set_priority(const uint32 priority) { priority_ = priority; } | 85 void set_priority(const uint32_t priority) { priority_ = priority; } |
| 86 | 86 |
| 87 // TODO(pthatcher): Remove once Chromium's jingle/glue/utils.cc | 87 // TODO(pthatcher): Remove once Chromium's jingle/glue/utils.cc |
| 88 // doesn't use it. | 88 // doesn't use it. |
| 89 // Maps old preference (which was 0.0-1.0) to match priority (which | 89 // Maps old preference (which was 0.0-1.0) to match priority (which |
| 90 // is 0-2^32-1) to to match RFC 5245, section 4.1.2.1. Also see | 90 // is 0-2^32-1) to to match RFC 5245, section 4.1.2.1. Also see |
| 91 // https://docs.google.com/a/google.com/document/d/ | 91 // https://docs.google.com/a/google.com/document/d/ |
| 92 // 1iNQDiwDKMh0NQOrCqbj3DKKRT0Dn5_5UJYhmZO-t7Uc/edit | 92 // 1iNQDiwDKMh0NQOrCqbj3DKKRT0Dn5_5UJYhmZO-t7Uc/edit |
| 93 float preference() const { | 93 float preference() const { |
| 94 // The preference value is clamped to two decimal precision. | 94 // The preference value is clamped to two decimal precision. |
| 95 return static_cast<float>(((priority_ >> 24) * 100 / 127) / 100.0); | 95 return static_cast<float>(((priority_ >> 24) * 100 / 127) / 100.0); |
| 96 } | 96 } |
| 97 | 97 |
| 98 // TODO(pthatcher): Remove once Chromium's jingle/glue/utils.cc | 98 // TODO(pthatcher): Remove once Chromium's jingle/glue/utils.cc |
| 99 // doesn't use it. | 99 // doesn't use it. |
| 100 void set_preference(float preference) { | 100 void set_preference(float preference) { |
| 101 // Limiting priority to UINT_MAX when value exceeds uint32 max. | 101 // Limiting priority to UINT_MAX when value exceeds uint32_t max. |
| 102 // This can happen for e.g. when preference = 3. | 102 // This can happen for e.g. when preference = 3. |
| 103 uint64 prio_val = static_cast<uint64>(preference * 127) << 24; | 103 uint64_t prio_val = static_cast<uint64_t>(preference * 127) << 24; |
| 104 priority_ = | 104 priority_ = static_cast<uint32_t>( |
| 105 static_cast<uint32>(std::min(prio_val, static_cast<uint64>(UINT_MAX))); | 105 std::min(prio_val, static_cast<uint64_t>(UINT_MAX))); |
| 106 } | 106 } |
| 107 | 107 |
| 108 const std::string & username() const { return username_; } | 108 const std::string & username() const { return username_; } |
| 109 void set_username(const std::string & username) { username_ = username; } | 109 void set_username(const std::string & username) { username_ = username; } |
| 110 | 110 |
| 111 const std::string & password() const { return password_; } | 111 const std::string & password() const { return password_; } |
| 112 void set_password(const std::string & password) { password_ = password; } | 112 void set_password(const std::string & password) { password_ = password; } |
| 113 | 113 |
| 114 const std::string & type() const { return type_; } | 114 const std::string & type() const { return type_; } |
| 115 void set_type(const std::string & type) { type_ = type; } | 115 void set_type(const std::string & type) { type_ = type; } |
| 116 | 116 |
| 117 const std::string & network_name() const { return network_name_; } | 117 const std::string & network_name() const { return network_name_; } |
| 118 void set_network_name(const std::string & network_name) { | 118 void set_network_name(const std::string & network_name) { |
| 119 network_name_ = network_name; | 119 network_name_ = network_name; |
| 120 } | 120 } |
| 121 | 121 |
| 122 rtc::AdapterType network_type() const { return network_type_; } | 122 rtc::AdapterType network_type() const { return network_type_; } |
| 123 void set_network_type(rtc::AdapterType network_type) { | 123 void set_network_type(rtc::AdapterType network_type) { |
| 124 network_type_ = network_type; | 124 network_type_ = network_type; |
| 125 } | 125 } |
| 126 | 126 |
| 127 // Candidates in a new generation replace those in the old generation. | 127 // Candidates in a new generation replace those in the old generation. |
| 128 uint32 generation() const { return generation_; } | 128 uint32_t generation() const { return generation_; } |
| 129 void set_generation(uint32 generation) { generation_ = generation; } | 129 void set_generation(uint32_t generation) { generation_ = generation; } |
| 130 const std::string generation_str() const { | 130 const std::string generation_str() const { |
| 131 std::ostringstream ost; | 131 std::ostringstream ost; |
| 132 ost << generation_; | 132 ost << generation_; |
| 133 return ost.str(); | 133 return ost.str(); |
| 134 } | 134 } |
| 135 void set_generation_str(const std::string& str) { | 135 void set_generation_str(const std::string& str) { |
| 136 std::istringstream ist(str); | 136 std::istringstream ist(str); |
| 137 ist >> generation_; | 137 ist >> generation_; |
| 138 } | 138 } |
| 139 | 139 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 170 } | 170 } |
| 171 | 171 |
| 172 std::string ToString() const { | 172 std::string ToString() const { |
| 173 return ToStringInternal(false); | 173 return ToStringInternal(false); |
| 174 } | 174 } |
| 175 | 175 |
| 176 std::string ToSensitiveString() const { | 176 std::string ToSensitiveString() const { |
| 177 return ToStringInternal(true); | 177 return ToStringInternal(true); |
| 178 } | 178 } |
| 179 | 179 |
| 180 uint32 GetPriority(uint32 type_preference, | 180 uint32_t GetPriority(uint32_t type_preference, |
| 181 int network_adapter_preference, | 181 int network_adapter_preference, |
| 182 int relay_preference) const { | 182 int relay_preference) const { |
| 183 // RFC 5245 - 4.1.2.1. | 183 // RFC 5245 - 4.1.2.1. |
| 184 // priority = (2^24)*(type preference) + | 184 // priority = (2^24)*(type preference) + |
| 185 // (2^8)*(local preference) + | 185 // (2^8)*(local preference) + |
| 186 // (2^0)*(256 - component ID) | 186 // (2^0)*(256 - component ID) |
| 187 | 187 |
| 188 // |local_preference| length is 2 bytes, 0-65535 inclusive. | 188 // |local_preference| length is 2 bytes, 0-65535 inclusive. |
| 189 // In our implemenation we will partion local_preference into | 189 // In our implemenation we will partion local_preference into |
| 190 // 0 1 | 190 // 0 1 |
| 191 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 | 191 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 |
| 192 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 192 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| (...skipping 22 matching lines...) Expand all Loading... |
| 215 << address << ":" << type_ << ":" << related_address_ << ":" | 215 << address << ":" << type_ << ":" << related_address_ << ":" |
| 216 << username_ << ":" << password_ << "]"; | 216 << username_ << ":" << password_ << "]"; |
| 217 return ost.str(); | 217 return ost.str(); |
| 218 } | 218 } |
| 219 | 219 |
| 220 std::string id_; | 220 std::string id_; |
| 221 int component_; | 221 int component_; |
| 222 std::string protocol_; | 222 std::string protocol_; |
| 223 std::string relay_protocol_; | 223 std::string relay_protocol_; |
| 224 rtc::SocketAddress address_; | 224 rtc::SocketAddress address_; |
| 225 uint32 priority_; | 225 uint32_t priority_; |
| 226 std::string username_; | 226 std::string username_; |
| 227 std::string password_; | 227 std::string password_; |
| 228 std::string type_; | 228 std::string type_; |
| 229 std::string network_name_; | 229 std::string network_name_; |
| 230 rtc::AdapterType network_type_; | 230 rtc::AdapterType network_type_; |
| 231 uint32 generation_; | 231 uint32_t generation_; |
| 232 std::string foundation_; | 232 std::string foundation_; |
| 233 rtc::SocketAddress related_address_; | 233 rtc::SocketAddress related_address_; |
| 234 std::string tcptype_; | 234 std::string tcptype_; |
| 235 }; | 235 }; |
| 236 | 236 |
| 237 // Used during parsing and writing to map component to channel name | 237 // Used during parsing and writing to map component to channel name |
| 238 // and back. This is primarily for converting old G-ICE candidate | 238 // and back. This is primarily for converting old G-ICE candidate |
| 239 // signalling to new ICE candidate classes. | 239 // signalling to new ICE candidate classes. |
| 240 class CandidateTranslator { | 240 class CandidateTranslator { |
| 241 public: | 241 public: |
| 242 virtual ~CandidateTranslator() {} | 242 virtual ~CandidateTranslator() {} |
| 243 virtual bool GetChannelNameFromComponent( | 243 virtual bool GetChannelNameFromComponent( |
| 244 int component, std::string* channel_name) const = 0; | 244 int component, std::string* channel_name) const = 0; |
| 245 virtual bool GetComponentFromChannelName( | 245 virtual bool GetComponentFromChannelName( |
| 246 const std::string& channel_name, int* component) const = 0; | 246 const std::string& channel_name, int* component) const = 0; |
| 247 }; | 247 }; |
| 248 | 248 |
| 249 } // namespace cricket | 249 } // namespace cricket |
| 250 | 250 |
| 251 #endif // WEBRTC_P2P_BASE_CANDIDATE_H_ | 251 #endif // WEBRTC_P2P_BASE_CANDIDATE_H_ |
| OLD | NEW |