Chromium Code Reviews| Index: webrtc/p2p/base/p2ptransportchannel.cc |
| diff --git a/webrtc/p2p/base/p2ptransportchannel.cc b/webrtc/p2p/base/p2ptransportchannel.cc |
| index 46ed40ad76f9ced65929339594e5757ae435bb32..15cd85f493e1c859112cb2cac7c0d8b6eed09252 100644 |
| --- a/webrtc/p2p/base/p2ptransportchannel.cc |
| +++ b/webrtc/p2p/base/p2ptransportchannel.cc |
| @@ -124,14 +124,6 @@ class ConnectionCompare { |
| cricket::Connection* a = const_cast<cricket::Connection*>(ca); |
| cricket::Connection* b = const_cast<cricket::Connection*>(cb); |
| - // The IceProtocol is initialized to ICEPROTO_HYBRID and can be updated to |
| - // GICE or RFC5245 when an answer SDP is set, or when a STUN message is |
| - // received. So the port receiving the STUN message may have a different |
| - // IceProtocol if the answer SDP is not set yet. |
| - ASSERT(a->port()->IceProtocol() == b->port()->IceProtocol() || |
| - a->port()->IceProtocol() == cricket::ICEPROTO_HYBRID || |
| - b->port()->IceProtocol() == cricket::ICEPROTO_HYBRID); |
| - |
| // Compare first on writability and static preferences. |
| int cmp = CompareConnections(a, b); |
| if (cmp > 0) |
| @@ -192,7 +184,6 @@ P2PTransportChannel::P2PTransportChannel(const std::string& content_name, |
| pending_best_connection_(NULL), |
| sort_dirty_(false), |
| was_writable_(false), |
| - protocol_type_(ICEPROTO_HYBRID), |
| remote_ice_mode_(ICEMODE_FULL), |
| ice_role_(ICEROLE_UNKNOWN), |
| tiebreaker_(0), |
| @@ -294,21 +285,6 @@ TransportChannelState P2PTransportChannel::GetState() const { |
| return TransportChannelState::STATE_COMPLETED; |
| } |
| -bool P2PTransportChannel::GetIceProtocolType(IceProtocolType* type) const { |
| - *type = protocol_type_; |
| - return true; |
| -} |
| - |
| -void P2PTransportChannel::SetIceProtocolType(IceProtocolType type) { |
| - ASSERT(worker_thread_ == rtc::Thread::Current()); |
| - |
| - protocol_type_ = type; |
| - for (std::vector<PortInterface *>::iterator it = ports_.begin(); |
| - it != ports_.end(); ++it) { |
| - (*it)->SetIceProtocolType(protocol_type_); |
| - } |
| -} |
| - |
| void P2PTransportChannel::SetIceCredentials(const std::string& ice_ufrag, |
| const std::string& ice_pwd) { |
| ASSERT(worker_thread_ == rtc::Thread::Current()); |
| @@ -348,9 +324,8 @@ void P2PTransportChannel::SetRemoteIceCredentials(const std::string& ice_ufrag, |
| } |
| if (ice_restart) { |
| - // |candidate.generation()| is not signaled in ICEPROTO_RFC5245. |
| - // Therefore we need to keep track of the remote ice restart so |
| - // newer connections are prioritized over the older. |
| + // We need to keep track of the remote ice restart so newer |
| + // connections are prioritized over the older. |
| ++remote_candidate_generation_; |
| } |
| } |
| @@ -411,7 +386,6 @@ void P2PTransportChannel::OnPortReady(PortAllocatorSession *session, |
| // The session will handle this, and send an initiate/accept/modify message |
| // if one is pending. |
| - port->SetIceProtocolType(protocol_type_); |
| port->SetIceRole(ice_role_); |
| port->SetIceTiebreaker(tiebreaker_); |
| ports_.push_back(port); |
| @@ -508,44 +482,30 @@ void P2PTransportChannel::OnUnknownAddress( |
| // Create a new candidate with this address. |
| std::string type; |
| int remote_candidate_priority; |
| - if (port->IceProtocol() == ICEPROTO_RFC5245) { |
| - // RFC 5245 |
| - // If the source transport address of the request does not match any |
| - // existing remote candidates, it represents a new peer reflexive remote |
| - // candidate. |
| - type = PRFLX_PORT_TYPE; |
| - |
| - // The priority of the candidate is set to the PRIORITY attribute |
| - // from the request. |
| - const StunUInt32Attribute* priority_attr = |
| - stun_msg->GetUInt32(STUN_ATTR_PRIORITY); |
| - if (!priority_attr) { |
| - LOG(LS_WARNING) << "P2PTransportChannel::OnUnknownAddress - " |
| - << "No STUN_ATTR_PRIORITY found in the " |
| - << "stun request message"; |
| - port->SendBindingErrorResponse(stun_msg, address, |
| - STUN_ERROR_BAD_REQUEST, |
| - STUN_ERROR_REASON_BAD_REQUEST); |
| - return; |
| - } |
| - remote_candidate_priority = priority_attr->value(); |
| - } else { |
| - // G-ICE doesn't support prflx candidate. |
| - // We set candidate type to STUN_PORT_TYPE if the binding request comes |
| - // from a relay port or the shared socket is used. Otherwise we use the |
| - // port's type as the candidate type. |
| - if (port->Type() == RELAY_PORT_TYPE || port->SharedSocket()) { |
| - type = STUN_PORT_TYPE; |
| - } else { |
| - type = port->Type(); |
| - } |
| - remote_candidate_priority = remote_candidate.GetPriority( |
| - ICE_TYPE_PREFERENCE_PRFLX, port->Network()->preference(), 0); |
| + // RFC 5245 |
| + // If the source transport address of the request does not match any |
| + // existing remote candidates, it represents a new peer reflexive remote |
| + // candidate. |
| + type = PRFLX_PORT_TYPE; |
|
Taylor Brandstetter
2015/07/28 23:57:03
Looks like the "type" variable isn't used any more
pthatcher1
2015/07/29 17:29:25
Good idea.
Done.
|
| + |
| + // The priority of the candidate is set to the PRIORITY attribute |
| + // from the request. |
| + const StunUInt32Attribute* priority_attr = |
| + stun_msg->GetUInt32(STUN_ATTR_PRIORITY); |
| + if (!priority_attr) { |
| + LOG(LS_WARNING) << "P2PTransportChannel::OnUnknownAddress - " |
| + << "No STUN_ATTR_PRIORITY found in the " |
| + << "stun request message"; |
| + port->SendBindingErrorResponse(stun_msg, address, |
| + STUN_ERROR_BAD_REQUEST, |
| + STUN_ERROR_REASON_BAD_REQUEST); |
| + return; |
| } |
| + remote_candidate_priority = priority_attr->value(); |
| remote_candidate = |
| Candidate(component(), ProtoToString(proto), address, 0, |
| - remote_username, remote_password, type, 0U, ""); |
| + remote_username, remote_password, PRFLX_PORT_TYPE, 0U, ""); |
| // From RFC 5245, section-7.2.1.3: |
| // The foundation of the candidate is set to an arbitrary value, different |
| @@ -556,74 +516,49 @@ void P2PTransportChannel::OnUnknownAddress( |
| remote_candidate.set_priority(remote_candidate_priority); |
| } |
| - if (port->IceProtocol() == ICEPROTO_RFC5245) { |
| - // RFC5245, the agent constructs a pair whose local candidate is equal to |
| - // the transport address on which the STUN request was received, and a |
| - // remote candidate equal to the source transport address where the |
| - // request came from. |
| - |
| - // There shouldn't be an existing connection with this remote address. |
| - // When ports are muxed, this channel might get multiple unknown address |
| - // signals. In that case if the connection is already exists, we should |
| - // simply ignore the signal othewise send server error. |
| - if (port->GetConnection(remote_candidate.address())) { |
| - if (port_muxed) { |
| - LOG(LS_INFO) << "Connection already exists for peer reflexive " |
| - << "candidate: " << remote_candidate.ToString(); |
| - return; |
| - } else { |
| - ASSERT(false); |
| - port->SendBindingErrorResponse(stun_msg, address, |
| - STUN_ERROR_SERVER_ERROR, |
| - STUN_ERROR_REASON_SERVER_ERROR); |
| - return; |
| - } |
| - } |
| + // RFC5245, the agent constructs a pair whose local candidate is equal to |
| + // the transport address on which the STUN request was received, and a |
| + // remote candidate equal to the source transport address where the |
| + // request came from. |
| - Connection* connection = port->CreateConnection( |
| - remote_candidate, cricket::PortInterface::ORIGIN_THIS_PORT); |
| - if (!connection) { |
| + // There shouldn't be an existing connection with this remote address. |
| + // When ports are muxed, this channel might get multiple unknown address |
| + // signals. In that case if the connection is already exists, we should |
| + // simply ignore the signal othewise send server error. |
| + if (port->GetConnection(remote_candidate.address())) { |
| + if (port_muxed) { |
| + LOG(LS_INFO) << "Connection already exists for peer reflexive " |
| + << "candidate: " << remote_candidate.ToString(); |
| + return; |
| + } else { |
| ASSERT(false); |
| port->SendBindingErrorResponse(stun_msg, address, |
| STUN_ERROR_SERVER_ERROR, |
| STUN_ERROR_REASON_SERVER_ERROR); |
| return; |
| } |
| + } |
| - LOG(LS_INFO) << "Adding connection from " |
| - << (remote_candidate_is_new ? "peer reflexive" : "resurrected") |
| - << " candidate: " << remote_candidate.ToString(); |
| - AddConnection(connection); |
| - connection->ReceivedPing(); |
| - |
| - // Send the pinger a successful stun response. |
| - port->SendBindingResponse(stun_msg, address); |
| - |
| - // Update the list of connections since we just added another. We do this |
| - // after sending the response since it could (in principle) delete the |
| - // connection in question. |
| - SortConnections(); |
| - } else { |
| - // Check for connectivity to this address. Create connections |
| - // to this address across all local ports. First, add this as a new remote |
| - // address |
| - if (!CreateConnections(remote_candidate, port, true)) { |
| - // Hopefully this won't occur, because changing a destination address |
| - // shouldn't cause a new connection to fail |
| - ASSERT(false); |
| - port->SendBindingErrorResponse(stun_msg, address, STUN_ERROR_SERVER_ERROR, |
| - STUN_ERROR_REASON_SERVER_ERROR); |
| - return; |
| - } |
| + Connection* connection = port->CreateConnection( |
| + remote_candidate, cricket::PortInterface::ORIGIN_THIS_PORT); |
| + if (!connection) { |
| + ASSERT(false); |
| + port->SendBindingErrorResponse(stun_msg, address, |
| + STUN_ERROR_SERVER_ERROR, |
| + STUN_ERROR_REASON_SERVER_ERROR); |
| + return; |
| + } |
| - // Send the pinger a successful stun response. |
| - port->SendBindingResponse(stun_msg, address); |
| + LOG(LS_INFO) << "Adding connection from " |
| + << (remote_candidate_is_new ? "peer reflexive" : "resurrected") |
| + << " candidate: " << remote_candidate.ToString(); |
| + AddConnection(connection); |
| + connection->ReceivedPing(); |
| - // Update the list of connections since we just added another. We do this |
| - // after sending the response since it could (in principle) delete the |
| - // connection in question. |
| - SortConnections(); |
| - } |
| + // Update the list of connections since we just added another. We do this |
| + // after sending the response since it could (in principle) delete the |
| + // connection in question. |
| + SortConnections(); |
| } |
| void P2PTransportChannel::OnRoleConflict(PortInterface* port) { |
| @@ -644,7 +579,6 @@ void P2PTransportChannel::OnSignalingReady() { |
| void P2PTransportChannel::OnUseCandidate(Connection* conn) { |
| ASSERT(worker_thread_ == rtc::Thread::Current()); |
| ASSERT(ice_role_ == ICEROLE_CONTROLLED); |
| - ASSERT(protocol_type_ == ICEPROTO_RFC5245); |
| if (conn->write_state() == Connection::STATE_WRITABLE) { |
| if (best_connection_ != conn) { |
| @@ -792,13 +726,8 @@ bool P2PTransportChannel::FindConnection( |
| uint32 P2PTransportChannel::GetRemoteCandidateGeneration( |
| const Candidate& candidate) { |
| - if (protocol_type_ == ICEPROTO_GOOGLE) { |
| - // The Candidate.generation() can be trusted. Nothing needs to be done. |
| - return candidate.generation(); |
| - } |
| - // |candidate.generation()| is not signaled in ICEPROTO_RFC5245. |
| - // Therefore we need to keep track of the remote ice restart so |
| - // newer connections are prioritized over the older. |
| + // We need to keep track of the remote ice restart so newer |
| + // connections are prioritized over the older. |
| ASSERT(candidate.generation() == 0 || |
| candidate.generation() == remote_candidate_generation_); |
| return remote_candidate_generation_; |
| @@ -976,15 +905,6 @@ void P2PTransportChannel::SortConnections() { |
| // will be sorted. |
| UpdateConnectionStates(); |
| - if (protocol_type_ == ICEPROTO_HYBRID) { |
| - // If we are in hybrid mode, we are not sending any ping requests, so there |
| - // is no point in sorting the connections. In hybrid state, ports can have |
| - // different protocol than hybrid and protocol may differ from one another. |
| - // Instead just update the state of this channel |
| - UpdateChannelState(); |
| - return; |
| - } |
| - |
| // Any changes after this point will require a re-sort. |
| sort_dirty_ = false; |
| @@ -1009,12 +929,12 @@ void P2PTransportChannel::SortConnections() { |
| if (connections_.size() > 0) |
| top_connection = connections_[0]; |
| - // We don't want to pick the best connections if channel is using RFC5245 |
| - // and it's mode is CONTROLLED, as connections will be selected by the |
| - // CONTROLLING agent. |
| + // We don't want to pick the best connections if channel is is |
|
Taylor Brandstetter
2015/07/28 23:57:03
Minor typo here.
pthatcher1
2015/07/29 17:29:26
Good catch.
Fixed.
|
| + // CONTROLLED, as connections will be selected by the CONTROLLING |
| + // agent. |
| // If necessary, switch to the new choice. |
| - if (protocol_type_ != ICEPROTO_RFC5245 || ice_role_ == ICEROLE_CONTROLLING) { |
| + if (ice_role_ == ICEROLE_CONTROLLING) { |
| if (ShouldSwitch(best_connection_, top_connection)) { |
| LOG(LS_INFO) << "Switching best connection on controlling side: " |
| << top_connection->ToString(); |
| @@ -1273,8 +1193,7 @@ Connection* P2PTransportChannel::FindNextPingableConnection() { |
| continue; |
| } |
| bool needs_triggered_check = |
| - (protocol_type_ == ICEPROTO_RFC5245 && |
| - !conn->writable() && |
| + (!conn->writable() && |
| conn->last_ping_received() > conn->last_ping_sent()); |
| if (needs_triggered_check && |
| (!oldest_needing_triggered_check || |
| @@ -1309,15 +1228,13 @@ Connection* P2PTransportChannel::FindNextPingableConnection() { |
| // b.2) |conn| is writable. |
| void P2PTransportChannel::PingConnection(Connection* conn) { |
| bool use_candidate = false; |
| - if (protocol_type_ == ICEPROTO_RFC5245) { |
| - if (remote_ice_mode_ == ICEMODE_FULL && ice_role_ == ICEROLE_CONTROLLING) { |
| - use_candidate = (conn == best_connection_) || |
| - (best_connection_ == NULL) || |
| - (!best_connection_->writable()) || |
| - (conn->priority() > best_connection_->priority()); |
| - } else if (remote_ice_mode_ == ICEMODE_LITE && conn == best_connection_) { |
| - use_candidate = best_connection_->writable(); |
| - } |
| + if (remote_ice_mode_ == ICEMODE_FULL && ice_role_ == ICEROLE_CONTROLLING) { |
| + use_candidate = (conn == best_connection_) || |
| + (best_connection_ == NULL) || |
| + (!best_connection_->writable()) || |
| + (conn->priority() > best_connection_->priority()); |
| + } else if (remote_ice_mode_ == ICEMODE_LITE && conn == best_connection_) { |
| + use_candidate = best_connection_->writable(); |
| } |
| conn->set_use_candidate_attr(use_candidate); |
| conn->Ping(rtc::Time()); |
| @@ -1330,7 +1247,7 @@ void P2PTransportChannel::OnConnectionStateChange(Connection* connection) { |
| // Update the best connection if the state change is from pending best |
| // connection and role is controlled. |
| - if (protocol_type_ == ICEPROTO_RFC5245 && ice_role_ == ICEROLE_CONTROLLED) { |
| + if (ice_role_ == ICEROLE_CONTROLLED) { |
| if (connection == pending_best_connection_ && connection->writable()) { |
| pending_best_connection_ = NULL; |
| LOG(LS_INFO) << "Switching best connection on controlled side" |