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

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
« no previous file with comments | « webrtc/p2p/base/turnport.h ('k') | webrtc/p2p/base/turnport_unittest.cc » ('j') | 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 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 }
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;
(...skipping 22 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_BOUND, the permission will be refreshed
1342 // by ChannelBindRequest.
1343 if (state_ != STATE_BOUND) {
1344 // Refresh the permission request about 1 minute before the permission
1345 // times out.
1346 int delay = TURN_PERMISSION_TIMEOUT - 60000;
1347 SendCreatePermissionRequest(delay);
1348 LOG_J(LS_INFO, port_) << "Scheduled create-permission-request in "
1349 << delay << "ms.";
1350 }
1340 } 1351 }
1341 1352
1342 void TurnEntry::OnCreatePermissionError(StunMessage* response, int code) { 1353 void TurnEntry::OnCreatePermissionError(StunMessage* response, int code) {
1343 if (code == STUN_ERROR_STALE_NONCE) { 1354 if (code == STUN_ERROR_STALE_NONCE) {
1344 if (port_->UpdateNonce(response)) { 1355 if (port_->UpdateNonce(response)) {
1345 SendCreatePermissionRequest(); 1356 SendCreatePermissionRequest(0);
1346 } 1357 }
1347 } else { 1358 } else {
1348 // Send signal with error code. 1359 // Send signal with error code.
1349 port_->SignalCreatePermissionResult(port_, ext_addr_, code); 1360 port_->SignalCreatePermissionResult(port_, ext_addr_, code);
1350 } 1361 }
1351 } 1362 }
1352 1363
1353 void TurnEntry::OnChannelBindSuccess() { 1364 void TurnEntry::OnChannelBindSuccess() {
1354 LOG_J(LS_INFO, port_) << "Channel bind for " << ext_addr_.ToSensitiveString() 1365 LOG_J(LS_INFO, port_) << "Channel bind for " << ext_addr_.ToSensitiveString()
1355 << " succeeded"; 1366 << " succeeded";
1356 ASSERT(state_ == STATE_BINDING || state_ == STATE_BOUND); 1367 ASSERT(state_ == STATE_BINDING || state_ == STATE_BOUND);
1357 state_ = STATE_BOUND; 1368 state_ = STATE_BOUND;
1358 } 1369 }
1359 1370
1360 void TurnEntry::OnChannelBindError(StunMessage* response, int code) { 1371 void TurnEntry::OnChannelBindError(StunMessage* response, int code) {
1361 // TODO(mallinath) - Implement handling of error response for channel 1372 // TODO(mallinath) - Implement handling of error response for channel
1362 // bind request as per http://tools.ietf.org/html/rfc5766#section-11.3 1373 // bind request as per http://tools.ietf.org/html/rfc5766#section-11.3
1363 if (code == STUN_ERROR_STALE_NONCE) { 1374 if (code == STUN_ERROR_STALE_NONCE) {
1364 if (port_->UpdateNonce(response)) { 1375 if (port_->UpdateNonce(response)) {
1365 // Send channel bind request with fresh nonce. 1376 // Send channel bind request with fresh nonce.
1366 SendChannelBindRequest(0); 1377 SendChannelBindRequest(0);
1367 } 1378 }
1368 } 1379 }
1369 } 1380 }
1370 1381
1371 } // namespace cricket 1382 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/base/turnport.h ('k') | webrtc/p2p/base/turnport_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698