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 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 19 matching lines...) Expand all Loading... | |
223 connection->set_remote_ice_mode(remote_ice_mode_); | 223 connection->set_remote_ice_mode(remote_ice_mode_); |
224 connection->SignalReadPacket.connect( | 224 connection->SignalReadPacket.connect( |
225 this, &P2PTransportChannel::OnReadPacket); | 225 this, &P2PTransportChannel::OnReadPacket); |
226 connection->SignalReadyToSend.connect( | 226 connection->SignalReadyToSend.connect( |
227 this, &P2PTransportChannel::OnReadyToSend); | 227 this, &P2PTransportChannel::OnReadyToSend); |
228 connection->SignalStateChange.connect( | 228 connection->SignalStateChange.connect( |
229 this, &P2PTransportChannel::OnConnectionStateChange); | 229 this, &P2PTransportChannel::OnConnectionStateChange); |
230 connection->SignalDestroyed.connect( | 230 connection->SignalDestroyed.connect( |
231 this, &P2PTransportChannel::OnConnectionDestroyed); | 231 this, &P2PTransportChannel::OnConnectionDestroyed); |
232 connection->SignalNominated.connect(this, &P2PTransportChannel::OnNominated); | 232 connection->SignalNominated.connect(this, &P2PTransportChannel::OnNominated); |
233 had_connection_ = true; | |
233 } | 234 } |
234 | 235 |
235 void P2PTransportChannel::SetIceRole(IceRole ice_role) { | 236 void P2PTransportChannel::SetIceRole(IceRole ice_role) { |
236 ASSERT(worker_thread_ == rtc::Thread::Current()); | 237 ASSERT(worker_thread_ == rtc::Thread::Current()); |
237 if (ice_role_ != ice_role) { | 238 if (ice_role_ != ice_role) { |
238 ice_role_ = ice_role; | 239 ice_role_ = ice_role; |
239 for (std::vector<PortInterface *>::iterator it = ports_.begin(); | 240 for (std::vector<PortInterface *>::iterator it = ports_.begin(); |
240 it != ports_.end(); ++it) { | 241 it != ports_.end(); ++it) { |
241 (*it)->SetIceRole(ice_role); | 242 (*it)->SetIceRole(ice_role); |
242 } | 243 } |
(...skipping 14 matching lines...) Expand all Loading... | |
257 // Currently a channel is considered ICE completed once there is no | 258 // Currently a channel is considered ICE completed once there is no |
258 // more than one connection per Network. This works for a single NIC | 259 // more than one connection per Network. This works for a single NIC |
259 // with both IPv4 and IPv6 enabled. However, this condition won't | 260 // with both IPv4 and IPv6 enabled. However, this condition won't |
260 // happen when there are multiple NICs and all of them have | 261 // happen when there are multiple NICs and all of them have |
261 // connectivity. | 262 // connectivity. |
262 // TODO(guoweis): Change Completion to be driven by a channel level | 263 // TODO(guoweis): Change Completion to be driven by a channel level |
263 // timer. | 264 // timer. |
264 TransportChannelState P2PTransportChannel::GetState() const { | 265 TransportChannelState P2PTransportChannel::GetState() const { |
265 std::set<rtc::Network*> networks; | 266 std::set<rtc::Network*> networks; |
266 | 267 |
267 if (connections_.size() == 0) { | 268 if (connections_.empty()) { |
268 return TransportChannelState::STATE_FAILED; | 269 return had_connection_ ? TransportChannelState::STATE_FAILED |
270 : TransportChannelState::STATE_INIT; | |
269 } | 271 } |
270 | 272 |
271 for (uint32 i = 0; i < connections_.size(); ++i) { | 273 for (uint32 i = 0; i < connections_.size(); ++i) { |
272 rtc::Network* network = connections_[i]->port()->Network(); | 274 rtc::Network* network = connections_[i]->port()->Network(); |
273 if (networks.find(network) == networks.end()) { | 275 if (networks.find(network) == networks.end()) { |
274 networks.insert(network); | 276 networks.insert(network); |
275 } else { | 277 } else { |
276 LOG_J(LS_VERBOSE, this) << "Ice not completed yet for this channel as " | 278 LOG_J(LS_VERBOSE, this) << "Ice not completed yet for this channel as " |
277 << network->ToString() | 279 << network->ToString() |
278 << " has more than 1 connection."; | 280 << " has more than 1 connection."; |
(...skipping 13 matching lines...) Expand all Loading... | |
292 // Restart candidate allocation if there is any change in either | 294 // Restart candidate allocation if there is any change in either |
293 // ice ufrag or password. | 295 // ice ufrag or password. |
294 ice_restart = | 296 ice_restart = |
295 IceCredentialsChanged(ice_ufrag_, ice_pwd_, ice_ufrag, ice_pwd); | 297 IceCredentialsChanged(ice_ufrag_, ice_pwd_, ice_ufrag, ice_pwd); |
296 } | 298 } |
297 | 299 |
298 ice_ufrag_ = ice_ufrag; | 300 ice_ufrag_ = ice_ufrag; |
299 ice_pwd_ = ice_pwd; | 301 ice_pwd_ = ice_pwd; |
300 | 302 |
301 if (ice_restart) { | 303 if (ice_restart) { |
302 // Restart candidate gathering. | 304 // Need to restart candidate gathering. |
303 Allocate(); | 305 // Someone should call MaybeStartGathering in the near future to do this. |
306 need_to_gather_candidates_ = true; | |
pthatcher1
2015/09/19 00:08:05
What if we use "gathering_state_ = new;" instead?
| |
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 // Go into the state of processing candidates, and running in general | 350 // Go into the state of processing candidates, and running in general |
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 | |
358 Allocate(); | |
359 | |
360 // Start pinging as the ports come in. | 360 // Start pinging as the ports come in. |
361 thread()->Post(this, MSG_PING); | 361 thread()->Post(this, MSG_PING); |
362 | 362 |
363 thread()->PostDelayed( | 363 thread()->PostDelayed( |
364 check_receiving_delay_, this, MSG_CHECK_RECEIVING); | 364 check_receiving_delay_, this, MSG_CHECK_RECEIVING); |
365 } | 365 } |
366 | 366 |
367 void P2PTransportChannel::MaybeStartGathering() { | |
368 if (need_to_gather_candidates_) { | |
369 need_to_gather_candidates_ = false; | |
370 if (gathering_state_ != kIceGatheringGathering) { | |
371 gathering_state_ = kIceGatheringGathering; | |
372 SignalGatheringState(this); | |
373 } | |
374 // Time for a new allocator | |
375 AddAllocatorSession(allocator_->CreateSession( | |
376 SessionId(), transport_name(), component(), ice_ufrag_, ice_pwd_)); | |
377 } | |
378 } | |
379 | |
367 // A new port is available, attempt to make connections for it | 380 // A new port is available, attempt to make connections for it |
368 void P2PTransportChannel::OnPortReady(PortAllocatorSession *session, | 381 void P2PTransportChannel::OnPortReady(PortAllocatorSession *session, |
369 PortInterface* port) { | 382 PortInterface* port) { |
370 ASSERT(worker_thread_ == rtc::Thread::Current()); | 383 ASSERT(worker_thread_ == rtc::Thread::Current()); |
371 | 384 |
372 // Set in-effect options on the new port | 385 // Set in-effect options on the new port |
373 for (OptionMap::const_iterator it = options_.begin(); | 386 for (OptionMap::const_iterator it = options_.begin(); |
374 it != options_.end(); | 387 it != options_.end(); |
375 ++it) { | 388 ++it) { |
376 int val = port->SetOption(it->first, it->second); | 389 int val = port->SetOption(it->first, it->second); |
(...skipping 24 matching lines...) Expand all Loading... | |
401 for (iter = remote_candidates_.begin(); iter != remote_candidates_.end(); | 414 for (iter = remote_candidates_.begin(); iter != remote_candidates_.end(); |
402 ++iter) { | 415 ++iter) { |
403 CreateConnection(port, *iter, iter->origin_port(), false); | 416 CreateConnection(port, *iter, iter->origin_port(), false); |
404 } | 417 } |
405 | 418 |
406 SortConnections(); | 419 SortConnections(); |
407 } | 420 } |
408 | 421 |
409 // A new candidate is available, let listeners know | 422 // A new candidate is available, let listeners know |
410 void P2PTransportChannel::OnCandidatesReady( | 423 void P2PTransportChannel::OnCandidatesReady( |
411 PortAllocatorSession *session, const std::vector<Candidate>& candidates) { | 424 PortAllocatorSession* session, |
425 const std::vector<Candidate>& candidates) { | |
412 ASSERT(worker_thread_ == rtc::Thread::Current()); | 426 ASSERT(worker_thread_ == rtc::Thread::Current()); |
413 for (size_t i = 0; i < candidates.size(); ++i) { | 427 for (size_t i = 0; i < candidates.size(); ++i) { |
414 SignalCandidateReady(this, candidates[i]); | 428 SignalCandidateGathered(this, candidates[i]); |
415 } | 429 } |
416 } | 430 } |
417 | 431 |
418 void P2PTransportChannel::OnCandidatesAllocationDone( | 432 void P2PTransportChannel::OnCandidatesAllocationDone( |
419 PortAllocatorSession* session) { | 433 PortAllocatorSession* session) { |
420 ASSERT(worker_thread_ == rtc::Thread::Current()); | 434 ASSERT(worker_thread_ == rtc::Thread::Current()); |
421 SignalCandidatesAllocationDone(this); | 435 gathering_state_ = kIceGatheringComplete; |
436 LOG(LS_INFO) << "P2PTransportChannel: " << transport_name() << ", component " | |
437 << component() << " gathering complete"; | |
438 SignalGatheringState(this); | |
422 } | 439 } |
423 | 440 |
424 // Handle stun packets | 441 // Handle stun packets |
425 void P2PTransportChannel::OnUnknownAddress( | 442 void P2PTransportChannel::OnUnknownAddress( |
426 PortInterface* port, | 443 PortInterface* port, |
427 const rtc::SocketAddress& address, ProtocolType proto, | 444 const rtc::SocketAddress& address, ProtocolType proto, |
428 IceMessage* stun_msg, const std::string &remote_username, | 445 IceMessage* stun_msg, const std::string &remote_username, |
429 bool port_muxed) { | 446 bool port_muxed) { |
430 ASSERT(worker_thread_ == rtc::Thread::Current()); | 447 ASSERT(worker_thread_ == rtc::Thread::Current()); |
431 | 448 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
482 int remote_candidate_priority; | 499 int remote_candidate_priority; |
483 | 500 |
484 // The priority of the candidate is set to the PRIORITY attribute | 501 // The priority of the candidate is set to the PRIORITY attribute |
485 // from the request. | 502 // from the request. |
486 const StunUInt32Attribute* priority_attr = | 503 const StunUInt32Attribute* priority_attr = |
487 stun_msg->GetUInt32(STUN_ATTR_PRIORITY); | 504 stun_msg->GetUInt32(STUN_ATTR_PRIORITY); |
488 if (!priority_attr) { | 505 if (!priority_attr) { |
489 LOG(LS_WARNING) << "P2PTransportChannel::OnUnknownAddress - " | 506 LOG(LS_WARNING) << "P2PTransportChannel::OnUnknownAddress - " |
490 << "No STUN_ATTR_PRIORITY found in the " | 507 << "No STUN_ATTR_PRIORITY found in the " |
491 << "stun request message"; | 508 << "stun request message"; |
492 port->SendBindingErrorResponse(stun_msg, address, | 509 port->SendBindingErrorResponse(stun_msg, address, STUN_ERROR_BAD_REQUEST, |
493 STUN_ERROR_BAD_REQUEST, | |
494 STUN_ERROR_REASON_BAD_REQUEST); | 510 STUN_ERROR_REASON_BAD_REQUEST); |
495 return; | 511 return; |
496 } | 512 } |
497 remote_candidate_priority = priority_attr->value(); | 513 remote_candidate_priority = priority_attr->value(); |
498 | 514 |
499 // RFC 5245 | 515 // RFC 5245 |
500 // If the source transport address of the request does not match any | 516 // If the source transport address of the request does not match any |
501 // existing remote candidates, it represents a new peer reflexive remote | 517 // existing remote candidates, it represents a new peer reflexive remote |
502 // candidate. | 518 // candidate. |
503 remote_candidate = | 519 remote_candidate = |
(...skipping 29 matching lines...) Expand all Loading... | |
533 STUN_ERROR_SERVER_ERROR, | 549 STUN_ERROR_SERVER_ERROR, |
534 STUN_ERROR_REASON_SERVER_ERROR); | 550 STUN_ERROR_REASON_SERVER_ERROR); |
535 return; | 551 return; |
536 } | 552 } |
537 } | 553 } |
538 | 554 |
539 Connection* connection = port->CreateConnection( | 555 Connection* connection = port->CreateConnection( |
540 remote_candidate, cricket::PortInterface::ORIGIN_THIS_PORT); | 556 remote_candidate, cricket::PortInterface::ORIGIN_THIS_PORT); |
541 if (!connection) { | 557 if (!connection) { |
542 ASSERT(false); | 558 ASSERT(false); |
543 port->SendBindingErrorResponse(stun_msg, address, | 559 port->SendBindingErrorResponse(stun_msg, address, STUN_ERROR_SERVER_ERROR, |
544 STUN_ERROR_SERVER_ERROR, | |
545 STUN_ERROR_REASON_SERVER_ERROR); | 560 STUN_ERROR_REASON_SERVER_ERROR); |
546 return; | 561 return; |
547 } | 562 } |
548 | 563 |
549 LOG(LS_INFO) << "Adding connection from " | 564 LOG(LS_INFO) << "Adding connection from " |
550 << (remote_candidate_is_new ? "peer reflexive" : "resurrected") | 565 << (remote_candidate_is_new ? "peer reflexive" : "resurrected") |
551 << " candidate: " << remote_candidate.ToString(); | 566 << " candidate: " << remote_candidate.ToString(); |
552 AddConnection(connection); | 567 AddConnection(connection); |
553 connection->ReceivedPing(); | 568 connection->ReceivedPing(); |
554 | 569 |
555 bool received_use_candidate = | 570 bool received_use_candidate = |
556 stun_msg->GetByteString(STUN_ATTR_USE_CANDIDATE) != nullptr; | 571 stun_msg->GetByteString(STUN_ATTR_USE_CANDIDATE) != nullptr; |
557 if (received_use_candidate && ice_role_ == ICEROLE_CONTROLLED) { | 572 if (received_use_candidate && ice_role_ == ICEROLE_CONTROLLED) { |
558 connection->set_nominated(true); | 573 connection->set_nominated(true); |
559 OnNominated(connection); | 574 OnNominated(connection); |
560 } | 575 } |
561 | 576 |
562 // Update the list of connections since we just added another. We do this | 577 // 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 | 578 // after sending the response since it could (in principle) delete the |
564 // connection in question. | 579 // connection in question. |
565 SortConnections(); | 580 SortConnections(); |
566 } | 581 } |
567 | 582 |
568 void P2PTransportChannel::OnRoleConflict(PortInterface* port) { | 583 void P2PTransportChannel::OnRoleConflict(PortInterface* port) { |
569 SignalRoleConflict(this); // STUN ping will be sent when SetRole is called | 584 SignalRoleConflict(this); // STUN ping will be sent when SetRole is called |
570 // from Transport. | 585 // from Transport. |
571 } | 586 } |
572 | 587 |
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) { | 588 void P2PTransportChannel::OnNominated(Connection* conn) { |
584 ASSERT(worker_thread_ == rtc::Thread::Current()); | 589 ASSERT(worker_thread_ == rtc::Thread::Current()); |
585 ASSERT(ice_role_ == ICEROLE_CONTROLLED); | 590 ASSERT(ice_role_ == ICEROLE_CONTROLLED); |
586 | 591 |
587 if (conn->write_state() == Connection::STATE_WRITABLE) { | 592 if (conn->write_state() == Connection::STATE_WRITABLE) { |
588 if (best_connection_ != conn) { | 593 if (best_connection_ != conn) { |
589 pending_best_connection_ = NULL; | 594 pending_best_connection_ = NULL; |
590 LOG(LS_INFO) << "Switching best connection on controlled side: " | 595 LOG(LS_INFO) << "Switching best connection on controlled side: " |
591 << conn->ToString(); | 596 << conn->ToString(); |
592 SwitchBestConnectionTo(conn); | 597 SwitchBestConnectionTo(conn); |
593 // Now we have selected the best connection, time to prune other existing | 598 // Now we have selected the best connection, time to prune other existing |
594 // connections and update the read/write state of the channel. | 599 // connections and update the read/write state of the channel. |
595 RequestSort(); | 600 RequestSort(); |
596 } | 601 } |
597 } else { | 602 } else { |
598 LOG(LS_INFO) << "Not switching the best connection on controlled side yet," | 603 LOG(LS_INFO) << "Not switching the best connection on controlled side yet," |
599 << " because it's not writable: " << conn->ToString(); | 604 << " because it's not writable: " << conn->ToString(); |
600 pending_best_connection_ = conn; | 605 pending_best_connection_ = conn; |
601 } | 606 } |
602 } | 607 } |
603 | 608 |
604 void P2PTransportChannel::OnCandidate(const Candidate& candidate) { | 609 void P2PTransportChannel::AddRemoteCandidate(const Candidate& candidate) { |
605 ASSERT(worker_thread_ == rtc::Thread::Current()); | 610 ASSERT(worker_thread_ == rtc::Thread::Current()); |
606 | 611 |
607 uint32 generation = candidate.generation(); | 612 uint32 generation = candidate.generation(); |
608 // Network may not guarantee the order of the candidate delivery. If a | 613 // Network may not guarantee the order of the candidate delivery. If a |
609 // remote candidate with an older generation arrives, drop it. | 614 // remote candidate with an older generation arrives, drop it. |
610 if (generation != 0 && generation < remote_candidate_generation_) { | 615 if (generation != 0 && generation < remote_candidate_generation_) { |
611 LOG(LS_WARNING) << "Dropping a remote candidate because its generation " | 616 LOG(LS_WARNING) << "Dropping a remote candidate because its generation " |
612 << generation | 617 << generation |
613 << " is lower than the current remote generation " | 618 << " is lower than the current remote generation " |
614 << remote_candidate_generation_; | 619 << remote_candidate_generation_; |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
843 return sent; | 848 return sent; |
844 } | 849 } |
845 | 850 |
846 bool P2PTransportChannel::GetStats(ConnectionInfos *infos) { | 851 bool P2PTransportChannel::GetStats(ConnectionInfos *infos) { |
847 ASSERT(worker_thread_ == rtc::Thread::Current()); | 852 ASSERT(worker_thread_ == rtc::Thread::Current()); |
848 // Gather connection infos. | 853 // Gather connection infos. |
849 infos->clear(); | 854 infos->clear(); |
850 | 855 |
851 std::vector<Connection *>::const_iterator it; | 856 std::vector<Connection *>::const_iterator it; |
852 for (it = connections_.begin(); it != connections_.end(); ++it) { | 857 for (it = connections_.begin(); it != connections_.end(); ++it) { |
853 Connection *connection = *it; | 858 Connection* connection = *it; |
854 ConnectionInfo info; | 859 ConnectionInfo info; |
855 info.best_connection = (best_connection_ == connection); | 860 info.best_connection = (best_connection_ == connection); |
856 info.readable = | 861 info.readable = |
857 (connection->read_state() == Connection::STATE_READABLE); | 862 (connection->read_state() == Connection::STATE_READABLE); |
858 info.writable = | 863 info.writable = |
859 (connection->write_state() == Connection::STATE_WRITABLE); | 864 (connection->write_state() == Connection::STATE_WRITABLE); |
860 info.timeout = | 865 info.timeout = |
861 (connection->write_state() == Connection::STATE_WRITE_TIMEOUT); | 866 (connection->write_state() == Connection::STATE_WRITE_TIMEOUT); |
862 info.new_connection = !connection->reported(); | 867 info.new_connection = !connection->reported(); |
863 connection->set_reported(true); | 868 connection->set_reported(true); |
(...skipping 14 matching lines...) Expand all Loading... | |
878 } | 883 } |
879 | 884 |
880 rtc::DiffServCodePoint P2PTransportChannel::DefaultDscpValue() const { | 885 rtc::DiffServCodePoint P2PTransportChannel::DefaultDscpValue() const { |
881 OptionMap::const_iterator it = options_.find(rtc::Socket::OPT_DSCP); | 886 OptionMap::const_iterator it = options_.find(rtc::Socket::OPT_DSCP); |
882 if (it == options_.end()) { | 887 if (it == options_.end()) { |
883 return rtc::DSCP_NO_CHANGE; | 888 return rtc::DSCP_NO_CHANGE; |
884 } | 889 } |
885 return static_cast<rtc::DiffServCodePoint> (it->second); | 890 return static_cast<rtc::DiffServCodePoint> (it->second); |
886 } | 891 } |
887 | 892 |
888 // Begin allocate (or immediately re-allocate, if MSG_ALLOCATE pending) | |
889 void P2PTransportChannel::Allocate() { | |
890 // Time for a new allocator, lets make sure we have a signalling channel | |
891 // to communicate candidates through first. | |
892 waiting_for_signaling_ = true; | |
893 SignalRequestSignaling(this); | |
894 } | |
895 | |
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); |
904 } | 901 } |
905 | 902 |
(...skipping 339 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 |