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

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

Issue 1350523003: TransportController refactoring. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing Mac test. Created 5 years, 3 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/p2ptransportchannel.h ('k') | webrtc/p2p/base/p2ptransportchannel_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 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/p2ptransportchannel.h" 11 #include "webrtc/p2p/base/p2ptransportchannel.h"
12 12
13 #include <set> 13 #include <set>
14 #include <algorithm>
14 #include "webrtc/p2p/base/common.h" 15 #include "webrtc/p2p/base/common.h"
15 #include "webrtc/p2p/base/relayport.h" // For RELAY_PORT_TYPE. 16 #include "webrtc/p2p/base/relayport.h" // For RELAY_PORT_TYPE.
16 #include "webrtc/p2p/base/stunport.h" // For STUN_PORT_TYPE. 17 #include "webrtc/p2p/base/stunport.h" // For STUN_PORT_TYPE.
17 #include "webrtc/base/common.h" 18 #include "webrtc/base/common.h"
18 #include "webrtc/base/crc32.h" 19 #include "webrtc/base/crc32.h"
19 #include "webrtc/base/logging.h" 20 #include "webrtc/base/logging.h"
20 #include "webrtc/base/stringencode.h" 21 #include "webrtc/base/stringencode.h"
21 22
22 namespace { 23 namespace {
23 24
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 if (prefs_cmp > 0) 163 if (prefs_cmp > 0)
163 return false; 164 return false;
164 165
165 return b_conn->rtt() <= a_conn->rtt() + kMinImprovement; 166 return b_conn->rtt() <= a_conn->rtt() + kMinImprovement;
166 } 167 }
167 168
168 } // unnamed namespace 169 } // unnamed namespace
169 170
170 namespace cricket { 171 namespace cricket {
171 172
172 P2PTransportChannel::P2PTransportChannel(const std::string& content_name, 173 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name,
173 int component, 174 int component,
174 P2PTransport* transport, 175 P2PTransport* transport,
175 PortAllocator *allocator) : 176 PortAllocator* allocator)
176 TransportChannelImpl(content_name, component), 177 : TransportChannelImpl(transport_name, component),
177 transport_(transport), 178 transport_(transport),
178 allocator_(allocator), 179 allocator_(allocator),
179 worker_thread_(rtc::Thread::Current()), 180 worker_thread_(rtc::Thread::Current()),
180 incoming_only_(false), 181 incoming_only_(false),
181 waiting_for_signaling_(false), 182 error_(0),
182 error_(0), 183 best_connection_(NULL),
183 best_connection_(NULL), 184 pending_best_connection_(NULL),
184 pending_best_connection_(NULL), 185 sort_dirty_(false),
185 sort_dirty_(false), 186 was_writable_(false),
186 was_writable_(false), 187 remote_ice_mode_(ICEMODE_FULL),
187 remote_ice_mode_(ICEMODE_FULL), 188 ice_role_(ICEROLE_UNKNOWN),
188 ice_role_(ICEROLE_UNKNOWN), 189 tiebreaker_(0),
189 tiebreaker_(0), 190 remote_candidate_generation_(0),
190 remote_candidate_generation_(0), 191 gathering_state_(kIceGatheringNew),
191 check_receiving_delay_(MIN_CHECK_RECEIVING_DELAY * 5), 192 check_receiving_delay_(MIN_CHECK_RECEIVING_DELAY * 5),
192 receiving_timeout_(MIN_CHECK_RECEIVING_DELAY * 50) { 193 receiving_timeout_(MIN_CHECK_RECEIVING_DELAY * 50) {}
193 }
194 194
195 P2PTransportChannel::~P2PTransportChannel() { 195 P2PTransportChannel::~P2PTransportChannel() {
196 ASSERT(worker_thread_ == rtc::Thread::Current()); 196 ASSERT(worker_thread_ == rtc::Thread::Current());
197 197
198 for (uint32 i = 0; i < allocator_sessions_.size(); ++i) 198 for (uint32 i = 0; i < allocator_sessions_.size(); ++i)
199 delete allocator_sessions_[i]; 199 delete allocator_sessions_[i];
200 } 200 }
201 201
202 // Add the allocator session to our list so that we know which sessions 202 // Add the allocator session to our list so that we know which sessions
203 // are still active. 203 // are still active.
(...skipping 20 matching lines...) Expand all
224 connection->set_receiving_timeout(receiving_timeout_); 224 connection->set_receiving_timeout(receiving_timeout_);
225 connection->SignalReadPacket.connect( 225 connection->SignalReadPacket.connect(
226 this, &P2PTransportChannel::OnReadPacket); 226 this, &P2PTransportChannel::OnReadPacket);
227 connection->SignalReadyToSend.connect( 227 connection->SignalReadyToSend.connect(
228 this, &P2PTransportChannel::OnReadyToSend); 228 this, &P2PTransportChannel::OnReadyToSend);
229 connection->SignalStateChange.connect( 229 connection->SignalStateChange.connect(
230 this, &P2PTransportChannel::OnConnectionStateChange); 230 this, &P2PTransportChannel::OnConnectionStateChange);
231 connection->SignalDestroyed.connect( 231 connection->SignalDestroyed.connect(
232 this, &P2PTransportChannel::OnConnectionDestroyed); 232 this, &P2PTransportChannel::OnConnectionDestroyed);
233 connection->SignalNominated.connect(this, &P2PTransportChannel::OnNominated); 233 connection->SignalNominated.connect(this, &P2PTransportChannel::OnNominated);
234 had_connection_ = true;
234 } 235 }
235 236
236 void P2PTransportChannel::SetIceRole(IceRole ice_role) { 237 void P2PTransportChannel::SetIceRole(IceRole ice_role) {
237 ASSERT(worker_thread_ == rtc::Thread::Current()); 238 ASSERT(worker_thread_ == rtc::Thread::Current());
238 if (ice_role_ != ice_role) { 239 if (ice_role_ != ice_role) {
239 ice_role_ = ice_role; 240 ice_role_ = ice_role;
240 for (std::vector<PortInterface *>::iterator it = ports_.begin(); 241 for (std::vector<PortInterface *>::iterator it = ports_.begin();
241 it != ports_.end(); ++it) { 242 it != ports_.end(); ++it) {
242 (*it)->SetIceRole(ice_role); 243 (*it)->SetIceRole(ice_role);
243 } 244 }
(...skipping 14 matching lines...) Expand all
258 // Currently a channel is considered ICE completed once there is no 259 // Currently a channel is considered ICE completed once there is no
259 // more than one connection per Network. This works for a single NIC 260 // more than one connection per Network. This works for a single NIC
260 // with both IPv4 and IPv6 enabled. However, this condition won't 261 // with both IPv4 and IPv6 enabled. However, this condition won't
261 // happen when there are multiple NICs and all of them have 262 // happen when there are multiple NICs and all of them have
262 // connectivity. 263 // connectivity.
263 // TODO(guoweis): Change Completion to be driven by a channel level 264 // TODO(guoweis): Change Completion to be driven by a channel level
264 // timer. 265 // timer.
265 TransportChannelState P2PTransportChannel::GetState() const { 266 TransportChannelState P2PTransportChannel::GetState() const {
266 std::set<rtc::Network*> networks; 267 std::set<rtc::Network*> networks;
267 268
268 if (connections_.size() == 0) { 269 if (connections_.empty()) {
269 return TransportChannelState::STATE_FAILED; 270 return had_connection_ ? TransportChannelState::STATE_FAILED
271 : TransportChannelState::STATE_INIT;
270 } 272 }
271 273
272 for (uint32 i = 0; i < connections_.size(); ++i) { 274 for (uint32 i = 0; i < connections_.size(); ++i) {
273 rtc::Network* network = connections_[i]->port()->Network(); 275 rtc::Network* network = connections_[i]->port()->Network();
274 if (networks.find(network) == networks.end()) { 276 if (networks.find(network) == networks.end()) {
275 networks.insert(network); 277 networks.insert(network);
276 } else { 278 } else {
277 LOG_J(LS_VERBOSE, this) << "Ice not completed yet for this channel as " 279 LOG_J(LS_VERBOSE, this) << "Ice not completed yet for this channel as "
278 << network->ToString() 280 << network->ToString()
279 << " has more than 1 connection."; 281 << " has more than 1 connection.";
280 return TransportChannelState::STATE_CONNECTING; 282 return TransportChannelState::STATE_CONNECTING;
281 } 283 }
282 } 284 }
283 LOG_J(LS_VERBOSE, this) << "Ice is completed for this channel."; 285 LOG_J(LS_VERBOSE, this) << "Ice is completed for this channel.";
284 286
285 return TransportChannelState::STATE_COMPLETED; 287 return TransportChannelState::STATE_COMPLETED;
286 } 288 }
287 289
288 void P2PTransportChannel::SetIceCredentials(const std::string& ice_ufrag, 290 void P2PTransportChannel::SetIceCredentials(const std::string& ice_ufrag,
289 const std::string& ice_pwd) { 291 const std::string& ice_pwd) {
290 ASSERT(worker_thread_ == rtc::Thread::Current()); 292 ASSERT(worker_thread_ == rtc::Thread::Current());
291 bool ice_restart = false;
292 if (!ice_ufrag_.empty() && !ice_pwd_.empty()) {
293 // Restart candidate allocation if there is any change in either
294 // ice ufrag or password.
295 ice_restart =
296 IceCredentialsChanged(ice_ufrag_, ice_pwd_, ice_ufrag, ice_pwd);
297 }
298
299 ice_ufrag_ = ice_ufrag; 293 ice_ufrag_ = ice_ufrag;
300 ice_pwd_ = ice_pwd; 294 ice_pwd_ = ice_pwd;
301 295 // Note: Candidate gathering will restart when MaybeStartGathering is next
302 if (ice_restart) { 296 // called.
303 // Restart candidate gathering.
304 Allocate();
305 }
306 } 297 }
307 298
308 void P2PTransportChannel::SetRemoteIceCredentials(const std::string& ice_ufrag, 299 void P2PTransportChannel::SetRemoteIceCredentials(const std::string& ice_ufrag,
309 const std::string& ice_pwd) { 300 const std::string& ice_pwd) {
310 ASSERT(worker_thread_ == rtc::Thread::Current()); 301 ASSERT(worker_thread_ == rtc::Thread::Current());
311 bool ice_restart = false; 302 bool ice_restart = false;
312 if (!remote_ice_ufrag_.empty() && !remote_ice_pwd_.empty()) { 303 if (!remote_ice_ufrag_.empty() && !remote_ice_pwd_.empty()) {
313 ice_restart = (remote_ice_ufrag_ != ice_ufrag) || 304 ice_restart = (remote_ice_ufrag_ != ice_ufrag) ||
314 (remote_ice_pwd_!= ice_pwd); 305 (remote_ice_pwd_!= ice_pwd);
315 } 306 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 // Go into the state of processing candidates, and running in general 343 // Go into the state of processing candidates, and running in general
353 void P2PTransportChannel::Connect() { 344 void P2PTransportChannel::Connect() {
354 ASSERT(worker_thread_ == rtc::Thread::Current()); 345 ASSERT(worker_thread_ == rtc::Thread::Current());
355 if (ice_ufrag_.empty() || ice_pwd_.empty()) { 346 if (ice_ufrag_.empty() || ice_pwd_.empty()) {
356 ASSERT(false); 347 ASSERT(false);
357 LOG(LS_ERROR) << "P2PTransportChannel::Connect: The ice_ufrag_ and the " 348 LOG(LS_ERROR) << "P2PTransportChannel::Connect: The ice_ufrag_ and the "
358 << "ice_pwd_ are not set."; 349 << "ice_pwd_ are not set.";
359 return; 350 return;
360 } 351 }
361 352
362 // Kick off an allocator session
363 Allocate();
364
365 // Start pinging as the ports come in. 353 // Start pinging as the ports come in.
366 thread()->Post(this, MSG_PING); 354 thread()->Post(this, MSG_PING);
367 355
368 thread()->PostDelayed( 356 thread()->PostDelayed(
369 check_receiving_delay_, this, MSG_CHECK_RECEIVING); 357 check_receiving_delay_, this, MSG_CHECK_RECEIVING);
370 } 358 }
371 359
360 void P2PTransportChannel::MaybeStartGathering() {
361 // Start gathering if we never started before, or if an ICE restart occurred.
362 if (allocator_sessions_.empty() ||
363 IceCredentialsChanged(allocator_sessions_.back()->ice_ufrag(),
364 allocator_sessions_.back()->ice_pwd(), ice_ufrag_,
365 ice_pwd_)) {
366 if (gathering_state_ != kIceGatheringGathering) {
367 gathering_state_ = kIceGatheringGathering;
368 SignalGatheringState(this);
369 }
370 // Time for a new allocator
371 AddAllocatorSession(allocator_->CreateSession(
372 SessionId(), transport_name(), component(), ice_ufrag_, ice_pwd_));
373 }
374 }
375
372 // A new port is available, attempt to make connections for it 376 // A new port is available, attempt to make connections for it
373 void P2PTransportChannel::OnPortReady(PortAllocatorSession *session, 377 void P2PTransportChannel::OnPortReady(PortAllocatorSession *session,
374 PortInterface* port) { 378 PortInterface* port) {
375 ASSERT(worker_thread_ == rtc::Thread::Current()); 379 ASSERT(worker_thread_ == rtc::Thread::Current());
376 380
377 // Set in-effect options on the new port 381 // Set in-effect options on the new port
378 for (OptionMap::const_iterator it = options_.begin(); 382 for (OptionMap::const_iterator it = options_.begin();
379 it != options_.end(); 383 it != options_.end();
380 ++it) { 384 ++it) {
381 int val = port->SetOption(it->first, it->second); 385 int val = port->SetOption(it->first, it->second);
(...skipping 24 matching lines...) Expand all
406 for (iter = remote_candidates_.begin(); iter != remote_candidates_.end(); 410 for (iter = remote_candidates_.begin(); iter != remote_candidates_.end();
407 ++iter) { 411 ++iter) {
408 CreateConnection(port, *iter, iter->origin_port()); 412 CreateConnection(port, *iter, iter->origin_port());
409 } 413 }
410 414
411 SortConnections(); 415 SortConnections();
412 } 416 }
413 417
414 // A new candidate is available, let listeners know 418 // A new candidate is available, let listeners know
415 void P2PTransportChannel::OnCandidatesReady( 419 void P2PTransportChannel::OnCandidatesReady(
416 PortAllocatorSession *session, const std::vector<Candidate>& candidates) { 420 PortAllocatorSession* session,
421 const std::vector<Candidate>& candidates) {
417 ASSERT(worker_thread_ == rtc::Thread::Current()); 422 ASSERT(worker_thread_ == rtc::Thread::Current());
418 for (size_t i = 0; i < candidates.size(); ++i) { 423 for (size_t i = 0; i < candidates.size(); ++i) {
419 SignalCandidateReady(this, candidates[i]); 424 SignalCandidateGathered(this, candidates[i]);
420 } 425 }
421 } 426 }
422 427
423 void P2PTransportChannel::OnCandidatesAllocationDone( 428 void P2PTransportChannel::OnCandidatesAllocationDone(
424 PortAllocatorSession* session) { 429 PortAllocatorSession* session) {
425 ASSERT(worker_thread_ == rtc::Thread::Current()); 430 ASSERT(worker_thread_ == rtc::Thread::Current());
426 SignalCandidatesAllocationDone(this); 431 gathering_state_ = kIceGatheringComplete;
432 LOG(LS_INFO) << "P2PTransportChannel: " << transport_name() << ", component "
433 << component() << " gathering complete";
434 SignalGatheringState(this);
427 } 435 }
428 436
429 // Handle stun packets 437 // Handle stun packets
430 void P2PTransportChannel::OnUnknownAddress( 438 void P2PTransportChannel::OnUnknownAddress(
431 PortInterface* port, 439 PortInterface* port,
432 const rtc::SocketAddress& address, ProtocolType proto, 440 const rtc::SocketAddress& address, ProtocolType proto,
433 IceMessage* stun_msg, const std::string &remote_username, 441 IceMessage* stun_msg, const std::string &remote_username,
434 bool port_muxed) { 442 bool port_muxed) {
435 ASSERT(worker_thread_ == rtc::Thread::Current()); 443 ASSERT(worker_thread_ == rtc::Thread::Current());
436 444
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 int remote_candidate_priority; 495 int remote_candidate_priority;
488 496
489 // The priority of the candidate is set to the PRIORITY attribute 497 // The priority of the candidate is set to the PRIORITY attribute
490 // from the request. 498 // from the request.
491 const StunUInt32Attribute* priority_attr = 499 const StunUInt32Attribute* priority_attr =
492 stun_msg->GetUInt32(STUN_ATTR_PRIORITY); 500 stun_msg->GetUInt32(STUN_ATTR_PRIORITY);
493 if (!priority_attr) { 501 if (!priority_attr) {
494 LOG(LS_WARNING) << "P2PTransportChannel::OnUnknownAddress - " 502 LOG(LS_WARNING) << "P2PTransportChannel::OnUnknownAddress - "
495 << "No STUN_ATTR_PRIORITY found in the " 503 << "No STUN_ATTR_PRIORITY found in the "
496 << "stun request message"; 504 << "stun request message";
497 port->SendBindingErrorResponse(stun_msg, address, 505 port->SendBindingErrorResponse(stun_msg, address, STUN_ERROR_BAD_REQUEST,
498 STUN_ERROR_BAD_REQUEST,
499 STUN_ERROR_REASON_BAD_REQUEST); 506 STUN_ERROR_REASON_BAD_REQUEST);
500 return; 507 return;
501 } 508 }
502 remote_candidate_priority = priority_attr->value(); 509 remote_candidate_priority = priority_attr->value();
503 510
504 // RFC 5245 511 // RFC 5245
505 // If the source transport address of the request does not match any 512 // If the source transport address of the request does not match any
506 // existing remote candidates, it represents a new peer reflexive remote 513 // existing remote candidates, it represents a new peer reflexive remote
507 // candidate. 514 // candidate.
508 remote_candidate = 515 remote_candidate =
(...skipping 29 matching lines...) Expand all
538 STUN_ERROR_SERVER_ERROR, 545 STUN_ERROR_SERVER_ERROR,
539 STUN_ERROR_REASON_SERVER_ERROR); 546 STUN_ERROR_REASON_SERVER_ERROR);
540 return; 547 return;
541 } 548 }
542 } 549 }
543 550
544 Connection* connection = port->CreateConnection( 551 Connection* connection = port->CreateConnection(
545 remote_candidate, cricket::PortInterface::ORIGIN_THIS_PORT); 552 remote_candidate, cricket::PortInterface::ORIGIN_THIS_PORT);
546 if (!connection) { 553 if (!connection) {
547 ASSERT(false); 554 ASSERT(false);
548 port->SendBindingErrorResponse(stun_msg, address, 555 port->SendBindingErrorResponse(stun_msg, address, STUN_ERROR_SERVER_ERROR,
549 STUN_ERROR_SERVER_ERROR,
550 STUN_ERROR_REASON_SERVER_ERROR); 556 STUN_ERROR_REASON_SERVER_ERROR);
551 return; 557 return;
552 } 558 }
553 559
554 LOG(LS_INFO) << "Adding connection from " 560 LOG(LS_INFO) << "Adding connection from "
555 << (remote_candidate_is_new ? "peer reflexive" : "resurrected") 561 << (remote_candidate_is_new ? "peer reflexive" : "resurrected")
556 << " candidate: " << remote_candidate.ToString(); 562 << " candidate: " << remote_candidate.ToString();
557 AddConnection(connection); 563 AddConnection(connection);
558 connection->ReceivedPing(); 564 connection->ReceivedPing();
559 565
560 bool received_use_candidate = 566 bool received_use_candidate =
561 stun_msg->GetByteString(STUN_ATTR_USE_CANDIDATE) != nullptr; 567 stun_msg->GetByteString(STUN_ATTR_USE_CANDIDATE) != nullptr;
562 if (received_use_candidate && ice_role_ == ICEROLE_CONTROLLED) { 568 if (received_use_candidate && ice_role_ == ICEROLE_CONTROLLED) {
563 connection->set_nominated(true); 569 connection->set_nominated(true);
564 OnNominated(connection); 570 OnNominated(connection);
565 } 571 }
566 572
567 // Update the list of connections since we just added another. We do this 573 // Update the list of connections since we just added another. We do this
568 // after sending the response since it could (in principle) delete the 574 // after sending the response since it could (in principle) delete the
569 // connection in question. 575 // connection in question.
570 SortConnections(); 576 SortConnections();
571 } 577 }
572 578
573 void P2PTransportChannel::OnRoleConflict(PortInterface* port) { 579 void P2PTransportChannel::OnRoleConflict(PortInterface* port) {
574 SignalRoleConflict(this); // STUN ping will be sent when SetRole is called 580 SignalRoleConflict(this); // STUN ping will be sent when SetRole is called
575 // from Transport. 581 // from Transport.
576 } 582 }
577 583
578 // When the signalling channel is ready, we can really kick off the allocator
579 void P2PTransportChannel::OnSignalingReady() {
580 ASSERT(worker_thread_ == rtc::Thread::Current());
581 if (waiting_for_signaling_) {
582 waiting_for_signaling_ = false;
583 AddAllocatorSession(allocator_->CreateSession(
584 SessionId(), content_name(), component(), ice_ufrag_, ice_pwd_));
585 }
586 }
587
588 void P2PTransportChannel::OnNominated(Connection* conn) { 584 void P2PTransportChannel::OnNominated(Connection* conn) {
589 ASSERT(worker_thread_ == rtc::Thread::Current()); 585 ASSERT(worker_thread_ == rtc::Thread::Current());
590 ASSERT(ice_role_ == ICEROLE_CONTROLLED); 586 ASSERT(ice_role_ == ICEROLE_CONTROLLED);
591 587
592 if (conn->write_state() == Connection::STATE_WRITABLE) { 588 if (conn->write_state() == Connection::STATE_WRITABLE) {
593 if (best_connection_ != conn) { 589 if (best_connection_ != conn) {
594 pending_best_connection_ = NULL; 590 pending_best_connection_ = NULL;
595 LOG(LS_INFO) << "Switching best connection on controlled side: " 591 LOG(LS_INFO) << "Switching best connection on controlled side: "
596 << conn->ToString(); 592 << conn->ToString();
597 SwitchBestConnectionTo(conn); 593 SwitchBestConnectionTo(conn);
598 // Now we have selected the best connection, time to prune other existing 594 // Now we have selected the best connection, time to prune other existing
599 // connections and update the read/write state of the channel. 595 // connections and update the read/write state of the channel.
600 RequestSort(); 596 RequestSort();
601 } 597 }
602 } else { 598 } else {
603 LOG(LS_INFO) << "Not switching the best connection on controlled side yet," 599 LOG(LS_INFO) << "Not switching the best connection on controlled side yet,"
604 << " because it's not writable: " << conn->ToString(); 600 << " because it's not writable: " << conn->ToString();
605 pending_best_connection_ = conn; 601 pending_best_connection_ = conn;
606 } 602 }
607 } 603 }
608 604
609 void P2PTransportChannel::OnCandidate(const Candidate& candidate) { 605 void P2PTransportChannel::AddRemoteCandidate(const Candidate& candidate) {
610 ASSERT(worker_thread_ == rtc::Thread::Current()); 606 ASSERT(worker_thread_ == rtc::Thread::Current());
611 607
612 uint32 generation = candidate.generation(); 608 uint32 generation = candidate.generation();
613 // Network may not guarantee the order of the candidate delivery. If a 609 // Network may not guarantee the order of the candidate delivery. If a
614 // remote candidate with an older generation arrives, drop it. 610 // remote candidate with an older generation arrives, drop it.
615 if (generation != 0 && generation < remote_candidate_generation_) { 611 if (generation != 0 && generation < remote_candidate_generation_) {
616 LOG(LS_WARNING) << "Dropping a remote candidate because its generation " 612 LOG(LS_WARNING) << "Dropping a remote candidate because its generation "
617 << generation 613 << generation
618 << " is lower than the current remote generation " 614 << " is lower than the current remote generation "
619 << remote_candidate_generation_; 615 << remote_candidate_generation_;
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 return sent; 836 return sent;
841 } 837 }
842 838
843 bool P2PTransportChannel::GetStats(ConnectionInfos *infos) { 839 bool P2PTransportChannel::GetStats(ConnectionInfos *infos) {
844 ASSERT(worker_thread_ == rtc::Thread::Current()); 840 ASSERT(worker_thread_ == rtc::Thread::Current());
845 // Gather connection infos. 841 // Gather connection infos.
846 infos->clear(); 842 infos->clear();
847 843
848 std::vector<Connection *>::const_iterator it; 844 std::vector<Connection *>::const_iterator it;
849 for (it = connections_.begin(); it != connections_.end(); ++it) { 845 for (it = connections_.begin(); it != connections_.end(); ++it) {
850 Connection *connection = *it; 846 Connection* connection = *it;
851 ConnectionInfo info; 847 ConnectionInfo info;
852 info.best_connection = (best_connection_ == connection); 848 info.best_connection = (best_connection_ == connection);
853 info.receiving = connection->receiving(); 849 info.receiving = connection->receiving();
854 info.writable = 850 info.writable =
855 (connection->write_state() == Connection::STATE_WRITABLE); 851 (connection->write_state() == Connection::STATE_WRITABLE);
856 info.timeout = 852 info.timeout =
857 (connection->write_state() == Connection::STATE_WRITE_TIMEOUT); 853 (connection->write_state() == Connection::STATE_WRITE_TIMEOUT);
858 info.new_connection = !connection->reported(); 854 info.new_connection = !connection->reported();
859 connection->set_reported(true); 855 connection->set_reported(true);
860 info.rtt = connection->rtt(); 856 info.rtt = connection->rtt();
(...skipping 13 matching lines...) Expand all
874 } 870 }
875 871
876 rtc::DiffServCodePoint P2PTransportChannel::DefaultDscpValue() const { 872 rtc::DiffServCodePoint P2PTransportChannel::DefaultDscpValue() const {
877 OptionMap::const_iterator it = options_.find(rtc::Socket::OPT_DSCP); 873 OptionMap::const_iterator it = options_.find(rtc::Socket::OPT_DSCP);
878 if (it == options_.end()) { 874 if (it == options_.end()) {
879 return rtc::DSCP_NO_CHANGE; 875 return rtc::DSCP_NO_CHANGE;
880 } 876 }
881 return static_cast<rtc::DiffServCodePoint> (it->second); 877 return static_cast<rtc::DiffServCodePoint> (it->second);
882 } 878 }
883 879
884 // Begin allocate (or immediately re-allocate, if MSG_ALLOCATE pending)
885 void P2PTransportChannel::Allocate() {
886 // Time for a new allocator, lets make sure we have a signalling channel
887 // to communicate candidates through first.
888 waiting_for_signaling_ = true;
889 SignalRequestSignaling(this);
890 }
891
892 // Monitor connection states. 880 // Monitor connection states.
893 void P2PTransportChannel::UpdateConnectionStates() { 881 void P2PTransportChannel::UpdateConnectionStates() {
894 uint32 now = rtc::Time(); 882 uint32 now = rtc::Time();
895 883
896 // We need to copy the list of connections since some may delete themselves 884 // We need to copy the list of connections since some may delete themselves
897 // when we call UpdateState. 885 // when we call UpdateState.
898 for (uint32 i = 0; i < connections_.size(); ++i) 886 for (uint32 i = 0; i < connections_.size(); ++i)
899 connections_[i]->UpdateState(now); 887 connections_[i]->UpdateState(now);
900 } 888 }
901 889
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
1221 // a.1) |conn| is the best connection OR 1209 // a.1) |conn| is the best connection OR
1222 // a.2) there is no best connection OR 1210 // a.2) there is no best connection OR
1223 // a.3) the best connection is unwritable OR 1211 // a.3) the best connection is unwritable OR
1224 // a.4) |conn| has higher priority than best_connection. 1212 // a.4) |conn| has higher priority than best_connection.
1225 // b) we're doing LITE ICE AND 1213 // b) we're doing LITE ICE AND
1226 // b.1) |conn| is the best_connection AND 1214 // b.1) |conn| is the best_connection AND
1227 // b.2) |conn| is writable. 1215 // b.2) |conn| is writable.
1228 void P2PTransportChannel::PingConnection(Connection* conn) { 1216 void P2PTransportChannel::PingConnection(Connection* conn) {
1229 bool use_candidate = false; 1217 bool use_candidate = false;
1230 if (remote_ice_mode_ == ICEMODE_FULL && ice_role_ == ICEROLE_CONTROLLING) { 1218 if (remote_ice_mode_ == ICEMODE_FULL && ice_role_ == ICEROLE_CONTROLLING) {
1231 use_candidate = (conn == best_connection_) || 1219 use_candidate = (conn == best_connection_) || (best_connection_ == NULL) ||
1232 (best_connection_ == NULL) ||
1233 (!best_connection_->writable()) || 1220 (!best_connection_->writable()) ||
1234 (conn->priority() > best_connection_->priority()); 1221 (conn->priority() > best_connection_->priority());
1235 } else if (remote_ice_mode_ == ICEMODE_LITE && conn == best_connection_) { 1222 } else if (remote_ice_mode_ == ICEMODE_LITE && conn == best_connection_) {
1236 use_candidate = best_connection_->writable(); 1223 use_candidate = best_connection_->writable();
1237 } 1224 }
1238 conn->set_use_candidate_attr(use_candidate); 1225 conn->set_use_candidate_attr(use_candidate);
1239 conn->Ping(rtc::Time()); 1226 conn->Ping(rtc::Time());
1240 } 1227 }
1241 1228
1242 // When a connection's state changes, we need to figure out who to use as 1229 // When a connection's state changes, we need to figure out who to use as
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 std::vector<PortInterface*>::iterator iter = 1291 std::vector<PortInterface*>::iterator iter =
1305 std::find(ports_.begin(), ports_.end(), port); 1292 std::find(ports_.begin(), ports_.end(), port);
1306 if (iter != ports_.end()) 1293 if (iter != ports_.end())
1307 ports_.erase(iter); 1294 ports_.erase(iter);
1308 1295
1309 LOG(INFO) << "Removed port from p2p socket: " 1296 LOG(INFO) << "Removed port from p2p socket: "
1310 << static_cast<int>(ports_.size()) << " remaining"; 1297 << static_cast<int>(ports_.size()) << " remaining";
1311 } 1298 }
1312 1299
1313 // We data is available, let listeners know 1300 // We data is available, let listeners know
1314 void P2PTransportChannel::OnReadPacket( 1301 void P2PTransportChannel::OnReadPacket(Connection* connection,
1315 Connection *connection, const char *data, size_t len, 1302 const char* data,
1316 const rtc::PacketTime& packet_time) { 1303 size_t len,
1304 const rtc::PacketTime& packet_time) {
1317 ASSERT(worker_thread_ == rtc::Thread::Current()); 1305 ASSERT(worker_thread_ == rtc::Thread::Current());
1318 1306
1319 // Do not deliver, if packet doesn't belong to the correct transport channel. 1307 // Do not deliver, if packet doesn't belong to the correct transport channel.
1320 if (!FindConnection(connection)) 1308 if (!FindConnection(connection))
1321 return; 1309 return;
1322 1310
1323 // Let the client know of an incoming packet 1311 // Let the client know of an incoming packet
1324 SignalReadPacket(this, data, len, packet_time, 0); 1312 SignalReadPacket(this, data, len, packet_time, 0);
1325 1313
1326 // May need to switch the sending connection based on the receiving media path 1314 // May need to switch the sending connection based on the receiving media path
1327 // if this is the controlled side. 1315 // if this is the controlled side.
1328 if (ice_role_ == ICEROLE_CONTROLLED && !best_nominated_connection() && 1316 if (ice_role_ == ICEROLE_CONTROLLED && !best_nominated_connection() &&
1329 connection->writable() && best_connection_ != connection) { 1317 connection->writable() && best_connection_ != connection) {
1330 SwitchBestConnectionTo(connection); 1318 SwitchBestConnectionTo(connection);
1331 } 1319 }
1332 } 1320 }
1333 1321
1334 void P2PTransportChannel::OnReadyToSend(Connection* connection) { 1322 void P2PTransportChannel::OnReadyToSend(Connection* connection) {
1335 if (connection == best_connection_ && writable()) { 1323 if (connection == best_connection_ && writable()) {
1336 SignalReadyToSend(this); 1324 SignalReadyToSend(this);
1337 } 1325 }
1338 } 1326 }
1339 1327
1340 } // namespace cricket 1328 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.h ('k') | webrtc/p2p/base/p2ptransportchannel_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698