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

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

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