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

Side by Side Diff: webrtc/p2p/base/relayserver.cc

Issue 1848083002: Change the size of the ICE ufrag to 4 bytes (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: git status Created 4 years, 8 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
« no previous file with comments | « webrtc/p2p/base/p2pconstants.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "webrtc/p2p/base/relayserver.h" 11 #include "webrtc/p2p/base/relayserver.h"
12 12
13 #ifdef WEBRTC_POSIX 13 #ifdef WEBRTC_POSIX
14 #include <errno.h> 14 #include <errno.h>
15 #endif // WEBRTC_POSIX 15 #endif // WEBRTC_POSIX
16 16
17 #include <algorithm> 17 #include <algorithm>
18 18
19 #include "webrtc/base/asynctcpsocket.h" 19 #include "webrtc/base/asynctcpsocket.h"
20 #include "webrtc/base/helpers.h" 20 #include "webrtc/base/helpers.h"
21 #include "webrtc/base/logging.h" 21 #include "webrtc/base/logging.h"
22 #include "webrtc/base/socketadapters.h" 22 #include "webrtc/base/socketadapters.h"
23 23
24 namespace cricket { 24 namespace cricket {
25 25
26 // By default, we require a ping every 90 seconds. 26 // By default, we require a ping every 90 seconds.
27 const int MAX_LIFETIME = 15 * 60 * 1000; 27 const int MAX_LIFETIME = 15 * 60 * 1000;
28 28
29 // The number of bytes in each of the usernames we use.
30 const uint32_t USERNAME_LENGTH = 16;
31
32 // Calls SendTo on the given socket and logs any bad results. 29 // Calls SendTo on the given socket and logs any bad results.
33 void Send(rtc::AsyncPacketSocket* socket, const char* bytes, size_t size, 30 void Send(rtc::AsyncPacketSocket* socket, const char* bytes, size_t size,
34 const rtc::SocketAddress& addr) { 31 const rtc::SocketAddress& addr) {
35 rtc::PacketOptions options; 32 rtc::PacketOptions options;
36 int result = socket->SendTo(bytes, size, addr, options); 33 int result = socket->SendTo(bytes, size, addr, options);
37 if (result < static_cast<int>(size)) { 34 if (result < static_cast<int>(size)) {
38 LOG(LS_ERROR) << "SendTo wrote only " << result << " of " << size 35 LOG(LS_ERROR) << "SendTo wrote only " << result << " of " << size
39 << " bytes"; 36 << " bytes";
40 } else if (result < 0) { 37 } else if (result < 0) {
41 LOG_ERR(LS_ERROR) << "SendTo"; 38 LOG_ERR(LS_ERROR) << "SendTo";
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 } 253 }
257 254
258 // The initial packet should have a username (which identifies the binding). 255 // The initial packet should have a username (which identifies the binding).
259 const StunByteStringAttribute* username_attr = 256 const StunByteStringAttribute* username_attr =
260 msg.GetByteString(STUN_ATTR_USERNAME); 257 msg.GetByteString(STUN_ATTR_USERNAME);
261 if (!username_attr) { 258 if (!username_attr) {
262 LOG(LS_WARNING) << "Dropping packet: no username"; 259 LOG(LS_WARNING) << "Dropping packet: no username";
263 return; 260 return;
264 } 261 }
265 262
266 uint32_t length = 263 uint32_t length = static_cast<uint32_t>(username_attr->length());
267 std::min(static_cast<uint32_t>(username_attr->length()), USERNAME_LENGTH);
268 std::string username(username_attr->bytes(), length); 264 std::string username(username_attr->bytes(), length);
265 // The username is the substring before colon in username_attr
266 std::string::size_type colonpos = username.find(':');
267 if (colonpos != std::string::npos) {
268 username = username.substr(0, colonpos);
pthatcher1 2016/05/05 18:07:19 I don't think this is correct. The place where we
Zhi Huang 2016/05/05 18:27:09 The reason I made these changes is some unit tests
pthatcher1 2016/05/05 20:24:31 I don't see why a length of 9 would cause this cod
Zhi Huang 2016/05/05 23:10:59 I changed code like this: const uint32_t USERNAME
pthatcher1 2016/05/09 23:59:25 uint32_t length = static_cast<uint32_t>(username_a
269 }
269 // TODO: Check the HMAC. 270 // TODO: Check the HMAC.
270
271 // The binding should already be present. 271 // The binding should already be present.
272 BindingMap::iterator biter = bindings_.find(username); 272 BindingMap::iterator biter = bindings_.find(username);
273 if (biter == bindings_.end()) { 273 if (biter == bindings_.end()) {
274 LOG(LS_WARNING) << "Dropping packet: no binding with username"; 274 LOG(LS_WARNING) << "Dropping packet: no binding with username";
275 return; 275 return;
276 } 276 }
277 277
278 // Add this authenticted connection to the binding. 278 // Add this authenticted connection to the binding.
279 RelayServerConnection* ext_conn = 279 RelayServerConnection* ext_conn =
280 new RelayServerConnection(biter->second, ap, socket); 280 new RelayServerConnection(biter->second, ap, socket);
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 } else { 741 } else {
742 server_->thread()->PostDelayed(lifetime_, this, MSG_LIFETIME_TIMER); 742 server_->thread()->PostDelayed(lifetime_, this, MSG_LIFETIME_TIMER);
743 } 743 }
744 744
745 } else { 745 } else {
746 ASSERT(false); 746 ASSERT(false);
747 } 747 }
748 } 748 }
749 749
750 } // namespace cricket 750 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/base/p2pconstants.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698