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

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

Issue 1434603002: Schedule a CreatePermissionRequest after the success of a previous request (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years, 1 month 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 2012 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2012 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 TurnEntry(TurnPort* port, int channel_id, 134 TurnEntry(TurnPort* port, int channel_id,
135 const rtc::SocketAddress& ext_addr); 135 const rtc::SocketAddress& ext_addr);
136 136
137 TurnPort* port() { return port_; } 137 TurnPort* port() { return port_; }
138 138
139 int channel_id() const { return channel_id_; } 139 int channel_id() const { return channel_id_; }
140 const rtc::SocketAddress& address() const { return ext_addr_; } 140 const rtc::SocketAddress& address() const { return ext_addr_; }
141 BindState state() const { return state_; } 141 BindState state() const { return state_; }
142 142
143 // Helper methods to send permission and channel bind requests. 143 // Helper methods to send permission and channel bind requests.
144 void SendCreatePermissionRequest(); 144 void SendCreatePermissionRequest(int delay);
145 void SendChannelBindRequest(int delay); 145 void SendChannelBindRequest(int delay);
146 // Sends a packet to the given destination address. 146 // Sends a packet to the given destination address.
147 // This will wrap the packet in STUN if necessary. 147 // This will wrap the packet in STUN if necessary.
148 int Send(const void* data, size_t size, bool payload, 148 int Send(const void* data, size_t size, bool payload,
149 const rtc::PacketOptions& options); 149 const rtc::PacketOptions& options);
150 150
151 void OnCreatePermissionSuccess(); 151 void OnCreatePermissionSuccess();
152 void OnCreatePermissionError(StunMessage* response, int code); 152 void OnCreatePermissionError(StunMessage* response, int code);
153 void OnChannelBindSuccess(); 153 void OnChannelBindSuccess();
154 void OnChannelBindError(StunMessage* response, int code); 154 void OnChannelBindError(StunMessage* response, int code);
(...skipping 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 entry_ = NULL; 1282 entry_ = NULL;
1283 } 1283 }
1284 1284
1285 TurnEntry::TurnEntry(TurnPort* port, int channel_id, 1285 TurnEntry::TurnEntry(TurnPort* port, int channel_id,
1286 const rtc::SocketAddress& ext_addr) 1286 const rtc::SocketAddress& ext_addr)
1287 : port_(port), 1287 : port_(port),
1288 channel_id_(channel_id), 1288 channel_id_(channel_id),
1289 ext_addr_(ext_addr), 1289 ext_addr_(ext_addr),
1290 state_(STATE_UNBOUND) { 1290 state_(STATE_UNBOUND) {
1291 // Creating permission for |ext_addr_|. 1291 // Creating permission for |ext_addr_|.
1292 SendCreatePermissionRequest(); 1292 SendCreatePermissionRequest(0);
1293 } 1293 }
1294 1294
1295 void TurnEntry::SendCreatePermissionRequest() { 1295 void TurnEntry::SendCreatePermissionRequest(int delay) {
1296 port_->SendRequest(new TurnCreatePermissionRequest( 1296 port_->SendRequest(new TurnCreatePermissionRequest(port_, this, ext_addr_),
1297 port_, this, ext_addr_), 0); 1297 delay);
1298 } 1298 }
pthatcher1 2015/11/11 20:22:09 To make it a little more readable, can you make tw
honghaiz3 2015/11/11 23:51:58 Of course I can, but using a delay parameter for b
pthatcher1 2015/11/12 00:21:08 Good point. Feel free to leave it.
1299 1299
1300 void TurnEntry::SendChannelBindRequest(int delay) { 1300 void TurnEntry::SendChannelBindRequest(int delay) {
1301 port_->SendRequest(new TurnChannelBindRequest( 1301 port_->SendRequest(new TurnChannelBindRequest(
1302 port_, this, channel_id_, ext_addr_), delay); 1302 port_, this, channel_id_, ext_addr_), delay);
1303 } 1303 }
1304 1304
1305 int TurnEntry::Send(const void* data, size_t size, bool payload, 1305 int TurnEntry::Send(const void* data, size_t size, bool payload,
1306 const rtc::PacketOptions& options) { 1306 const rtc::PacketOptions& options) {
1307 rtc::ByteBuffer buf; 1307 rtc::ByteBuffer buf;
1308 if (state_ != STATE_BOUND) { 1308 if (state_ != STATE_BOUND) {
(...skipping 21 matching lines...) Expand all
1330 } 1330 }
1331 return port_->Send(buf.Data(), buf.Length(), options); 1331 return port_->Send(buf.Data(), buf.Length(), options);
1332 } 1332 }
1333 1333
1334 void TurnEntry::OnCreatePermissionSuccess() { 1334 void TurnEntry::OnCreatePermissionSuccess() {
1335 LOG_J(LS_INFO, port_) << "Create permission for " 1335 LOG_J(LS_INFO, port_) << "Create permission for "
1336 << ext_addr_.ToSensitiveString() 1336 << ext_addr_.ToSensitiveString()
1337 << " succeeded"; 1337 << " succeeded";
1338 // For success result code will be 0. 1338 // For success result code will be 0.
1339 port_->SignalCreatePermissionResult(port_, ext_addr_, 0); 1339 port_->SignalCreatePermissionResult(port_, ext_addr_, 0);
1340
1341 // If |state_| is STATE_BINDING or STATE_BOUND, the permission is refreshed
1342 // by ChannelBindRequest.
pthatcher1 2015/11/11 20:22:09 If we are STATE_BINDING and the ChannelBindRequest
honghaiz3 2015/11/11 23:51:58 Done
1343 if (state_ == STATE_UNBOUND) {
1344 SendCreatePermissionRequest(TURN_PERMISSION_TIMEOUT - 60000);
pthatcher1 2015/11/11 20:22:09 Can you explain the 60000, or make it a named cons
honghaiz3 2015/11/11 23:51:58 Added comments.
1345 }
1340 } 1346 }
1341 1347
1342 void TurnEntry::OnCreatePermissionError(StunMessage* response, int code) { 1348 void TurnEntry::OnCreatePermissionError(StunMessage* response, int code) {
1343 if (code == STUN_ERROR_STALE_NONCE) { 1349 if (code == STUN_ERROR_STALE_NONCE) {
1344 if (port_->UpdateNonce(response)) { 1350 if (port_->UpdateNonce(response)) {
1345 SendCreatePermissionRequest(); 1351 SendCreatePermissionRequest(0);
1346 } 1352 }
1347 } else { 1353 } else {
1348 // Send signal with error code. 1354 // Send signal with error code.
1349 port_->SignalCreatePermissionResult(port_, ext_addr_, code); 1355 port_->SignalCreatePermissionResult(port_, ext_addr_, code);
1350 } 1356 }
1351 } 1357 }
1352 1358
1353 void TurnEntry::OnChannelBindSuccess() { 1359 void TurnEntry::OnChannelBindSuccess() {
1354 LOG_J(LS_INFO, port_) << "Channel bind for " << ext_addr_.ToSensitiveString() 1360 LOG_J(LS_INFO, port_) << "Channel bind for " << ext_addr_.ToSensitiveString()
1355 << " succeeded"; 1361 << " succeeded";
1356 ASSERT(state_ == STATE_BINDING || state_ == STATE_BOUND); 1362 ASSERT(state_ == STATE_BINDING || state_ == STATE_BOUND);
1357 state_ = STATE_BOUND; 1363 state_ = STATE_BOUND;
1358 } 1364 }
1359 1365
1360 void TurnEntry::OnChannelBindError(StunMessage* response, int code) { 1366 void TurnEntry::OnChannelBindError(StunMessage* response, int code) {
1361 // TODO(mallinath) - Implement handling of error response for channel 1367 // TODO(mallinath) - Implement handling of error response for channel
1362 // bind request as per http://tools.ietf.org/html/rfc5766#section-11.3 1368 // bind request as per http://tools.ietf.org/html/rfc5766#section-11.3
1363 if (code == STUN_ERROR_STALE_NONCE) { 1369 if (code == STUN_ERROR_STALE_NONCE) {
1364 if (port_->UpdateNonce(response)) { 1370 if (port_->UpdateNonce(response)) {
1365 // Send channel bind request with fresh nonce. 1371 // Send channel bind request with fresh nonce.
1366 SendChannelBindRequest(0); 1372 SendChannelBindRequest(0);
1367 } 1373 }
1368 } 1374 }
1369 } 1375 }
1370 1376
1371 } // namespace cricket 1377 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698