OLD | NEW |
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 Loading... |
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 20 matching lines...) Expand all Loading... |
223 connection->set_remote_ice_mode(remote_ice_mode_); | 224 connection->set_remote_ice_mode(remote_ice_mode_); |
224 connection->SignalReadPacket.connect( | 225 connection->SignalReadPacket.connect( |
225 this, &P2PTransportChannel::OnReadPacket); | 226 this, &P2PTransportChannel::OnReadPacket); |
226 connection->SignalReadyToSend.connect( | 227 connection->SignalReadyToSend.connect( |
227 this, &P2PTransportChannel::OnReadyToSend); | 228 this, &P2PTransportChannel::OnReadyToSend); |
228 connection->SignalStateChange.connect( | 229 connection->SignalStateChange.connect( |
229 this, &P2PTransportChannel::OnConnectionStateChange); | 230 this, &P2PTransportChannel::OnConnectionStateChange); |
230 connection->SignalDestroyed.connect( | 231 connection->SignalDestroyed.connect( |
231 this, &P2PTransportChannel::OnConnectionDestroyed); | 232 this, &P2PTransportChannel::OnConnectionDestroyed); |
232 connection->SignalNominated.connect(this, &P2PTransportChannel::OnNominated); | 233 connection->SignalNominated.connect(this, &P2PTransportChannel::OnNominated); |
| 234 had_connection_ = true; |
233 } | 235 } |
234 | 236 |
235 void P2PTransportChannel::SetIceRole(IceRole ice_role) { | 237 void P2PTransportChannel::SetIceRole(IceRole ice_role) { |
236 ASSERT(worker_thread_ == rtc::Thread::Current()); | 238 ASSERT(worker_thread_ == rtc::Thread::Current()); |
237 if (ice_role_ != ice_role) { | 239 if (ice_role_ != ice_role) { |
238 ice_role_ = ice_role; | 240 ice_role_ = ice_role; |
239 for (std::vector<PortInterface *>::iterator it = ports_.begin(); | 241 for (std::vector<PortInterface *>::iterator it = ports_.begin(); |
240 it != ports_.end(); ++it) { | 242 it != ports_.end(); ++it) { |
241 (*it)->SetIceRole(ice_role); | 243 (*it)->SetIceRole(ice_role); |
242 } | 244 } |
(...skipping 14 matching lines...) Expand all Loading... |
257 // Currently a channel is considered ICE completed once there is no | 259 // Currently a channel is considered ICE completed once there is no |
258 // 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 |
259 // with both IPv4 and IPv6 enabled. However, this condition won't | 261 // with both IPv4 and IPv6 enabled. However, this condition won't |
260 // happen when there are multiple NICs and all of them have | 262 // happen when there are multiple NICs and all of them have |
261 // connectivity. | 263 // connectivity. |
262 // TODO(guoweis): Change Completion to be driven by a channel level | 264 // TODO(guoweis): Change Completion to be driven by a channel level |
263 // timer. | 265 // timer. |
264 TransportChannelState P2PTransportChannel::GetState() const { | 266 TransportChannelState P2PTransportChannel::GetState() const { |
265 std::set<rtc::Network*> networks; | 267 std::set<rtc::Network*> networks; |
266 | 268 |
267 if (connections_.size() == 0) { | 269 if (connections_.empty()) { |
268 return TransportChannelState::STATE_FAILED; | 270 return had_connection_ ? TransportChannelState::STATE_FAILED |
| 271 : TransportChannelState::STATE_INIT; |
269 } | 272 } |
270 | 273 |
271 for (uint32 i = 0; i < connections_.size(); ++i) { | 274 for (uint32 i = 0; i < connections_.size(); ++i) { |
272 rtc::Network* network = connections_[i]->port()->Network(); | 275 rtc::Network* network = connections_[i]->port()->Network(); |
273 if (networks.find(network) == networks.end()) { | 276 if (networks.find(network) == networks.end()) { |
274 networks.insert(network); | 277 networks.insert(network); |
275 } else { | 278 } else { |
276 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 " |
277 << network->ToString() | 280 << network->ToString() |
278 << " has more than 1 connection."; | 281 << " has more than 1 connection."; |
(...skipping 14 matching lines...) Expand all Loading... |
293 // ice ufrag or password. | 296 // ice ufrag or password. |
294 ice_restart = | 297 ice_restart = |
295 IceCredentialsChanged(ice_ufrag_, ice_pwd_, ice_ufrag, ice_pwd); | 298 IceCredentialsChanged(ice_ufrag_, ice_pwd_, ice_ufrag, ice_pwd); |
296 } | 299 } |
297 | 300 |
298 ice_ufrag_ = ice_ufrag; | 301 ice_ufrag_ = ice_ufrag; |
299 ice_pwd_ = ice_pwd; | 302 ice_pwd_ = ice_pwd; |
300 | 303 |
301 if (ice_restart) { | 304 if (ice_restart) { |
302 // Restart candidate gathering. | 305 // Restart candidate gathering. |
303 Allocate(); | 306 StartGatheringCandidates(); |
304 } | 307 } |
305 } | 308 } |
306 | 309 |
307 void P2PTransportChannel::SetRemoteIceCredentials(const std::string& ice_ufrag, | 310 void P2PTransportChannel::SetRemoteIceCredentials(const std::string& ice_ufrag, |
308 const std::string& ice_pwd) { | 311 const std::string& ice_pwd) { |
309 ASSERT(worker_thread_ == rtc::Thread::Current()); | 312 ASSERT(worker_thread_ == rtc::Thread::Current()); |
310 bool ice_restart = false; | 313 bool ice_restart = false; |
311 if (!remote_ice_ufrag_.empty() && !remote_ice_pwd_.empty()) { | 314 if (!remote_ice_ufrag_.empty() && !remote_ice_pwd_.empty()) { |
312 ice_restart = (remote_ice_ufrag_ != ice_ufrag) || | 315 ice_restart = (remote_ice_ufrag_ != ice_ufrag) || |
313 (remote_ice_pwd_!= ice_pwd); | 316 (remote_ice_pwd_!= ice_pwd); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 void P2PTransportChannel::Connect() { | 351 void P2PTransportChannel::Connect() { |
349 ASSERT(worker_thread_ == rtc::Thread::Current()); | 352 ASSERT(worker_thread_ == rtc::Thread::Current()); |
350 if (ice_ufrag_.empty() || ice_pwd_.empty()) { | 353 if (ice_ufrag_.empty() || ice_pwd_.empty()) { |
351 ASSERT(false); | 354 ASSERT(false); |
352 LOG(LS_ERROR) << "P2PTransportChannel::Connect: The ice_ufrag_ and the " | 355 LOG(LS_ERROR) << "P2PTransportChannel::Connect: The ice_ufrag_ and the " |
353 << "ice_pwd_ are not set."; | 356 << "ice_pwd_ are not set."; |
354 return; | 357 return; |
355 } | 358 } |
356 | 359 |
357 // Kick off an allocator session | 360 // Kick off an allocator session |
358 Allocate(); | 361 StartGatheringCandidates(); |
359 | 362 |
360 // Start pinging as the ports come in. | 363 // Start pinging as the ports come in. |
361 thread()->Post(this, MSG_PING); | 364 thread()->Post(this, MSG_PING); |
362 | 365 |
363 thread()->PostDelayed( | 366 thread()->PostDelayed( |
364 check_receiving_delay_, this, MSG_CHECK_RECEIVING); | 367 check_receiving_delay_, this, MSG_CHECK_RECEIVING); |
365 } | 368 } |
366 | 369 |
367 // A new port is available, attempt to make connections for it | 370 // A new port is available, attempt to make connections for it |
368 void P2PTransportChannel::OnPortReady(PortAllocatorSession *session, | 371 void P2PTransportChannel::OnPortReady(PortAllocatorSession *session, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 for (iter = remote_candidates_.begin(); iter != remote_candidates_.end(); | 404 for (iter = remote_candidates_.begin(); iter != remote_candidates_.end(); |
402 ++iter) { | 405 ++iter) { |
403 CreateConnection(port, *iter, iter->origin_port(), false); | 406 CreateConnection(port, *iter, iter->origin_port(), false); |
404 } | 407 } |
405 | 408 |
406 SortConnections(); | 409 SortConnections(); |
407 } | 410 } |
408 | 411 |
409 // A new candidate is available, let listeners know | 412 // A new candidate is available, let listeners know |
410 void P2PTransportChannel::OnCandidatesReady( | 413 void P2PTransportChannel::OnCandidatesReady( |
411 PortAllocatorSession *session, const std::vector<Candidate>& candidates) { | 414 PortAllocatorSession* session, |
| 415 const std::vector<Candidate>& candidates) { |
412 ASSERT(worker_thread_ == rtc::Thread::Current()); | 416 ASSERT(worker_thread_ == rtc::Thread::Current()); |
413 for (size_t i = 0; i < candidates.size(); ++i) { | 417 for (size_t i = 0; i < candidates.size(); ++i) { |
414 SignalCandidateReady(this, candidates[i]); | 418 SignalCandidateGathered(this, candidates[i]); |
415 } | 419 } |
416 } | 420 } |
417 | 421 |
418 void P2PTransportChannel::OnCandidatesAllocationDone( | 422 void P2PTransportChannel::OnCandidatesAllocationDone( |
419 PortAllocatorSession* session) { | 423 PortAllocatorSession* session) { |
420 ASSERT(worker_thread_ == rtc::Thread::Current()); | 424 ASSERT(worker_thread_ == rtc::Thread::Current()); |
421 SignalCandidatesAllocationDone(this); | 425 gathering_state_ = kIceGatheringComplete; |
| 426 LOG(LS_INFO) << "P2PTransportChannel: " << transport_name() << ", component " |
| 427 << component() << " gathering complete"; |
| 428 SignalGatheringState(this); |
422 } | 429 } |
423 | 430 |
424 // Handle stun packets | 431 // Handle stun packets |
425 void P2PTransportChannel::OnUnknownAddress( | 432 void P2PTransportChannel::OnUnknownAddress( |
426 PortInterface* port, | 433 PortInterface* port, |
427 const rtc::SocketAddress& address, ProtocolType proto, | 434 const rtc::SocketAddress& address, ProtocolType proto, |
428 IceMessage* stun_msg, const std::string &remote_username, | 435 IceMessage* stun_msg, const std::string &remote_username, |
429 bool port_muxed) { | 436 bool port_muxed) { |
430 ASSERT(worker_thread_ == rtc::Thread::Current()); | 437 ASSERT(worker_thread_ == rtc::Thread::Current()); |
431 | 438 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 int remote_candidate_priority; | 489 int remote_candidate_priority; |
483 | 490 |
484 // The priority of the candidate is set to the PRIORITY attribute | 491 // The priority of the candidate is set to the PRIORITY attribute |
485 // from the request. | 492 // from the request. |
486 const StunUInt32Attribute* priority_attr = | 493 const StunUInt32Attribute* priority_attr = |
487 stun_msg->GetUInt32(STUN_ATTR_PRIORITY); | 494 stun_msg->GetUInt32(STUN_ATTR_PRIORITY); |
488 if (!priority_attr) { | 495 if (!priority_attr) { |
489 LOG(LS_WARNING) << "P2PTransportChannel::OnUnknownAddress - " | 496 LOG(LS_WARNING) << "P2PTransportChannel::OnUnknownAddress - " |
490 << "No STUN_ATTR_PRIORITY found in the " | 497 << "No STUN_ATTR_PRIORITY found in the " |
491 << "stun request message"; | 498 << "stun request message"; |
492 port->SendBindingErrorResponse(stun_msg, address, | 499 port->SendBindingErrorResponse(stun_msg, address, STUN_ERROR_BAD_REQUEST, |
493 STUN_ERROR_BAD_REQUEST, | |
494 STUN_ERROR_REASON_BAD_REQUEST); | 500 STUN_ERROR_REASON_BAD_REQUEST); |
495 return; | 501 return; |
496 } | 502 } |
497 remote_candidate_priority = priority_attr->value(); | 503 remote_candidate_priority = priority_attr->value(); |
498 | 504 |
499 // RFC 5245 | 505 // RFC 5245 |
500 // If the source transport address of the request does not match any | 506 // If the source transport address of the request does not match any |
501 // existing remote candidates, it represents a new peer reflexive remote | 507 // existing remote candidates, it represents a new peer reflexive remote |
502 // candidate. | 508 // candidate. |
503 remote_candidate = | 509 remote_candidate = |
(...skipping 29 matching lines...) Expand all Loading... |
533 STUN_ERROR_SERVER_ERROR, | 539 STUN_ERROR_SERVER_ERROR, |
534 STUN_ERROR_REASON_SERVER_ERROR); | 540 STUN_ERROR_REASON_SERVER_ERROR); |
535 return; | 541 return; |
536 } | 542 } |
537 } | 543 } |
538 | 544 |
539 Connection* connection = port->CreateConnection( | 545 Connection* connection = port->CreateConnection( |
540 remote_candidate, cricket::PortInterface::ORIGIN_THIS_PORT); | 546 remote_candidate, cricket::PortInterface::ORIGIN_THIS_PORT); |
541 if (!connection) { | 547 if (!connection) { |
542 ASSERT(false); | 548 ASSERT(false); |
543 port->SendBindingErrorResponse(stun_msg, address, | 549 port->SendBindingErrorResponse(stun_msg, address, STUN_ERROR_SERVER_ERROR, |
544 STUN_ERROR_SERVER_ERROR, | |
545 STUN_ERROR_REASON_SERVER_ERROR); | 550 STUN_ERROR_REASON_SERVER_ERROR); |
546 return; | 551 return; |
547 } | 552 } |
548 | 553 |
549 LOG(LS_INFO) << "Adding connection from " | 554 LOG(LS_INFO) << "Adding connection from " |
550 << (remote_candidate_is_new ? "peer reflexive" : "resurrected") | 555 << (remote_candidate_is_new ? "peer reflexive" : "resurrected") |
551 << " candidate: " << remote_candidate.ToString(); | 556 << " candidate: " << remote_candidate.ToString(); |
552 AddConnection(connection); | 557 AddConnection(connection); |
553 connection->ReceivedPing(); | 558 connection->ReceivedPing(); |
554 | 559 |
555 bool received_use_candidate = | 560 bool received_use_candidate = |
556 stun_msg->GetByteString(STUN_ATTR_USE_CANDIDATE) != nullptr; | 561 stun_msg->GetByteString(STUN_ATTR_USE_CANDIDATE) != nullptr; |
557 if (received_use_candidate && ice_role_ == ICEROLE_CONTROLLED) { | 562 if (received_use_candidate && ice_role_ == ICEROLE_CONTROLLED) { |
558 connection->set_nominated(true); | 563 connection->set_nominated(true); |
559 OnNominated(connection); | 564 OnNominated(connection); |
560 } | 565 } |
561 | 566 |
562 // Update the list of connections since we just added another. We do this | 567 // Update the list of connections since we just added another. We do this |
563 // after sending the response since it could (in principle) delete the | 568 // after sending the response since it could (in principle) delete the |
564 // connection in question. | 569 // connection in question. |
565 SortConnections(); | 570 SortConnections(); |
566 } | 571 } |
567 | 572 |
568 void P2PTransportChannel::OnRoleConflict(PortInterface* port) { | 573 void P2PTransportChannel::OnRoleConflict(PortInterface* port) { |
569 SignalRoleConflict(this); // STUN ping will be sent when SetRole is called | 574 SignalRoleConflict(this); // STUN ping will be sent when SetRole is called |
570 // from Transport. | 575 // from Transport. |
571 } | 576 } |
572 | 577 |
573 // When the signalling channel is ready, we can really kick off the allocator | |
574 void P2PTransportChannel::OnSignalingReady() { | |
575 ASSERT(worker_thread_ == rtc::Thread::Current()); | |
576 if (waiting_for_signaling_) { | |
577 waiting_for_signaling_ = false; | |
578 AddAllocatorSession(allocator_->CreateSession( | |
579 SessionId(), content_name(), component(), ice_ufrag_, ice_pwd_)); | |
580 } | |
581 } | |
582 | |
583 void P2PTransportChannel::OnNominated(Connection* conn) { | 578 void P2PTransportChannel::OnNominated(Connection* conn) { |
584 ASSERT(worker_thread_ == rtc::Thread::Current()); | 579 ASSERT(worker_thread_ == rtc::Thread::Current()); |
585 ASSERT(ice_role_ == ICEROLE_CONTROLLED); | 580 ASSERT(ice_role_ == ICEROLE_CONTROLLED); |
586 | 581 |
587 if (conn->write_state() == Connection::STATE_WRITABLE) { | 582 if (conn->write_state() == Connection::STATE_WRITABLE) { |
588 if (best_connection_ != conn) { | 583 if (best_connection_ != conn) { |
589 pending_best_connection_ = NULL; | 584 pending_best_connection_ = NULL; |
590 LOG(LS_INFO) << "Switching best connection on controlled side: " | 585 LOG(LS_INFO) << "Switching best connection on controlled side: " |
591 << conn->ToString(); | 586 << conn->ToString(); |
592 SwitchBestConnectionTo(conn); | 587 SwitchBestConnectionTo(conn); |
593 // Now we have selected the best connection, time to prune other existing | 588 // Now we have selected the best connection, time to prune other existing |
594 // connections and update the read/write state of the channel. | 589 // connections and update the read/write state of the channel. |
595 RequestSort(); | 590 RequestSort(); |
596 } | 591 } |
597 } else { | 592 } else { |
598 LOG(LS_INFO) << "Not switching the best connection on controlled side yet," | 593 LOG(LS_INFO) << "Not switching the best connection on controlled side yet," |
599 << " because it's not writable: " << conn->ToString(); | 594 << " because it's not writable: " << conn->ToString(); |
600 pending_best_connection_ = conn; | 595 pending_best_connection_ = conn; |
601 } | 596 } |
602 } | 597 } |
603 | 598 |
604 void P2PTransportChannel::OnCandidate(const Candidate& candidate) { | 599 void P2PTransportChannel::AddRemoteCandidate(const Candidate& candidate) { |
605 ASSERT(worker_thread_ == rtc::Thread::Current()); | 600 ASSERT(worker_thread_ == rtc::Thread::Current()); |
606 | 601 |
607 uint32 generation = candidate.generation(); | 602 uint32 generation = candidate.generation(); |
608 // Network may not guarantee the order of the candidate delivery. If a | 603 // Network may not guarantee the order of the candidate delivery. If a |
609 // remote candidate with an older generation arrives, drop it. | 604 // remote candidate with an older generation arrives, drop it. |
610 if (generation != 0 && generation < remote_candidate_generation_) { | 605 if (generation != 0 && generation < remote_candidate_generation_) { |
611 LOG(LS_WARNING) << "Dropping a remote candidate because its generation " | 606 LOG(LS_WARNING) << "Dropping a remote candidate because its generation " |
612 << generation | 607 << generation |
613 << " is lower than the current remote generation " | 608 << " is lower than the current remote generation " |
614 << remote_candidate_generation_; | 609 << remote_candidate_generation_; |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 return sent; | 838 return sent; |
844 } | 839 } |
845 | 840 |
846 bool P2PTransportChannel::GetStats(ConnectionInfos *infos) { | 841 bool P2PTransportChannel::GetStats(ConnectionInfos *infos) { |
847 ASSERT(worker_thread_ == rtc::Thread::Current()); | 842 ASSERT(worker_thread_ == rtc::Thread::Current()); |
848 // Gather connection infos. | 843 // Gather connection infos. |
849 infos->clear(); | 844 infos->clear(); |
850 | 845 |
851 std::vector<Connection *>::const_iterator it; | 846 std::vector<Connection *>::const_iterator it; |
852 for (it = connections_.begin(); it != connections_.end(); ++it) { | 847 for (it = connections_.begin(); it != connections_.end(); ++it) { |
853 Connection *connection = *it; | 848 Connection* connection = *it; |
854 ConnectionInfo info; | 849 ConnectionInfo info; |
855 info.best_connection = (best_connection_ == connection); | 850 info.best_connection = (best_connection_ == connection); |
856 info.readable = | 851 info.readable = |
857 (connection->read_state() == Connection::STATE_READABLE); | 852 (connection->read_state() == Connection::STATE_READABLE); |
858 info.writable = | 853 info.writable = |
859 (connection->write_state() == Connection::STATE_WRITABLE); | 854 (connection->write_state() == Connection::STATE_WRITABLE); |
860 info.timeout = | 855 info.timeout = |
861 (connection->write_state() == Connection::STATE_WRITE_TIMEOUT); | 856 (connection->write_state() == Connection::STATE_WRITE_TIMEOUT); |
862 info.new_connection = !connection->reported(); | 857 info.new_connection = !connection->reported(); |
863 connection->set_reported(true); | 858 connection->set_reported(true); |
(...skipping 14 matching lines...) Expand all Loading... |
878 } | 873 } |
879 | 874 |
880 rtc::DiffServCodePoint P2PTransportChannel::DefaultDscpValue() const { | 875 rtc::DiffServCodePoint P2PTransportChannel::DefaultDscpValue() const { |
881 OptionMap::const_iterator it = options_.find(rtc::Socket::OPT_DSCP); | 876 OptionMap::const_iterator it = options_.find(rtc::Socket::OPT_DSCP); |
882 if (it == options_.end()) { | 877 if (it == options_.end()) { |
883 return rtc::DSCP_NO_CHANGE; | 878 return rtc::DSCP_NO_CHANGE; |
884 } | 879 } |
885 return static_cast<rtc::DiffServCodePoint> (it->second); | 880 return static_cast<rtc::DiffServCodePoint> (it->second); |
886 } | 881 } |
887 | 882 |
888 // Begin allocate (or immediately re-allocate, if MSG_ALLOCATE pending) | 883 void P2PTransportChannel::StartGatheringCandidates() { |
889 void P2PTransportChannel::Allocate() { | 884 // Time for a new allocator |
890 // Time for a new allocator, lets make sure we have a signalling channel | 885 if (gathering_state_ != kIceGatheringGathering) { |
891 // to communicate candidates through first. | 886 gathering_state_ = kIceGatheringGathering; |
892 waiting_for_signaling_ = true; | 887 SignalGatheringState(this); |
893 SignalRequestSignaling(this); | 888 } |
| 889 AddAllocatorSession(allocator_->CreateSession( |
| 890 SessionId(), transport_name(), component(), ice_ufrag_, ice_pwd_)); |
894 } | 891 } |
895 | 892 |
896 // Monitor connection states. | 893 // Monitor connection states. |
897 void P2PTransportChannel::UpdateConnectionStates() { | 894 void P2PTransportChannel::UpdateConnectionStates() { |
898 uint32 now = rtc::Time(); | 895 uint32 now = rtc::Time(); |
899 | 896 |
900 // We need to copy the list of connections since some may delete themselves | 897 // We need to copy the list of connections since some may delete themselves |
901 // when we call UpdateState. | 898 // when we call UpdateState. |
902 for (uint32 i = 0; i < connections_.size(); ++i) | 899 for (uint32 i = 0; i < connections_.size(); ++i) |
903 connections_[i]->UpdateState(now); | 900 connections_[i]->UpdateState(now); |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1245 // a.1) |conn| is the best connection OR | 1242 // a.1) |conn| is the best connection OR |
1246 // a.2) there is no best connection OR | 1243 // a.2) there is no best connection OR |
1247 // a.3) the best connection is unwritable OR | 1244 // a.3) the best connection is unwritable OR |
1248 // a.4) |conn| has higher priority than best_connection. | 1245 // a.4) |conn| has higher priority than best_connection. |
1249 // b) we're doing LITE ICE AND | 1246 // b) we're doing LITE ICE AND |
1250 // b.1) |conn| is the best_connection AND | 1247 // b.1) |conn| is the best_connection AND |
1251 // b.2) |conn| is writable. | 1248 // b.2) |conn| is writable. |
1252 void P2PTransportChannel::PingConnection(Connection* conn) { | 1249 void P2PTransportChannel::PingConnection(Connection* conn) { |
1253 bool use_candidate = false; | 1250 bool use_candidate = false; |
1254 if (remote_ice_mode_ == ICEMODE_FULL && ice_role_ == ICEROLE_CONTROLLING) { | 1251 if (remote_ice_mode_ == ICEMODE_FULL && ice_role_ == ICEROLE_CONTROLLING) { |
1255 use_candidate = (conn == best_connection_) || | 1252 use_candidate = (conn == best_connection_) || (best_connection_ == NULL) || |
1256 (best_connection_ == NULL) || | |
1257 (!best_connection_->writable()) || | 1253 (!best_connection_->writable()) || |
1258 (conn->priority() > best_connection_->priority()); | 1254 (conn->priority() > best_connection_->priority()); |
1259 } else if (remote_ice_mode_ == ICEMODE_LITE && conn == best_connection_) { | 1255 } else if (remote_ice_mode_ == ICEMODE_LITE && conn == best_connection_) { |
1260 use_candidate = best_connection_->writable(); | 1256 use_candidate = best_connection_->writable(); |
1261 } | 1257 } |
1262 conn->set_use_candidate_attr(use_candidate); | 1258 conn->set_use_candidate_attr(use_candidate); |
1263 conn->Ping(rtc::Time()); | 1259 conn->Ping(rtc::Time()); |
1264 } | 1260 } |
1265 | 1261 |
1266 // When a connection's state changes, we need to figure out who to use as | 1262 // 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 Loading... |
1328 std::vector<PortInterface*>::iterator iter = | 1324 std::vector<PortInterface*>::iterator iter = |
1329 std::find(ports_.begin(), ports_.end(), port); | 1325 std::find(ports_.begin(), ports_.end(), port); |
1330 if (iter != ports_.end()) | 1326 if (iter != ports_.end()) |
1331 ports_.erase(iter); | 1327 ports_.erase(iter); |
1332 | 1328 |
1333 LOG(INFO) << "Removed port from p2p socket: " | 1329 LOG(INFO) << "Removed port from p2p socket: " |
1334 << static_cast<int>(ports_.size()) << " remaining"; | 1330 << static_cast<int>(ports_.size()) << " remaining"; |
1335 } | 1331 } |
1336 | 1332 |
1337 // We data is available, let listeners know | 1333 // We data is available, let listeners know |
1338 void P2PTransportChannel::OnReadPacket( | 1334 void P2PTransportChannel::OnReadPacket(Connection* connection, |
1339 Connection *connection, const char *data, size_t len, | 1335 const char* data, |
1340 const rtc::PacketTime& packet_time) { | 1336 size_t len, |
| 1337 const rtc::PacketTime& packet_time) { |
1341 ASSERT(worker_thread_ == rtc::Thread::Current()); | 1338 ASSERT(worker_thread_ == rtc::Thread::Current()); |
1342 | 1339 |
1343 // Do not deliver, if packet doesn't belong to the correct transport channel. | 1340 // Do not deliver, if packet doesn't belong to the correct transport channel. |
1344 if (!FindConnection(connection)) | 1341 if (!FindConnection(connection)) |
1345 return; | 1342 return; |
1346 | 1343 |
1347 // Let the client know of an incoming packet | 1344 // Let the client know of an incoming packet |
1348 SignalReadPacket(this, data, len, packet_time, 0); | 1345 SignalReadPacket(this, data, len, packet_time, 0); |
1349 | 1346 |
1350 // May need to switch the sending connection based on the receiving media path | 1347 // May need to switch the sending connection based on the receiving media path |
1351 // if this is the controlled side. | 1348 // if this is the controlled side. |
1352 if (ice_role_ == ICEROLE_CONTROLLED && !best_nominated_connection() && | 1349 if (ice_role_ == ICEROLE_CONTROLLED && !best_nominated_connection() && |
1353 connection->writable() && best_connection_ != connection) { | 1350 connection->writable() && best_connection_ != connection) { |
1354 SwitchBestConnectionTo(connection); | 1351 SwitchBestConnectionTo(connection); |
1355 } | 1352 } |
1356 } | 1353 } |
1357 | 1354 |
1358 void P2PTransportChannel::OnReadyToSend(Connection* connection) { | 1355 void P2PTransportChannel::OnReadyToSend(Connection* connection) { |
1359 if (connection == best_connection_ && writable()) { | 1356 if (connection == best_connection_ && writable()) { |
1360 SignalReadyToSend(this); | 1357 SignalReadyToSend(this); |
1361 } | 1358 } |
1362 } | 1359 } |
1363 | 1360 |
1364 } // namespace cricket | 1361 } // namespace cricket |
OLD | NEW |