Adding IceConfig option to assume TURN/TURN candidate pairs will work.
This will allow media to be sent on these pairs before a binding
response is received, shortening call setup time. However, this is only
possible if the TURN servers don't require CreatePermission when
communicating with each other.
R=honghaiz@webrtc.org, pthatcher@webrtc.org
NOTRY=True
Review-Url: https://codereview.webrtc.org/2063823008
Cr-Original-Commit-Position: refs/heads/master@{#13268}
Cr-Mirrored-From: https://chromium.googlesource.com/external/webrtc
Cr-Mirrored-Commit: 14f97f5bc65f2319642719d5a061a3747f586bb7
diff --git a/api/webrtcsession_unittest.cc b/api/webrtcsession_unittest.cc
index e8234d7..fab5e1a 100644
--- a/api/webrtcsession_unittest.cc
+++ b/api/webrtcsession_unittest.cc
@@ -2247,7 +2247,7 @@
candidates = local_desc->candidates(kMediaContentIndex0);
size_t num_local_candidates = candidates->count();
// Enable Continual Gathering
- session_->SetIceConfig(cricket::IceConfig(-1, -1, true, false, -1));
+ session_->SetIceConfig(cricket::IceConfig(-1, -1, true, false, -1, true));
// Bring down the network interface to trigger candidate removals.
RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
// Verify that all local candidates are removed.
diff --git a/p2p/base/p2ptransportchannel.cc b/p2p/base/p2ptransportchannel.cc
index 5c1f85d..86843db 100644
--- a/p2p/base/p2ptransportchannel.cc
+++ b/p2p/base/p2ptransportchannel.cc
@@ -32,7 +32,7 @@
// The minimum improvement in RTT that justifies a switch.
static const double kMinImprovement = 10;
-bool IsRelayRelay(cricket::Connection* conn) {
+bool IsRelayRelay(const cricket::Connection* conn) {
return conn->local_candidate().type() == cricket::RELAY_PORT_TYPE &&
conn->remote_candidate().type() == cricket::RELAY_PORT_TYPE;
}
@@ -51,155 +51,6 @@
return cricket::PortInterface::ORIGIN_OTHER_PORT;
}
-// Compares two connections based only on the candidate and network information.
-// Returns positive if |a| is better than |b|.
-int CompareConnectionCandidates(cricket::Connection* a,
- cricket::Connection* b) {
- uint32_t a_cost = a->ComputeNetworkCost();
- uint32_t b_cost = b->ComputeNetworkCost();
- // Smaller cost is better.
- if (a_cost < b_cost) {
- return 1;
- }
- if (a_cost > b_cost) {
- return -1;
- }
-
- // Compare connection priority. Lower values get sorted last.
- if (a->priority() > b->priority())
- return 1;
- if (a->priority() < b->priority())
- return -1;
-
- // If we're still tied at this point, prefer a younger generation.
- return (a->remote_candidate().generation() + a->port()->generation()) -
- (b->remote_candidate().generation() + b->port()->generation());
-}
-
-// Compare two connections based on their writing, receiving, and connected
-// states.
-int CompareConnectionStates(cricket::Connection* a, cricket::Connection* b) {
- // Sort based on write-state. Better states have lower values.
- if (a->write_state() < b->write_state())
- return 1;
- if (a->write_state() > b->write_state())
- return -1;
-
- // We prefer a receiving connection to a non-receiving, higher-priority
- // connection when sorting connections and choosing which connection to
- // switch to.
- if (a->receiving() && !b->receiving())
- return 1;
- if (!a->receiving() && b->receiving())
- return -1;
-
- // WARNING: Some complexity here about TCP reconnecting.
- // When a TCP connection fails because of a TCP socket disconnecting, the
- // active side of the connection will attempt to reconnect for 5 seconds while
- // pretending to be writable (the connection is not set to the unwritable
- // state). On the passive side, the connection also remains writable even
- // though it is disconnected, and a new connection is created when the active
- // side connects. At that point, there are two TCP connections on the passive
- // side: 1. the old, disconnected one that is pretending to be writable, and
- // 2. the new, connected one that is maybe not yet writable. For purposes of
- // pruning, pinging, and selecting the best connection, we want to treat the
- // new connection as "better" than the old one. We could add a method called
- // something like Connection::ImReallyBadEvenThoughImWritable, but that is
- // equivalent to the existing Connection::connected(), which we already have.
- // So, in code throughout this file, we'll check whether the connection is
- // connected() or not, and if it is not, treat it as "worse" than a connected
- // one, even though it's writable. In the code below, we're doing so to make
- // sure we treat a new writable connection as better than an old disconnected
- // connection.
-
- // In the case where we reconnect TCP connections, the original best
- // connection is disconnected without changing to WRITE_TIMEOUT. In this case,
- // the new connection, when it becomes writable, should have higher priority.
- if (a->write_state() == cricket::Connection::STATE_WRITABLE &&
- b->write_state() == cricket::Connection::STATE_WRITABLE) {
- if (a->connected() && !b->connected()) {
- return 1;
- }
- if (!a->connected() && b->connected()) {
- return -1;
- }
- }
- return 0;
-}
-
-int CompareConnections(cricket::Connection* a, cricket::Connection* b) {
- int state_cmp = CompareConnectionStates(a, b);
- if (state_cmp != 0) {
- return state_cmp;
- }
- // Compare the candidate information.
- return CompareConnectionCandidates(a, b);
-}
-
-// Wraps the comparison connection into a less than operator that puts higher
-// priority writable connections first.
-class ConnectionCompare {
- public:
- bool operator()(const cricket::Connection *ca,
- const cricket::Connection *cb) {
- cricket::Connection* a = const_cast<cricket::Connection*>(ca);
- cricket::Connection* b = const_cast<cricket::Connection*>(cb);
-
- // Compare first on writability and static preferences.
- int cmp = CompareConnections(a, b);
- if (cmp > 0)
- return true;
- if (cmp < 0)
- return false;
-
- // Otherwise, sort based on latency estimate.
- return a->rtt() < b->rtt();
-
- // Should we bother checking for the last connection that last received
- // data? It would help rendezvous on the connection that is also receiving
- // packets.
- //
- // TODO: Yes we should definitely do this. The TCP protocol gains
- // efficiency by being used bidirectionally, as opposed to two separate
- // unidirectional streams. This test should probably occur before
- // comparison of local prefs (assuming combined prefs are the same). We
- // need to be careful though, not to bounce back and forth with both sides
- // trying to rendevous with the other.
- }
-};
-
-// Determines whether we should switch between two connections, based first on
-// connection states, static preferences, and then (if those are equal) on
-// latency estimates.
-bool ShouldSwitch(cricket::Connection* a_conn,
- cricket::Connection* b_conn,
- cricket::IceRole ice_role) {
- if (a_conn == b_conn)
- return false;
-
- if (!a_conn || !b_conn) // don't think the latter should happen
- return true;
-
- // We prefer to switch to a writable and receiving connection over a
- // non-writable or non-receiving connection, even if the latter has
- // been nominated by the controlling side.
- int state_cmp = CompareConnectionStates(a_conn, b_conn);
- if (state_cmp != 0) {
- return state_cmp < 0;
- }
- if (ice_role == cricket::ICEROLE_CONTROLLED && a_conn->nominated()) {
- LOG(LS_VERBOSE) << "Controlled side did not switch due to nominated status";
- return false;
- }
-
- int prefs_cmp = CompareConnectionCandidates(a_conn, b_conn);
- if (prefs_cmp != 0) {
- return prefs_cmp < 0;
- }
-
- return b_conn->rtt() <= a_conn->rtt() + kMinImprovement;
-}
-
} // unnamed namespace
namespace cricket {
@@ -251,7 +102,8 @@
0 /* backup_connection_ping_interval */,
false /* gather_continually */,
false /* prioritize_most_likely_candidate_pairs */,
- STABLE_WRITABLE_CONNECTION_PING_INTERVAL) {
+ STABLE_WRITABLE_CONNECTION_PING_INTERVAL,
+ true /* presume_writable_when_fully_relayed */) {
uint32_t weak_ping_interval = ::strtoul(
webrtc::field_trial::FindFullName("WebRTC-StunInterPacketDelay").c_str(),
nullptr, 10);
@@ -446,6 +298,19 @@
LOG(LS_INFO) << "Set stable_writable_connection_ping_interval to "
<< config_.stable_writable_connection_ping_interval;
}
+
+ if (config.presume_writable_when_fully_relayed !=
+ config_.presume_writable_when_fully_relayed) {
+ if (!connections_.empty()) {
+ LOG(LS_ERROR) << "Trying to change 'presume writable' "
+ << "while connections already exist!";
+ } else {
+ config_.presume_writable_when_fully_relayed =
+ config.presume_writable_when_fully_relayed;
+ LOG(LS_INFO) << "Set presume writable when fully relayed to "
+ << config_.presume_writable_when_fully_relayed;
+ }
+ }
}
const IceConfig& P2PTransportChannel::config() const {
@@ -1049,6 +914,176 @@
}
}
+// Compare two connections based on their writing, receiving, and connected
+// states.
+int P2PTransportChannel::CompareConnectionStates(const Connection* a,
+ const Connection* b) const {
+ static constexpr int a_is_better = 1;
+ static constexpr int b_is_better = -1;
+
+ // First, prefer a connection that's writable or presumed writable over
+ // one that's not writable.
+ bool a_writable = a->writable() || PresumedWritable(a);
+ bool b_writable = b->writable() || PresumedWritable(b);
+ if (a_writable && !b_writable) {
+ return a_is_better;
+ }
+ if (!a_writable && b_writable) {
+ return b_is_better;
+ }
+
+ // Sort based on write-state. Better states have lower values.
+ if (a->write_state() < b->write_state()) {
+ return a_is_better;
+ }
+ if (b->write_state() < a->write_state()) {
+ return b_is_better;
+ }
+
+ // We prefer a receiving connection to a non-receiving, higher-priority
+ // connection when sorting connections and choosing which connection to
+ // switch to.
+ if (a->receiving() && !b->receiving()) {
+ return a_is_better;
+ }
+ if (!a->receiving() && b->receiving()) {
+ return b_is_better;
+ }
+
+ // WARNING: Some complexity here about TCP reconnecting.
+ // When a TCP connection fails because of a TCP socket disconnecting, the
+ // active side of the connection will attempt to reconnect for 5 seconds while
+ // pretending to be writable (the connection is not set to the unwritable
+ // state). On the passive side, the connection also remains writable even
+ // though it is disconnected, and a new connection is created when the active
+ // side connects. At that point, there are two TCP connections on the passive
+ // side: 1. the old, disconnected one that is pretending to be writable, and
+ // 2. the new, connected one that is maybe not yet writable. For purposes of
+ // pruning, pinging, and selecting the best connection, we want to treat the
+ // new connection as "better" than the old one. We could add a method called
+ // something like Connection::ImReallyBadEvenThoughImWritable, but that is
+ // equivalent to the existing Connection::connected(), which we already have.
+ // So, in code throughout this file, we'll check whether the connection is
+ // connected() or not, and if it is not, treat it as "worse" than a connected
+ // one, even though it's writable. In the code below, we're doing so to make
+ // sure we treat a new writable connection as better than an old disconnected
+ // connection.
+
+ // In the case where we reconnect TCP connections, the original best
+ // connection is disconnected without changing to WRITE_TIMEOUT. In this case,
+ // the new connection, when it becomes writable, should have higher priority.
+ if (a->write_state() == Connection::STATE_WRITABLE &&
+ b->write_state() == Connection::STATE_WRITABLE) {
+ if (a->connected() && !b->connected()) {
+ return a_is_better;
+ }
+ if (!a->connected() && b->connected()) {
+ return b_is_better;
+ }
+ }
+ return 0;
+}
+
+// Compares two connections based only on the candidate and network information.
+// Returns positive if |a| is better than |b|.
+int P2PTransportChannel::CompareConnectionCandidates(
+ const Connection* a,
+ const Connection* b) const {
+ // Prefer lower network cost.
+ uint32_t a_cost = a->ComputeNetworkCost();
+ uint32_t b_cost = b->ComputeNetworkCost();
+ // Smaller cost is better.
+ if (a_cost < b_cost) {
+ return 1;
+ }
+ if (a_cost > b_cost) {
+ return -1;
+ }
+
+ // Compare connection priority. Lower values get sorted last.
+ if (a->priority() > b->priority()) {
+ return 1;
+ }
+ if (a->priority() < b->priority()) {
+ return -1;
+ }
+
+ // If we're still tied at this point, prefer a younger generation.
+ // (Younger generation means a larger generation number).
+ return (a->remote_candidate().generation() + a->port()->generation()) -
+ (b->remote_candidate().generation() + b->port()->generation());
+}
+
+int P2PTransportChannel::CompareConnections(const Connection* a,
+ const Connection* b) const {
+ // Compare first on writability and static preferences.
+ int state_cmp = CompareConnectionStates(a, b);
+ if (state_cmp != 0) {
+ return state_cmp;
+ }
+ // Then compare the candidate information.
+ int candidates_cmp = CompareConnectionCandidates(a, b);
+ if (candidates_cmp != 0) {
+ return candidates_cmp;
+ }
+ // Otherwise, compare based on latency estimate.
+ return b->rtt() - a->rtt();
+
+ // Should we bother checking for the last connection that last received
+ // data? It would help rendezvous on the connection that is also receiving
+ // packets.
+ //
+ // TODO(deadbeef): Yes we should definitely do this. The TCP protocol gains
+ // efficiency by being used bidirectionally, as opposed to two separate
+ // unidirectional streams. This test should probably occur before
+ // comparison of local prefs (assuming combined prefs are the same). We
+ // need to be careful though, not to bounce back and forth with both sides
+ // trying to rendevous with the other.
+}
+
+bool P2PTransportChannel::PresumedWritable(
+ const cricket::Connection* conn) const {
+ return (conn->write_state() == Connection::STATE_WRITE_INIT &&
+ config_.presume_writable_when_fully_relayed &&
+ conn->local_candidate().type() == RELAY_PORT_TYPE &&
+ (conn->remote_candidate().type() == RELAY_PORT_TYPE ||
+ conn->remote_candidate().type() == PRFLX_PORT_TYPE));
+}
+
+// Determines whether we should switch between two connections, based first on
+// connection states, static preferences, and then (if those are equal) on
+// latency estimates.
+bool P2PTransportChannel::ShouldSwitchSelectedConnection(
+ const Connection* selected,
+ const Connection* conn) const {
+ if (selected == conn) {
+ return false;
+ }
+
+ if (!selected || !conn) { // don't think the latter should happen
+ return true;
+ }
+
+ // We prefer to switch to a writable and receiving connection over a
+ // non-writable or non-receiving connection, even if the latter has
+ // been nominated by the controlling side.
+ int state_cmp = CompareConnectionStates(selected, conn);
+ if (state_cmp != 0) {
+ return state_cmp < 0;
+ }
+ if (ice_role_ == ICEROLE_CONTROLLED && selected->nominated()) {
+ LOG(LS_VERBOSE) << "Controlled side did not switch due to nominated status";
+ return false;
+ }
+
+ int prefs_cmp = CompareConnectionCandidates(selected, conn);
+ if (prefs_cmp != 0) {
+ return prefs_cmp < 0;
+ }
+
+ return selected->rtt() - conn->rtt() >= kMinImprovement;
+}
+
// Sort the available connections to find the best one. We also monitor
// the number of available connections and the current state.
void P2PTransportChannel::SortConnections() {
@@ -1065,8 +1100,10 @@
// that amongst equal preference, writable connections, this will choose the
// one whose estimated latency is lowest. So it is the only one that we
// need to consider switching to.
- ConnectionCompare cmp;
- std::stable_sort(connections_.begin(), connections_.end(), cmp);
+ std::stable_sort(connections_.begin(), connections_.end(),
+ [this](const Connection* a, const Connection* b) {
+ return CompareConnections(a, b) > 0;
+ });
LOG(LS_VERBOSE) << "Sorting " << connections_.size()
<< " available connections:";
for (size_t i = 0; i < connections_.size(); ++i) {
@@ -1079,7 +1116,7 @@
// If necessary, switch to the new choice.
// Note that |top_connection| doesn't have to be writable to become the best
// connection although it will have higher priority if it is writable.
- if (ShouldSwitch(best_connection_, top_connection, ice_role_)) {
+ if (ShouldSwitchSelectedConnection(best_connection_, top_connection)) {
LOG(LS_INFO) << "Switching best connection: " << top_connection->ToString();
SwitchBestConnectionTo(top_connection);
}
@@ -1168,7 +1205,7 @@
// channel so that it knows whether the media channel is allowed to
// send; then it will only signal ready-to-send if the media channel
// has been disallowed to send.
- if (best_connection_->writable()) {
+ if (best_connection_->writable() || PresumedWritable(best_connection_)) {
SignalReadyToSend(this);
}
} else {
@@ -1223,8 +1260,11 @@
SignalStateChanged(this);
}
- bool writable = best_connection_ && best_connection_->writable();
- set_writable(writable);
+ // If our best connection is "presumed writable" (TURN-TURN with no
+ // CreatePermission required), act like we're already writable to the upper
+ // layers, so they can start media quicker.
+ set_writable(best_connection_ && (best_connection_->writable() ||
+ PresumedWritable(best_connection_)));
bool receiving = false;
for (const Connection* connection : connections_) {
diff --git a/p2p/base/p2ptransportchannel.h b/p2p/base/p2ptransportchannel.h
index 3f0191e..d28f60b 100644
--- a/p2p/base/p2ptransportchannel.h
+++ b/p2p/base/p2ptransportchannel.h
@@ -104,6 +104,7 @@
// only update the parameter if it is considered set in |config|. For example,
// a negative value of receiving_timeout will be considered "not set" and we
// will not use it to update the respective parameter in |config_|.
+ // TODO(deadbeef): Use rtc::Optional instead of negative values.
void SetIceConfig(const IceConfig& config) override;
const IceConfig& config() const;
@@ -209,6 +210,20 @@
bool weak() const;
void UpdateConnectionStates();
void RequestSort();
+
+ // The methods below return a positive value if a is preferable to b,
+ // a negative value if b is preferable, and 0 if they're equally preferable.
+ int CompareConnectionStates(const cricket::Connection* a,
+ const cricket::Connection* b) const;
+ int CompareConnectionCandidates(const cricket::Connection* a,
+ const cricket::Connection* b) const;
+ // Compares first on states, then on candidates, then on RTT.
+ int CompareConnections(const cricket::Connection* a,
+ const cricket::Connection* b) const;
+ bool PresumedWritable(const cricket::Connection* conn) const;
+
+ bool ShouldSwitchSelectedConnection(const cricket::Connection* selected,
+ const cricket::Connection* conn) const;
void SortConnections();
void SwitchBestConnectionTo(Connection* conn);
void UpdateState();
diff --git a/p2p/base/p2ptransportchannel_unittest.cc b/p2p/base/p2ptransportchannel_unittest.cc
index 87be379..7bd52b3 100644
--- a/p2p/base/p2ptransportchannel_unittest.cc
+++ b/p2p/base/p2ptransportchannel_unittest.cc
@@ -33,15 +33,14 @@
#include "webrtc/base/thread.h"
#include "webrtc/base/virtualsocketserver.h"
-using cricket::kDefaultPortAllocatorFlags;
-using cricket::kMinimumStepDelay;
-using cricket::kDefaultStepDelay;
-using cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET;
-using cricket::ServerAddresses;
-using cricket::MIN_PINGS_AT_WEAK_PING_INTERVAL;
+namespace {
+
using rtc::SocketAddress;
-static const int kDefaultTimeout = 1000;
+// Default timeout for tests in this file.
+// Should be large enough for slow buildbots to run the tests reliably.
+static const int kDefaultTimeout = 10000;
+
static const int kOnlyLocalPorts = cricket::PORTALLOCATOR_DISABLE_STUN |
cricket::PORTALLOCATOR_DISABLE_RELAY |
cricket::PORTALLOCATOR_DISABLE_TCP;
@@ -106,9 +105,9 @@
enum { MSG_ADD_CANDIDATES, MSG_REMOVE_CANDIDATES };
-static cricket::IceConfig CreateIceConfig(int receiving_timeout,
- bool gather_continually,
- int backup_ping_interval = -1) {
+cricket::IceConfig CreateIceConfig(int receiving_timeout,
+ bool gather_continually,
+ int backup_ping_interval = -1) {
cricket::IceConfig config;
config.receiving_timeout = receiving_timeout;
config.gather_continually = gather_continually;
@@ -116,6 +115,25 @@
return config;
}
+cricket::Candidate CreateUdpCandidate(const std::string& type,
+ const std::string& ip,
+ int port,
+ int priority,
+ const std::string& ufrag = "") {
+ cricket::Candidate c;
+ c.set_address(rtc::SocketAddress(ip, port));
+ c.set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT);
+ c.set_protocol(cricket::UDP_PROTOCOL_NAME);
+ c.set_priority(priority);
+ c.set_username(ufrag);
+ c.set_type(type);
+ return c;
+}
+
+} // namespace {
+
+namespace cricket {
+
// This test simulates 2 P2P endpoints that want to establish connectivity
// with each other over various network topologies and conditions, which can be
// specified in each individial test.
@@ -142,27 +160,35 @@
nss_(new rtc::NATSocketServer(vss_.get())),
ss_(new rtc::FirewallSocketServer(nss_.get())),
ss_scope_(ss_.get()),
- stun_server_(cricket::TestStunServer::Create(main_, kStunAddr)),
+ stun_server_(TestStunServer::Create(main_, kStunAddr)),
turn_server_(main_, kTurnUdpIntAddr, kTurnUdpExtAddr),
- relay_server_(main_, kRelayUdpIntAddr, kRelayUdpExtAddr,
- kRelayTcpIntAddr, kRelayTcpExtAddr,
- kRelaySslTcpIntAddr, kRelaySslTcpExtAddr),
- socks_server1_(ss_.get(), kSocksProxyAddrs[0],
- ss_.get(), kSocksProxyAddrs[0]),
- socks_server2_(ss_.get(), kSocksProxyAddrs[1],
- ss_.get(), kSocksProxyAddrs[1]),
+ relay_server_(main_,
+ kRelayUdpIntAddr,
+ kRelayUdpExtAddr,
+ kRelayTcpIntAddr,
+ kRelayTcpExtAddr,
+ kRelaySslTcpIntAddr,
+ kRelaySslTcpExtAddr),
+ socks_server1_(ss_.get(),
+ kSocksProxyAddrs[0],
+ ss_.get(),
+ kSocksProxyAddrs[0]),
+ socks_server2_(ss_.get(),
+ kSocksProxyAddrs[1],
+ ss_.get(),
+ kSocksProxyAddrs[1]),
force_relay_(false) {
- ep1_.role_ = cricket::ICEROLE_CONTROLLING;
- ep2_.role_ = cricket::ICEROLE_CONTROLLED;
+ ep1_.role_ = ICEROLE_CONTROLLING;
+ ep2_.role_ = ICEROLE_CONTROLLED;
ServerAddresses stun_servers;
stun_servers.insert(kStunAddr);
- ep1_.allocator_.reset(new cricket::BasicPortAllocator(
- &ep1_.network_manager_,
- stun_servers, kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr));
- ep2_.allocator_.reset(new cricket::BasicPortAllocator(
- &ep2_.network_manager_,
- stun_servers, kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr));
+ ep1_.allocator_.reset(new BasicPortAllocator(
+ &ep1_.network_manager_, stun_servers, kRelayUdpIntAddr,
+ kRelayTcpIntAddr, kRelaySslTcpIntAddr));
+ ep2_.allocator_.reset(new BasicPortAllocator(
+ &ep2_.network_manager_, stun_servers, kRelayUdpIntAddr,
+ kRelayTcpIntAddr, kRelaySslTcpIntAddr));
}
protected:
@@ -216,29 +242,28 @@
std::string name_; // TODO - Currently not used.
std::list<std::string> ch_packets_;
- std::unique_ptr<cricket::P2PTransportChannel> ch_;
+ std::unique_ptr<P2PTransportChannel> ch_;
};
struct CandidatesData : public rtc::MessageData {
- CandidatesData(cricket::TransportChannel* ch, const cricket::Candidate& c)
+ CandidatesData(TransportChannel* ch, const Candidate& c)
: channel(ch), candidates(1, c) {}
- CandidatesData(cricket::TransportChannel* ch,
- const std::vector<cricket::Candidate>& cc)
+ CandidatesData(TransportChannel* ch, const std::vector<Candidate>& cc)
: channel(ch), candidates(cc) {}
- cricket::TransportChannel* channel;
- cricket::Candidates candidates;
+ TransportChannel* channel;
+ Candidates candidates;
};
struct Endpoint {
Endpoint()
- : role_(cricket::ICEROLE_UNKNOWN),
+ : role_(ICEROLE_UNKNOWN),
tiebreaker_(0),
role_conflict_(false),
save_candidates_(false) {}
- bool HasChannel(cricket::TransportChannel* ch) {
+ bool HasChannel(TransportChannel* ch) {
return (ch == cd1_.ch_.get() || ch == cd2_.ch_.get());
}
- ChannelData* GetChannelData(cricket::TransportChannel* ch) {
+ ChannelData* GetChannelData(TransportChannel* ch) {
if (!HasChannel(ch)) return NULL;
if (cd1_.ch_.get() == ch)
return &cd1_;
@@ -246,8 +271,8 @@
return &cd2_;
}
- void SetIceRole(cricket::IceRole role) { role_ = role; }
- cricket::IceRole ice_role() { return role_; }
+ void SetIceRole(IceRole role) { role_ = role; }
+ IceRole ice_role() { return role_; }
void SetIceTiebreaker(uint64_t tiebreaker) { tiebreaker_ = tiebreaker; }
uint64_t GetIceTiebreaker() { return tiebreaker_; }
void OnRoleConflict(bool role_conflict) { role_conflict_ = role_conflict; }
@@ -260,17 +285,18 @@
}
rtc::FakeNetworkManager network_manager_;
- std::unique_ptr<cricket::BasicPortAllocator> allocator_;
+ std::unique_ptr<BasicPortAllocator> allocator_;
ChannelData cd1_;
ChannelData cd2_;
- cricket::IceRole role_;
+ IceRole role_;
uint64_t tiebreaker_;
bool role_conflict_;
bool save_candidates_;
std::vector<CandidatesData*> saved_candidates_;
+ bool ready_to_send_ = false;
};
- ChannelData* GetChannelData(cricket::TransportChannel* channel) {
+ ChannelData* GetChannelData(TransportChannel* channel) {
if (ep1_.HasChannel(channel))
return ep1_.GetChannelData(channel);
else
@@ -283,13 +309,11 @@
std::string ice_ufrag_ep2_cd1_ch = kIceUfrag[1];
std::string ice_pwd_ep2_cd1_ch = kIcePwd[1];
ep1_.cd1_.ch_.reset(CreateChannel(
- 0, cricket::ICE_CANDIDATE_COMPONENT_DEFAULT,
- ice_ufrag_ep1_cd1_ch, ice_pwd_ep1_cd1_ch,
- ice_ufrag_ep2_cd1_ch, ice_pwd_ep2_cd1_ch));
+ 0, ICE_CANDIDATE_COMPONENT_DEFAULT, ice_ufrag_ep1_cd1_ch,
+ ice_pwd_ep1_cd1_ch, ice_ufrag_ep2_cd1_ch, ice_pwd_ep2_cd1_ch));
ep2_.cd1_.ch_.reset(CreateChannel(
- 1, cricket::ICE_CANDIDATE_COMPONENT_DEFAULT,
- ice_ufrag_ep2_cd1_ch, ice_pwd_ep2_cd1_ch,
- ice_ufrag_ep1_cd1_ch, ice_pwd_ep1_cd1_ch));
+ 1, ICE_CANDIDATE_COMPONENT_DEFAULT, ice_ufrag_ep2_cd1_ch,
+ ice_pwd_ep2_cd1_ch, ice_ufrag_ep1_cd1_ch, ice_pwd_ep1_cd1_ch));
ep1_.cd1_.ch_->MaybeStartGathering();
ep2_.cd1_.ch_->MaybeStartGathering();
if (num == 2) {
@@ -298,26 +322,25 @@
std::string ice_ufrag_ep2_cd2_ch = kIceUfrag[3];
std::string ice_pwd_ep2_cd2_ch = kIcePwd[3];
ep1_.cd2_.ch_.reset(CreateChannel(
- 0, cricket::ICE_CANDIDATE_COMPONENT_DEFAULT,
- ice_ufrag_ep1_cd2_ch, ice_pwd_ep1_cd2_ch,
- ice_ufrag_ep2_cd2_ch, ice_pwd_ep2_cd2_ch));
+ 0, ICE_CANDIDATE_COMPONENT_DEFAULT, ice_ufrag_ep1_cd2_ch,
+ ice_pwd_ep1_cd2_ch, ice_ufrag_ep2_cd2_ch, ice_pwd_ep2_cd2_ch));
ep2_.cd2_.ch_.reset(CreateChannel(
- 1, cricket::ICE_CANDIDATE_COMPONENT_DEFAULT,
- ice_ufrag_ep2_cd2_ch, ice_pwd_ep2_cd2_ch,
- ice_ufrag_ep1_cd2_ch, ice_pwd_ep1_cd2_ch));
+ 1, ICE_CANDIDATE_COMPONENT_DEFAULT, ice_ufrag_ep2_cd2_ch,
+ ice_pwd_ep2_cd2_ch, ice_ufrag_ep1_cd2_ch, ice_pwd_ep1_cd2_ch));
ep1_.cd2_.ch_->MaybeStartGathering();
ep2_.cd2_.ch_->MaybeStartGathering();
}
}
- cricket::P2PTransportChannel* CreateChannel(
- int endpoint,
- int component,
- const std::string& local_ice_ufrag,
- const std::string& local_ice_pwd,
- const std::string& remote_ice_ufrag,
- const std::string& remote_ice_pwd) {
- cricket::P2PTransportChannel* channel = new cricket::P2PTransportChannel(
+ P2PTransportChannel* CreateChannel(int endpoint,
+ int component,
+ const std::string& local_ice_ufrag,
+ const std::string& local_ice_pwd,
+ const std::string& remote_ice_ufrag,
+ const std::string& remote_ice_pwd) {
+ P2PTransportChannel* channel = new P2PTransportChannel(
"test content name", component, GetAllocator(endpoint));
+ channel->SignalReadyToSend.connect(
+ this, &P2PTransportChannelTestBase::OnReadyToSend);
channel->SignalCandidateGathered.connect(
this, &P2PTransportChannelTestBase::OnCandidateGathered);
channel->SignalCandidatesRemoved.connect(
@@ -341,10 +364,10 @@
ep1_.cd2_.ch_.reset();
ep2_.cd2_.ch_.reset();
}
- cricket::P2PTransportChannel* ep1_ch1() { return ep1_.cd1_.ch_.get(); }
- cricket::P2PTransportChannel* ep1_ch2() { return ep1_.cd2_.ch_.get(); }
- cricket::P2PTransportChannel* ep2_ch1() { return ep2_.cd1_.ch_.get(); }
- cricket::P2PTransportChannel* ep2_ch2() { return ep2_.cd2_.ch_.get(); }
+ P2PTransportChannel* ep1_ch1() { return ep1_.cd1_.ch_.get(); }
+ P2PTransportChannel* ep1_ch2() { return ep1_.cd2_.ch_.get(); }
+ P2PTransportChannel* ep2_ch1() { return ep2_.cd1_.ch_.get(); }
+ P2PTransportChannel* ep2_ch2() { return ep2_.cd2_.ch_.get(); }
// Common results.
static const Result kLocalUdpToLocalUdp;
@@ -372,7 +395,7 @@
return NULL;
}
}
- cricket::PortAllocator* GetAllocator(int endpoint) {
+ PortAllocator* GetAllocator(int endpoint) {
return GetEndpoint(endpoint)->allocator_.get();
}
void AddAddress(int endpoint, const SocketAddress& addr) {
@@ -398,7 +421,7 @@
void SetAllocatorFlags(int endpoint, int flags) {
GetAllocator(endpoint)->set_flags(flags);
}
- void SetIceRole(int endpoint, cricket::IceRole role) {
+ void SetIceRole(int endpoint, IceRole role) {
GetEndpoint(endpoint)->SetIceRole(role);
}
void SetIceTiebreaker(int endpoint, uint64_t tiebreaker) {
@@ -590,12 +613,10 @@
ep2_ch1()->receiving() && ep2_ch1()->writable(),
1000, 1000);
- const cricket::Candidate* old_local_candidate1 = LocalCandidate(ep1_ch1());
- const cricket::Candidate* old_local_candidate2 = LocalCandidate(ep2_ch1());
- const cricket::Candidate* old_remote_candidate1 =
- RemoteCandidate(ep1_ch1());
- const cricket::Candidate* old_remote_candidate2 =
- RemoteCandidate(ep2_ch1());
+ const Candidate* old_local_candidate1 = LocalCandidate(ep1_ch1());
+ const Candidate* old_local_candidate2 = LocalCandidate(ep2_ch1());
+ const Candidate* old_remote_candidate1 = RemoteCandidate(ep1_ch1());
+ const Candidate* old_remote_candidate2 = RemoteCandidate(ep2_ch1());
ep1_ch1()->SetIceCredentials(kIceUfrag[2], kIcePwd[2]);
ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]);
@@ -623,7 +644,7 @@
void TestSignalRoleConflict() {
SetIceTiebreaker(0, kTiebreaker1); // Default EP1 is in controlling state.
- SetIceRole(1, cricket::ICEROLE_CONTROLLING);
+ SetIceRole(1, ICEROLE_CONTROLLING);
SetIceTiebreaker(1, kTiebreaker2);
// Creating channels with both channels role set to CONTROLLING.
@@ -645,10 +666,13 @@
TestSendRecv(1);
}
+ void OnReadyToSend(TransportChannel* ch) {
+ GetEndpoint(ch)->ready_to_send_ = true;
+ }
+
// We pass the candidates directly to the other side.
- void OnCandidateGathered(cricket::TransportChannelImpl* ch,
- const cricket::Candidate& c) {
- if (force_relay_ && c.type() != cricket::RELAY_PORT_TYPE)
+ void OnCandidateGathered(TransportChannelImpl* ch, const Candidate& c) {
+ if (force_relay_ && c.type() != RELAY_PORT_TYPE)
return;
if (GetEndpoint(ch)->save_candidates_) {
@@ -663,8 +687,8 @@
GetEndpoint(endpoint)->save_candidates_ = true;
}
- void OnCandidatesRemoved(cricket::TransportChannelImpl* ch,
- const std::vector<cricket::Candidate>& candidates) {
+ void OnCandidatesRemoved(TransportChannelImpl* ch,
+ const std::vector<Candidate>& candidates) {
// Candidate removals are not paused.
CandidatesData* candidates_data = new CandidatesData(ch, candidates);
main_->Post(RTC_FROM_HERE, this, MSG_REMOVE_CANDIDATES, candidates_data);
@@ -674,12 +698,12 @@
void VerifySavedTcpCandidates(int endpoint, const std::string& tcptype) {
for (auto& data : GetEndpoint(endpoint)->saved_candidates_) {
for (auto& candidate : data->candidates) {
- EXPECT_EQ(candidate.protocol(), cricket::TCP_PROTOCOL_NAME);
+ EXPECT_EQ(candidate.protocol(), TCP_PROTOCOL_NAME);
EXPECT_EQ(candidate.tcptype(), tcptype);
- if (candidate.tcptype() == cricket::TCPTYPE_ACTIVE_STR) {
- EXPECT_EQ(candidate.address().port(), cricket::DISCARD_PORT);
- } else if (candidate.tcptype() == cricket::TCPTYPE_PASSIVE_STR) {
- EXPECT_NE(candidate.address().port(), cricket::DISCARD_PORT);
+ if (candidate.tcptype() == TCPTYPE_ACTIVE_STR) {
+ EXPECT_EQ(candidate.address().port(), DISCARD_PORT);
+ } else if (candidate.tcptype() == TCPTYPE_PASSIVE_STR) {
+ EXPECT_NE(candidate.address().port(), DISCARD_PORT);
} else {
FAIL() << "Unknown tcptype: " << candidate.tcptype();
}
@@ -702,7 +726,10 @@
case MSG_ADD_CANDIDATES: {
std::unique_ptr<CandidatesData> data(
static_cast<CandidatesData*>(msg->pdata));
- cricket::P2PTransportChannel* rch = GetRemoteChannel(data->channel);
+ P2PTransportChannel* rch = GetRemoteChannel(data->channel);
+ if (!rch) {
+ return;
+ }
for (auto& c : data->candidates) {
if (remote_ice_credential_source_ != FROM_CANDIDATE) {
c.set_username("");
@@ -717,8 +744,11 @@
case MSG_REMOVE_CANDIDATES: {
std::unique_ptr<CandidatesData> data(
static_cast<CandidatesData*>(msg->pdata));
- cricket::P2PTransportChannel* rch = GetRemoteChannel(data->channel);
- for (cricket::Candidate& c : data->candidates) {
+ P2PTransportChannel* rch = GetRemoteChannel(data->channel);
+ if (!rch) {
+ return;
+ }
+ for (Candidate& c : data->candidates) {
LOG(LS_INFO) << "Removed remote candidate " << c.ToString();
rch->RemoveRemoteCandidate(c);
}
@@ -726,40 +756,40 @@
}
}
}
- void OnReadPacket(cricket::TransportChannel* channel, const char* data,
- size_t len, const rtc::PacketTime& packet_time,
+ void OnReadPacket(TransportChannel* channel,
+ const char* data,
+ size_t len,
+ const rtc::PacketTime& packet_time,
int flags) {
std::list<std::string>& packets = GetPacketList(channel);
packets.push_front(std::string(data, len));
}
- void OnRoleConflict(cricket::TransportChannelImpl* channel) {
+ void OnRoleConflict(TransportChannelImpl* channel) {
GetEndpoint(channel)->OnRoleConflict(true);
- cricket::IceRole new_role =
- GetEndpoint(channel)->ice_role() == cricket::ICEROLE_CONTROLLING ?
- cricket::ICEROLE_CONTROLLED : cricket::ICEROLE_CONTROLLING;
+ IceRole new_role = GetEndpoint(channel)->ice_role() == ICEROLE_CONTROLLING
+ ? ICEROLE_CONTROLLED
+ : ICEROLE_CONTROLLING;
channel->SetIceRole(new_role);
}
- int SendData(cricket::TransportChannel* channel,
- const char* data, size_t len) {
+ int SendData(TransportChannel* channel, const char* data, size_t len) {
rtc::PacketOptions options;
return channel->SendPacket(data, len, options, 0);
}
- bool CheckDataOnChannel(cricket::TransportChannel* channel,
- const char* data, int len) {
+ bool CheckDataOnChannel(TransportChannel* channel,
+ const char* data,
+ int len) {
return GetChannelData(channel)->CheckData(data, len);
}
- static const cricket::Candidate* LocalCandidate(
- cricket::P2PTransportChannel* ch) {
+ static const Candidate* LocalCandidate(P2PTransportChannel* ch) {
return (ch && ch->best_connection()) ?
&ch->best_connection()->local_candidate() : NULL;
}
- static const cricket::Candidate* RemoteCandidate(
- cricket::P2PTransportChannel* ch) {
+ static const Candidate* RemoteCandidate(P2PTransportChannel* ch) {
return (ch && ch->best_connection()) ?
&ch->best_connection()->remote_candidate() : NULL;
}
- Endpoint* GetEndpoint(cricket::TransportChannel* ch) {
+ Endpoint* GetEndpoint(TransportChannel* ch) {
if (ep1_.HasChannel(ch)) {
return &ep1_;
} else if (ep2_.HasChannel(ch)) {
@@ -768,8 +798,7 @@
return NULL;
}
}
- cricket::P2PTransportChannel* GetRemoteChannel(
- cricket::TransportChannel* ch) {
+ P2PTransportChannel* GetRemoteChannel(TransportChannel* ch) {
if (ch == ep1_ch1())
return ep2_ch1();
else if (ch == ep1_ch2())
@@ -781,7 +810,7 @@
else
return NULL;
}
- std::list<std::string>& GetPacketList(cricket::TransportChannel* ch) {
+ std::list<std::string>& GetPacketList(TransportChannel* ch) {
return GetChannelData(ch)->ch_packets_;
}
@@ -805,9 +834,9 @@
std::unique_ptr<rtc::NATSocketServer> nss_;
std::unique_ptr<rtc::FirewallSocketServer> ss_;
rtc::SocketServerScope ss_scope_;
- std::unique_ptr<cricket::TestStunServer> stun_server_;
- cricket::TestTurnServer turn_server_;
- cricket::TestRelayServer relay_server_;
+ std::unique_ptr<TestStunServer> stun_server_;
+ TestTurnServer turn_server_;
+ TestRelayServer relay_server_;
rtc::SocksProxyServer socks_server1_;
rtc::SocksProxyServer socks_server2_;
Endpoint ep1_;
@@ -865,21 +894,17 @@
int allocator_flags2) {
ServerAddresses stun_servers;
stun_servers.insert(kStunAddr);
- GetEndpoint(0)->allocator_.reset(
- new cricket::BasicPortAllocator(&(GetEndpoint(0)->network_manager_),
- stun_servers,
- rtc::SocketAddress(), rtc::SocketAddress(),
- rtc::SocketAddress()));
- GetEndpoint(1)->allocator_.reset(
- new cricket::BasicPortAllocator(&(GetEndpoint(1)->network_manager_),
- stun_servers,
- rtc::SocketAddress(), rtc::SocketAddress(),
- rtc::SocketAddress()));
+ GetEndpoint(0)->allocator_.reset(new BasicPortAllocator(
+ &(GetEndpoint(0)->network_manager_), stun_servers, rtc::SocketAddress(),
+ rtc::SocketAddress(), rtc::SocketAddress()));
+ GetEndpoint(1)->allocator_.reset(new BasicPortAllocator(
+ &(GetEndpoint(1)->network_manager_), stun_servers, rtc::SocketAddress(),
+ rtc::SocketAddress(), rtc::SocketAddress()));
- cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
+ RelayServerConfig turn_server(RELAY_TURN);
turn_server.credentials = kRelayCredentials;
turn_server.ports.push_back(
- cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
+ ProtocolAddress(kTurnUdpIntAddr, PROTO_UDP, false));
GetEndpoint(0)->allocator_->AddTurnServer(turn_server);
GetEndpoint(1)->allocator_->AddTurnServer(turn_server);
@@ -1090,11 +1115,11 @@
ep2_ch1()->receiving() && ep2_ch1()->writable(),
1000, 1000);
TestSendRecv(1);
- cricket::ConnectionInfos infos;
+ ConnectionInfos infos;
ASSERT_TRUE(ep1_ch1()->GetStats(&infos));
ASSERT_TRUE(infos.size() >= 1);
- cricket::ConnectionInfo* best_conn_info = nullptr;
- for (cricket::ConnectionInfo& info : infos) {
+ ConnectionInfo* best_conn_info = nullptr;
+ for (ConnectionInfo& info : infos) {
if (info.best_connection) {
best_conn_info = &info;
break;
@@ -1130,7 +1155,7 @@
// The caller should have the best connection connected to the peer reflexive
// candidate.
- const cricket::Connection* best_connection = NULL;
+ const Connection* best_connection = NULL;
WAIT((best_connection = ep1_ch1()->best_connection()) != NULL, 2000);
EXPECT_EQ("prflx", ep1_ch1()->best_connection()->remote_candidate().type());
@@ -1204,7 +1229,7 @@
ResumeCandidates(1);
- const cricket::Connection* best_connection = NULL;
+ const Connection* best_connection = NULL;
WAIT((best_connection = ep2_ch1()->best_connection()) != NULL, 2000);
// Wait to verify the connection is not culled.
@@ -1229,8 +1254,8 @@
kDefaultPortAllocatorFlags);
// Only gather relay candidates, so that when the prflx candidate arrives
// it's prioritized above the current candidate pair.
- GetEndpoint(0)->allocator_->set_candidate_filter(cricket::CF_RELAY);
- GetEndpoint(1)->allocator_->set_candidate_filter(cricket::CF_RELAY);
+ GetEndpoint(0)->allocator_->set_candidate_filter(CF_RELAY);
+ GetEndpoint(1)->allocator_->set_candidate_filter(CF_RELAY);
// Setting this allows us to control when SetRemoteIceCredentials is called.
set_remote_ice_credential_source(FROM_CANDIDATE);
CreateChannels(1);
@@ -1253,8 +1278,7 @@
EXPECT_EQ_WAIT("prflx",
ep1_ch1()->best_connection()->remote_candidate().type(),
kDefaultTimeout);
- const cricket::Connection* prflx_best_connection =
- ep1_ch1()->best_connection();
+ const Connection* prflx_best_connection = ep1_ch1()->best_connection();
// Now simulate the ICE restart on ep1.
ep1_ch1()->SetIceCredentials(kIceUfrag[2], kIcePwd[2]);
@@ -1278,7 +1302,7 @@
ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
kDefaultPortAllocatorFlags);
CreateChannels(1);
- const cricket::Connection* best_connection = NULL;
+ const Connection* best_connection = NULL;
// Wait until the callee's connections are created.
WAIT((best_connection = ep2_ch1()->best_connection()) != NULL, 1000);
// Wait to see if they get culled; they shouldn't.
@@ -1333,9 +1357,9 @@
SetAllocationStepDelay(0, kMinimumStepDelay);
SetAllocationStepDelay(1, kMinimumStepDelay);
- int kOnlyLocalTcpPorts = cricket::PORTALLOCATOR_DISABLE_UDP |
- cricket::PORTALLOCATOR_DISABLE_STUN |
- cricket::PORTALLOCATOR_DISABLE_RELAY;
+ int kOnlyLocalTcpPorts = PORTALLOCATOR_DISABLE_UDP |
+ PORTALLOCATOR_DISABLE_STUN |
+ PORTALLOCATOR_DISABLE_RELAY;
// Disable all protocols except TCP.
SetAllocatorFlags(0, kOnlyLocalTcpPorts);
SetAllocatorFlags(1, kOnlyLocalTcpPorts);
@@ -1354,8 +1378,8 @@
CreateChannels(1);
// Verify tcp candidates.
- VerifySavedTcpCandidates(0, cricket::TCPTYPE_PASSIVE_STR);
- VerifySavedTcpCandidates(1, cricket::TCPTYPE_ACTIVE_STR);
+ VerifySavedTcpCandidates(0, TCPTYPE_PASSIVE_STR);
+ VerifySavedTcpCandidates(1, TCPTYPE_ACTIVE_STR);
// Resume candidates.
ResumeCandidates(0);
@@ -1384,7 +1408,8 @@
// Disable on Windows because it is flaky.
// https://bugs.chromium.org/p/webrtc/issues/detail?id=6019
#if defined(WEBRTC_WIN)
-#define MAYBE_TestIceConfigWillPassDownToPort DISABLED_TestIceConfigWillPassDownToPort
+#define MAYBE_TestIceConfigWillPassDownToPort \
+ DISABLED_TestIceConfigWillPassDownToPort
#else
#define MAYBE_TestIceConfigWillPassDownToPort TestIceConfigWillPassDownToPort
#endif
@@ -1392,27 +1417,27 @@
AddAddress(0, kPublicAddrs[0]);
AddAddress(1, kPublicAddrs[1]);
- SetIceRole(0, cricket::ICEROLE_CONTROLLING);
+ SetIceRole(0, ICEROLE_CONTROLLING);
SetIceTiebreaker(0, kTiebreaker1);
- SetIceRole(1, cricket::ICEROLE_CONTROLLING);
+ SetIceRole(1, ICEROLE_CONTROLLING);
SetIceTiebreaker(1, kTiebreaker2);
CreateChannels(1);
EXPECT_EQ_WAIT(2u, ep1_ch1()->ports().size(), 1000);
- const std::vector<cricket::PortInterface *> ports_before = ep1_ch1()->ports();
+ const std::vector<PortInterface*> ports_before = ep1_ch1()->ports();
for (size_t i = 0; i < ports_before.size(); ++i) {
- EXPECT_EQ(cricket::ICEROLE_CONTROLLING, ports_before[i]->GetIceRole());
+ EXPECT_EQ(ICEROLE_CONTROLLING, ports_before[i]->GetIceRole());
EXPECT_EQ(kTiebreaker1, ports_before[i]->IceTiebreaker());
}
- ep1_ch1()->SetIceRole(cricket::ICEROLE_CONTROLLED);
+ ep1_ch1()->SetIceRole(ICEROLE_CONTROLLED);
ep1_ch1()->SetIceTiebreaker(kTiebreaker2);
- const std::vector<cricket::PortInterface *> ports_after = ep1_ch1()->ports();
+ const std::vector<PortInterface*> ports_after = ep1_ch1()->ports();
for (size_t i = 0; i < ports_after.size(); ++i) {
- EXPECT_EQ(cricket::ICEROLE_CONTROLLED, ports_before[i]->GetIceRole());
+ EXPECT_EQ(ICEROLE_CONTROLLED, ports_before[i]->GetIceRole());
// SetIceTiebreaker after Connect() has been called will fail. So expect the
// original value.
EXPECT_EQ(kTiebreaker1, ports_before[i]->IceTiebreaker());
@@ -1470,8 +1495,8 @@
SetAllocationStepDelay(1, kMinimumStepDelay);
// Enable IPv6
- SetAllocatorFlags(0, cricket::PORTALLOCATOR_ENABLE_IPV6);
- SetAllocatorFlags(1, cricket::PORTALLOCATOR_ENABLE_IPV6);
+ SetAllocatorFlags(0, PORTALLOCATOR_ENABLE_IPV6);
+ SetAllocatorFlags(1, PORTALLOCATOR_ENABLE_IPV6);
CreateChannels(1);
@@ -1491,8 +1516,8 @@
TEST_F(P2PTransportChannelTest, TestForceTurn) {
ConfigureEndpoints(
NAT_PORT_RESTRICTED, NAT_SYMMETRIC,
- kDefaultPortAllocatorFlags | cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET,
- kDefaultPortAllocatorFlags | cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
+ kDefaultPortAllocatorFlags | PORTALLOCATOR_ENABLE_SHARED_SOCKET,
+ kDefaultPortAllocatorFlags | PORTALLOCATOR_ENABLE_SHARED_SOCKET);
set_force_relay(true);
SetAllocationStepDelay(0, kMinimumStepDelay);
@@ -1524,7 +1549,7 @@
SetAllocationStepDelay(0, kDefaultStepDelay);
SetAllocationStepDelay(1, kDefaultStepDelay);
CreateChannels(1);
- cricket::IceConfig config = CreateIceConfig(1000, true);
+ IceConfig config = CreateIceConfig(1000, true);
ep1_ch1()->SetIceConfig(config);
// By default, ep2 does not gather continually.
@@ -1532,13 +1557,12 @@
ep1_ch1()->receiving() && ep1_ch1()->writable() &&
ep2_ch1()->receiving() && ep2_ch1()->writable(),
1000, 1000);
- WAIT(cricket::IceGatheringState::kIceGatheringComplete ==
- ep1_ch1()->gathering_state(),
+ WAIT(IceGatheringState::kIceGatheringComplete == ep1_ch1()->gathering_state(),
1000);
- EXPECT_EQ(cricket::IceGatheringState::kIceGatheringGathering,
+ EXPECT_EQ(IceGatheringState::kIceGatheringGathering,
ep1_ch1()->gathering_state());
// By now, ep2 should have completed gathering.
- EXPECT_EQ(cricket::IceGatheringState::kIceGatheringComplete,
+ EXPECT_EQ(IceGatheringState::kIceGatheringComplete,
ep2_ch1()->gathering_state());
DestroyChannels();
@@ -1557,9 +1581,9 @@
allocator_1->turn_servers(), pool_size);
allocator_2->SetConfiguration(allocator_2->stun_servers(),
allocator_2->turn_servers(), pool_size);
- const cricket::PortAllocatorSession* pooled_session_1 =
+ const PortAllocatorSession* pooled_session_1 =
allocator_1->GetPooledSession();
- const cricket::PortAllocatorSession* pooled_session_2 =
+ const PortAllocatorSession* pooled_session_2 =
allocator_2->GetPooledSession();
ASSERT_NE(nullptr, pooled_session_1);
ASSERT_NE(nullptr, pooled_session_2);
@@ -1600,9 +1624,9 @@
allocator_1->turn_servers(), pool_size);
allocator_2->SetConfiguration(allocator_2->stun_servers(),
allocator_2->turn_servers(), pool_size);
- const cricket::PortAllocatorSession* pooled_session_1 =
+ const PortAllocatorSession* pooled_session_1 =
allocator_1->GetPooledSession();
- const cricket::PortAllocatorSession* pooled_session_2 =
+ const PortAllocatorSession* pooled_session_2 =
allocator_2->GetPooledSession();
ASSERT_NE(nullptr, pooled_session_1);
ASSERT_NE(nullptr, pooled_session_2);
@@ -1630,6 +1654,84 @@
ep2_ch1()->best_connection()->port()));
}
+// Test that when the "presume_writable_when_fully_relayed" flag is set to
+// false and there's a TURN-TURN candidate pair, it's presume to be writable
+// as soon as it's created.
+TEST_F(P2PTransportChannelTest, TurnToTurnPresumedWritable) {
+ ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
+ kDefaultPortAllocatorFlags);
+ // Only configure one channel so we can control when the remote candidate
+ // is added.
+ GetEndpoint(0)->cd1_.ch_.reset(
+ CreateChannel(0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[0],
+ kIcePwd[0], kIceUfrag[1], kIcePwd[1]));
+ IceConfig config;
+ config.presume_writable_when_fully_relayed = true;
+ ep1_ch1()->SetIceConfig(config);
+ ep1_ch1()->MaybeStartGathering();
+ EXPECT_EQ_WAIT(IceGatheringState::kIceGatheringComplete,
+ ep1_ch1()->gathering_state(), kDefaultTimeout);
+ // Add two remote candidates; a host candidate (with higher priority)
+ // and TURN candidate.
+ ep1_ch1()->AddRemoteCandidate(
+ CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
+ ep1_ch1()->AddRemoteCandidate(
+ CreateUdpCandidate(RELAY_PORT_TYPE, "2.2.2.2", 2, 0));
+ // Expect that the TURN-TURN candidate pair will be prioritized since it's
+ // "probably writable".
+ EXPECT_TRUE(ep1_ch1()->best_connection() != nullptr);
+ EXPECT_EQ(RELAY_PORT_TYPE, LocalCandidate(ep1_ch1())->type());
+ EXPECT_EQ(RELAY_PORT_TYPE, RemoteCandidate(ep1_ch1())->type());
+ // Also expect that the channel instantly indicates that it's writable since
+ // it has a TURN-TURN pair.
+ EXPECT_TRUE(ep1_ch1()->writable());
+ EXPECT_TRUE(GetEndpoint(0)->ready_to_send_);
+}
+
+// Test that a presumed-writable TURN<->TURN connection is preferred above an
+// unreliable connection (one that has failed to be pinged for some time).
+TEST_F(P2PTransportChannelTest, PresumedWritablePreferredOverUnreliable) {
+ rtc::ScopedFakeClock fake_clock;
+
+ ConfigureEndpoints(NAT_SYMMETRIC, NAT_SYMMETRIC, kDefaultPortAllocatorFlags,
+ kDefaultPortAllocatorFlags);
+ IceConfig config;
+ config.presume_writable_when_fully_relayed = true;
+ GetEndpoint(0)->cd1_.ch_.reset(
+ CreateChannel(0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[0],
+ kIcePwd[0], kIceUfrag[1], kIcePwd[1]));
+ GetEndpoint(1)->cd1_.ch_.reset(
+ CreateChannel(1, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[1],
+ kIcePwd[1], kIceUfrag[0], kIcePwd[0]));
+ ep1_ch1()->SetIceConfig(config);
+ ep2_ch1()->SetIceConfig(config);
+ ep1_ch1()->MaybeStartGathering();
+ ep2_ch1()->MaybeStartGathering();
+ // Wait for initial connection as usual.
+ EXPECT_TRUE_SIMULATED_WAIT(
+ ep1_ch1()->receiving() && ep1_ch1()->writable() &&
+ ep1_ch1()->best_connection()->writable() && ep2_ch1()->receiving() &&
+ ep2_ch1()->writable() && ep2_ch1()->best_connection()->writable(),
+ 1000, fake_clock);
+ const Connection* old_best_connection = ep1_ch1()->best_connection();
+ // Destroy the second channel and wait for the current connection on the
+ // first channel to become "unreliable", making it no longer writable.
+ GetEndpoint(1)->cd1_.ch_.reset();
+ EXPECT_TRUE_SIMULATED_WAIT(!ep1_ch1()->writable(), 10000, fake_clock);
+ EXPECT_NE(nullptr, ep1_ch1()->best_connection());
+ // Add a remote TURN candidate. The first channel should still have a TURN
+ // port available to make a TURN<->TURN pair that's presumed writable.
+ ep1_ch1()->AddRemoteCandidate(
+ CreateUdpCandidate(RELAY_PORT_TYPE, "2.2.2.2", 2, 0));
+ EXPECT_EQ(RELAY_PORT_TYPE, LocalCandidate(ep1_ch1())->type());
+ EXPECT_EQ(RELAY_PORT_TYPE, RemoteCandidate(ep1_ch1())->type());
+ EXPECT_TRUE(ep1_ch1()->writable());
+ EXPECT_TRUE(GetEndpoint(0)->ready_to_send_);
+ EXPECT_NE(old_best_connection, ep1_ch1()->best_connection());
+ // Explitly destroy channels, before fake clock is destroyed.
+ DestroyChannels();
+}
+
// Test what happens when we have 2 users behind the same NAT. This can lead
// to interesting behavior because the STUN server will only give out the
// address of the outermost NAT.
@@ -1705,7 +1807,7 @@
RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1]));
// Make the receiving timeout shorter for testing.
- cricket::IceConfig config = CreateIceConfig(1000, false);
+ IceConfig config = CreateIceConfig(1000, false);
ep1_ch1()->SetIceConfig(config);
ep2_ch1()->SetIceConfig(config);
@@ -1713,8 +1815,8 @@
LOG(LS_INFO) << "Failing over...";
fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[1]);
// The best connections will switch, so keep references to them.
- const cricket::Connection* best_connection1 = ep1_ch1()->best_connection();
- const cricket::Connection* best_connection2 = ep2_ch1()->best_connection();
+ const Connection* best_connection1 = ep1_ch1()->best_connection();
+ const Connection* best_connection2 = ep2_ch1()->best_connection();
// We should detect loss of receiving within 1 second or so.
EXPECT_TRUE_WAIT(
!best_connection1->receiving() && !best_connection2->receiving(), 3000);
@@ -1757,7 +1859,7 @@
RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1]));
// Make the receiving timeout shorter for testing.
- cricket::IceConfig config = CreateIceConfig(1000, false);
+ IceConfig config = CreateIceConfig(1000, false);
ep1_ch1()->SetIceConfig(config);
ep2_ch1()->SetIceConfig(config);
@@ -1765,8 +1867,8 @@
LOG(LS_INFO) << "Failing over...";
fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]);
// The best connections will switch, so keep references to them.
- const cricket::Connection* best_connection1 = ep1_ch1()->best_connection();
- const cricket::Connection* best_connection2 = ep2_ch1()->best_connection();
+ const Connection* best_connection1 = ep1_ch1()->best_connection();
+ const Connection* best_connection2 = ep2_ch1()->best_connection();
// We should detect loss of receiving within 1 second or so.
EXPECT_TRUE_WAIT(
!best_connection1->receiving() && !best_connection2->receiving(), 3000);
@@ -1869,11 +1971,10 @@
ep2_ch1()->SetIceConfig(CreateIceConfig(2000, false, backup_ping_interval));
// After the state becomes COMPLETED, the backup connection will be pinged
// once every |backup_ping_interval| milliseconds.
- ASSERT_TRUE_WAIT(ep2_ch1()->GetState() == cricket::STATE_COMPLETED, 1000);
- const std::vector<cricket::Connection*>& connections =
- ep2_ch1()->connections();
+ ASSERT_TRUE_WAIT(ep2_ch1()->GetState() == STATE_COMPLETED, 1000);
+ const std::vector<Connection*>& connections = ep2_ch1()->connections();
ASSERT_EQ(2U, connections.size());
- cricket::Connection* backup_conn = connections[1];
+ Connection* backup_conn = connections[1];
EXPECT_TRUE_WAIT(backup_conn->writable(), 3000);
int64_t last_ping_response_ms = backup_conn->last_ping_response_received();
EXPECT_TRUE_WAIT(
@@ -1892,10 +1993,10 @@
CreateChannels(1);
// Both transport channels will reach STATE_COMPLETED quickly.
- EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_COMPLETED,
- ep1_ch1()->GetState(), 1000);
- EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_COMPLETED,
- ep2_ch1()->GetState(), 1000);
+ EXPECT_EQ_WAIT(TransportChannelState::STATE_COMPLETED, ep1_ch1()->GetState(),
+ 1000);
+ EXPECT_EQ_WAIT(TransportChannelState::STATE_COMPLETED, ep2_ch1()->GetState(),
+ 1000);
}
// Tests that when a network interface becomes inactive, if and only if
@@ -1994,8 +2095,8 @@
ss_scope_(vss_.get()) {}
protected:
- void PrepareChannel(cricket::P2PTransportChannel* ch) {
- ch->SetIceRole(cricket::ICEROLE_CONTROLLING);
+ void PrepareChannel(P2PTransportChannel* ch) {
+ ch->SetIceRole(ICEROLE_CONTROLLING);
ch->SetIceCredentials(kIceUfrag[0], kIcePwd[0]);
ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]);
ch->SignalSelectedCandidatePairChanged.connect(
@@ -2006,54 +2107,39 @@
this, &P2PTransportChannelPingTest::OnChannelStateChanged);
}
- cricket::Candidate CreateHostCandidate(const std::string& ip,
- int port,
- int priority,
- const std::string& ufrag = "") {
- cricket::Candidate c;
- c.set_address(rtc::SocketAddress(ip, port));
- c.set_component(1);
- c.set_protocol(cricket::UDP_PROTOCOL_NAME);
- c.set_priority(priority);
- c.set_username(ufrag);
- c.set_type(cricket::LOCAL_PORT_TYPE);
- return c;
- }
-
- cricket::Connection* WaitForConnectionTo(cricket::P2PTransportChannel* ch,
- const std::string& ip,
- int port_num) {
+ Connection* WaitForConnectionTo(P2PTransportChannel* ch,
+ const std::string& ip,
+ int port_num) {
EXPECT_TRUE_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, 3000);
return GetConnectionTo(ch, ip, port_num);
}
- cricket::Port* GetPort(cricket::P2PTransportChannel* ch) {
+ Port* GetPort(P2PTransportChannel* ch) {
if (ch->ports().empty()) {
return nullptr;
}
- return static_cast<cricket::Port*>(ch->ports()[0]);
+ return static_cast<Port*>(ch->ports()[0]);
}
- cricket::Connection* GetConnectionTo(cricket::P2PTransportChannel* ch,
- const std::string& ip,
- int port_num) {
- cricket::Port* port = GetPort(ch);
+ Connection* GetConnectionTo(P2PTransportChannel* ch,
+ const std::string& ip,
+ int port_num) {
+ Port* port = GetPort(ch);
if (!port) {
return nullptr;
}
return port->GetConnection(rtc::SocketAddress(ip, port_num));
}
- cricket::Connection* FindNextPingableConnectionAndPingIt(
- cricket::P2PTransportChannel* ch) {
- cricket::Connection* conn = ch->FindNextPingableConnection();
+ Connection* FindNextPingableConnectionAndPingIt(P2PTransportChannel* ch) {
+ Connection* conn = ch->FindNextPingableConnection();
if (conn) {
ch->MarkConnectionPinged(conn);
}
return conn;
}
- int SendData(cricket::TransportChannel& channel,
+ int SendData(TransportChannel& channel,
const char* data,
size_t len,
int packet_id) {
@@ -2063,25 +2149,23 @@
}
void OnSelectedCandidatePairChanged(
- cricket::TransportChannel* transport_channel,
- cricket::CandidatePairInterface* selected_candidate_pair,
+ TransportChannel* transport_channel,
+ CandidatePairInterface* selected_candidate_pair,
int last_sent_packet_id) {
last_selected_candidate_pair_ = selected_candidate_pair;
last_sent_packet_id_ = last_sent_packet_id;
}
- void ReceivePingOnConnection(cricket::Connection* conn,
+ void ReceivePingOnConnection(Connection* conn,
const std::string& remote_ufrag,
int priority) {
- cricket::IceMessage msg;
- msg.SetType(cricket::STUN_BINDING_REQUEST);
- msg.AddAttribute(new cricket::StunByteStringAttribute(
- cricket::STUN_ATTR_USERNAME,
+ IceMessage msg;
+ msg.SetType(STUN_BINDING_REQUEST);
+ msg.AddAttribute(new StunByteStringAttribute(
+ STUN_ATTR_USERNAME,
conn->local_candidate().username() + ":" + remote_ufrag));
- msg.AddAttribute(new cricket::StunUInt32Attribute(
- cricket::STUN_ATTR_PRIORITY, priority));
- msg.SetTransactionID(
- rtc::CreateRandomString(cricket::kStunTransactionIdLength));
+ msg.AddAttribute(new StunUInt32Attribute(STUN_ATTR_PRIORITY, priority));
+ msg.SetTransactionID(rtc::CreateRandomString(kStunTransactionIdLength));
msg.AddMessageIntegrity(conn->local_candidate().password());
msg.AddFingerprint();
rtc::ByteBufferWriter buf;
@@ -2089,42 +2173,42 @@
conn->OnReadPacket(buf.Data(), buf.Length(), rtc::CreatePacketTime(0));
}
- void OnReadyToSend(cricket::TransportChannel* channel) {
+ void OnReadyToSend(TransportChannel* channel) {
channel_ready_to_send_ = true;
}
- void OnChannelStateChanged(cricket::TransportChannelImpl* channel) {
+ void OnChannelStateChanged(TransportChannelImpl* channel) {
channel_state_ = channel->GetState();
}
- cricket::CandidatePairInterface* last_selected_candidate_pair() {
+ CandidatePairInterface* last_selected_candidate_pair() {
return last_selected_candidate_pair_;
}
int last_sent_packet_id() { return last_sent_packet_id_; }
bool channel_ready_to_send() { return channel_ready_to_send_; }
void reset_channel_ready_to_send() { channel_ready_to_send_ = false; }
- cricket::TransportChannelState channel_state() { return channel_state_; }
+ TransportChannelState channel_state() { return channel_state_; }
private:
std::unique_ptr<rtc::PhysicalSocketServer> pss_;
std::unique_ptr<rtc::VirtualSocketServer> vss_;
rtc::SocketServerScope ss_scope_;
- cricket::CandidatePairInterface* last_selected_candidate_pair_ = nullptr;
+ CandidatePairInterface* last_selected_candidate_pair_ = nullptr;
int last_sent_packet_id_ = -1;
bool channel_ready_to_send_ = false;
- cricket::TransportChannelState channel_state_ = cricket::STATE_INIT;
+ TransportChannelState channel_state_ = STATE_INIT;
};
TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("trigger checks", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("trigger checks", 1, &pa);
PrepareChannel(&ch);
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
- ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2));
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
- cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn1 != nullptr);
ASSERT_TRUE(conn2 != nullptr);
@@ -2140,16 +2224,16 @@
}
TEST_F(P2PTransportChannelPingTest, TestAllConnectionsPingedSufficiently) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("ping sufficiently", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("ping sufficiently", 1, &pa);
PrepareChannel(&ch);
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
- ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2));
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
- cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn1 != nullptr);
ASSERT_TRUE(conn2 != nullptr);
@@ -2169,13 +2253,13 @@
int SCHEDULING_RANGE = 200;
int RTT_RANGE = 10;
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("TestChannel", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("TestChannel", 1, &pa);
PrepareChannel(&ch);
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
- cricket::Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
+ Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn != nullptr);
SIMULATED_WAIT(conn->num_pings_sent() == 1, kDefaultTimeout, clock);
@@ -2188,7 +2272,7 @@
int64_t ping_interval_ms = (clock.TimeNanos() - start) /
rtc::kNumNanosecsPerMillisec /
(MIN_PINGS_AT_WEAK_PING_INTERVAL - 1);
- EXPECT_EQ(ping_interval_ms, cricket::WEAK_PING_INTERVAL);
+ EXPECT_EQ(ping_interval_ms, WEAK_PING_INTERVAL);
// Stabilizing.
@@ -2199,11 +2283,9 @@
// to converge the RTT.
SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock);
ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec;
- EXPECT_GE(ping_interval_ms,
- cricket::STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL);
+ EXPECT_GE(ping_interval_ms, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL);
EXPECT_LE(ping_interval_ms,
- cricket::STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL +
- SCHEDULING_RANGE);
+ STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE);
// Stabilized.
@@ -2216,11 +2298,9 @@
start = clock.TimeNanos();
SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock);
ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec;
- EXPECT_GE(ping_interval_ms,
- cricket::STABLE_WRITABLE_CONNECTION_PING_INTERVAL);
- EXPECT_LE(
- ping_interval_ms,
- cricket::STABLE_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE);
+ EXPECT_GE(ping_interval_ms, STABLE_WRITABLE_CONNECTION_PING_INTERVAL);
+ EXPECT_LE(ping_interval_ms,
+ STABLE_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE);
// Destabilized.
@@ -2245,24 +2325,22 @@
ping_sent_before = conn->num_pings_sent();
SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock);
ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec;
- EXPECT_GE(ping_interval_ms,
- cricket::STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL);
+ EXPECT_GE(ping_interval_ms, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL);
EXPECT_LE(ping_interval_ms,
- cricket::STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL +
- SCHEDULING_RANGE);
+ STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE);
}
TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("trigger checks", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("trigger checks", 1, &pa);
PrepareChannel(&ch);
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
- ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2));
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
- cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn1 != nullptr);
ASSERT_TRUE(conn2 != nullptr);
@@ -2279,14 +2357,14 @@
}
TEST_F(P2PTransportChannelPingTest, TestFailedConnectionNotPingable) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("Do not ping failed connections", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("Do not ping failed connections", 1, &pa);
PrepareChannel(&ch);
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(conn1, ch.FindNextPingableConnection());
@@ -2297,18 +2375,18 @@
}
TEST_F(P2PTransportChannelPingTest, TestSignalStateChanged) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("state change", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("state change", 1, &pa);
PrepareChannel(&ch);
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
// Pruning the connection reduces the set of active connections and changes
// the channel state.
conn1->Prune();
- EXPECT_EQ_WAIT(cricket::STATE_FAILED, channel_state(), kDefaultTimeout);
+ EXPECT_EQ_WAIT(STATE_FAILED, channel_state(), kDefaultTimeout);
}
// Test adding remote candidates with different ufrags. If a remote candidate
@@ -2318,16 +2396,17 @@
// credentials arrive. If a remote candidate is added with the current ICE
// ufrag, its pwd and generation will be set properly.
TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("add candidate", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("add candidate", 1, &pa);
PrepareChannel(&ch);
ch.Connect();
ch.MaybeStartGathering();
// Add a candidate with a future ufrag.
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1, kIceUfrag[2]));
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ ch.AddRemoteCandidate(
+ CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1, kIceUfrag[2]));
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
- const cricket::Candidate& candidate = conn1->remote_candidate();
+ const Candidate& candidate = conn1->remote_candidate();
EXPECT_EQ(kIceUfrag[2], candidate.username());
EXPECT_TRUE(candidate.password().empty());
EXPECT_TRUE(FindNextPingableConnectionAndPingIt(&ch) == nullptr);
@@ -2341,22 +2420,24 @@
EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch));
// Add a candidate with an old ufrag. No connection will be created.
- ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2, kIceUfrag[1]));
+ ch.AddRemoteCandidate(
+ CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2, kIceUfrag[1]));
rtc::Thread::Current()->ProcessMessages(500);
EXPECT_TRUE(GetConnectionTo(&ch, "2.2.2.2", 2) == nullptr);
// Add a candidate with the current ufrag, its pwd and generation will be
// assigned, even if the generation is not set.
- ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 0, kIceUfrag[2]));
- cricket::Connection* conn3 = nullptr;
+ ch.AddRemoteCandidate(
+ CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 0, kIceUfrag[2]));
+ Connection* conn3 = nullptr;
ASSERT_TRUE_WAIT((conn3 = GetConnectionTo(&ch, "3.3.3.3", 3)) != nullptr,
3000);
- const cricket::Candidate& new_candidate = conn3->remote_candidate();
+ const Candidate& new_candidate = conn3->remote_candidate();
EXPECT_EQ(kIcePwd[2], new_candidate.password());
EXPECT_EQ(1U, new_candidate.generation());
// Check that the pwd of all remote candidates are properly assigned.
- for (const cricket::RemoteCandidate& candidate : ch.remote_candidates()) {
+ for (const RemoteCandidate& candidate : ch.remote_candidates()) {
EXPECT_TRUE(candidate.username() == kIceUfrag[1] ||
candidate.username() == kIceUfrag[2]);
if (candidate.username() == kIceUfrag[1]) {
@@ -2368,22 +2449,22 @@
}
TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("connection resurrection", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("connection resurrection", 1, &pa);
PrepareChannel(&ch);
ch.Connect();
ch.MaybeStartGathering();
// Create conn1 and keep track of original candidate priority.
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
uint32_t remote_priority = conn1->remote_candidate().priority();
// Create a higher priority candidate and make the connection
// receiving/writable. This will prune conn1.
- ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2));
- cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
+ Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
conn2->ReceivedPing();
conn2->ReceivedPingResponse(LOW_RTT);
@@ -2395,34 +2476,34 @@
EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 1000);
// Create a minimal STUN message with prflx priority.
- cricket::IceMessage request;
- request.SetType(cricket::STUN_BINDING_REQUEST);
- request.AddAttribute(new cricket::StunByteStringAttribute(
- cricket::STUN_ATTR_USERNAME, kIceUfrag[1]));
- uint32_t prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24;
- request.AddAttribute(new cricket::StunUInt32Attribute(
- cricket::STUN_ATTR_PRIORITY, prflx_priority));
+ IceMessage request;
+ request.SetType(STUN_BINDING_REQUEST);
+ request.AddAttribute(
+ new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1]));
+ uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
+ request.AddAttribute(
+ new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority));
EXPECT_NE(prflx_priority, remote_priority);
- cricket::Port* port = GetPort(&ch);
+ Port* port = GetPort(&ch);
// conn1 should be resurrected with original priority.
- port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1),
- cricket::PROTO_UDP, &request, kIceUfrag[1], false);
+ port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP,
+ &request, kIceUfrag[1], false);
conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(conn1->remote_candidate().priority(), remote_priority);
// conn3, a real prflx connection, should have prflx priority.
- port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 1),
- cricket::PROTO_UDP, &request, kIceUfrag[1], false);
- cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 1);
+ port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 1), PROTO_UDP,
+ &request, kIceUfrag[1], false);
+ Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 1);
ASSERT_TRUE(conn3 != nullptr);
EXPECT_EQ(conn3->remote_candidate().priority(), prflx_priority);
}
TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("receiving state change", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("receiving state change", 1, &pa);
PrepareChannel(&ch);
// Default receiving timeout and checking receiving interval should not be too
// small.
@@ -2433,8 +2514,8 @@
EXPECT_EQ(50, ch.check_receiving_interval());
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
conn1->ReceivedPing();
@@ -2451,14 +2532,14 @@
// best connection changes and SignalReadyToSend will be fired if the new best
// connection is writable.
TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("receiving state change", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("receiving state change", 1, &pa);
PrepareChannel(&ch);
- ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
+ ch.SetIceRole(ICEROLE_CONTROLLED);
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(conn1, ch.best_connection());
EXPECT_EQ(conn1, last_selected_candidate_pair());
@@ -2472,8 +2553,8 @@
SendData(ch, data, len, ++last_packet_id);
// When a higher priority candidate comes in, the new connection is chosen
// as the best connection.
- ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 10));
- cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10));
+ Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
EXPECT_EQ(conn2, ch.best_connection());
EXPECT_EQ(conn2, last_selected_candidate_pair());
@@ -2484,8 +2565,8 @@
// connection will be set as the best connection, even though
// its priority is lower.
SendData(ch, data, len, ++last_packet_id);
- ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 1));
- cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1));
+ Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
ASSERT_TRUE(conn3 != nullptr);
// Because it has a lower priority, the best connection is still conn2.
EXPECT_EQ(conn2, ch.best_connection());
@@ -2503,8 +2584,8 @@
// it will not be set as the best connection because the best connection
// is nominated by the controlling side.
SendData(ch, data, len, ++last_packet_id);
- ch.AddRemoteCandidate(CreateHostCandidate("4.4.4.4", 4, 100));
- cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "4.4.4.4", 4, 100));
+ Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4);
ASSERT_TRUE(conn4 != nullptr);
EXPECT_EQ(conn3, ch.best_connection());
// But if it is nominated via use_candidate and writable, it will be set as
@@ -2529,24 +2610,24 @@
// request contains the use_candidate attribute. Plus, it will also sends back
// a ping response and set the ICE pwd in the remote candidate appropriately.
TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("receiving state change", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("receiving state change", 1, &pa);
PrepareChannel(&ch);
- ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
+ ch.SetIceRole(ICEROLE_CONTROLLED);
ch.Connect();
ch.MaybeStartGathering();
// A minimal STUN message with prflx priority.
- cricket::IceMessage request;
- request.SetType(cricket::STUN_BINDING_REQUEST);
- request.AddAttribute(new cricket::StunByteStringAttribute(
- cricket::STUN_ATTR_USERNAME, kIceUfrag[1]));
- uint32_t prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24;
- request.AddAttribute(new cricket::StunUInt32Attribute(
- cricket::STUN_ATTR_PRIORITY, prflx_priority));
- cricket::TestUDPPort* port = static_cast<cricket::TestUDPPort*>(GetPort(&ch));
- port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1),
- cricket::PROTO_UDP, &request, kIceUfrag[1], false);
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ IceMessage request;
+ request.SetType(STUN_BINDING_REQUEST);
+ request.AddAttribute(
+ new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1]));
+ uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
+ request.AddAttribute(
+ new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority));
+ TestUDPPort* port = static_cast<TestUDPPort*>(GetPort(&ch));
+ port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP,
+ &request, kIceUfrag[1], false);
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_TRUE(port->sent_binding_response());
EXPECT_EQ(conn1, ch.best_connection());
@@ -2555,8 +2636,8 @@
port->set_sent_binding_response(false);
// Another connection is nominated via use_candidate.
- ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1));
- cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
+ Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
// Because it has a lower priority, the best connection is still conn1.
EXPECT_EQ(conn1, ch.best_connection());
@@ -2570,9 +2651,9 @@
// Another request with unknown address, it will not be set as the best
// connection because the best connection was nominated by the controlling
// side.
- port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3),
- cricket::PROTO_UDP, &request, kIceUfrag[1], false);
- cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
+ port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), PROTO_UDP,
+ &request, kIceUfrag[1], false);
+ Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
ASSERT_TRUE(conn3 != nullptr);
EXPECT_TRUE(port->sent_binding_response());
conn3->ReceivedPingResponse(LOW_RTT); // Become writable.
@@ -2581,11 +2662,10 @@
// However if the request contains use_candidate attribute, it will be
// selected as the best connection.
- request.AddAttribute(
- new cricket::StunByteStringAttribute(cricket::STUN_ATTR_USE_CANDIDATE));
- port->SignalUnknownAddress(port, rtc::SocketAddress("4.4.4.4", 4),
- cricket::PROTO_UDP, &request, kIceUfrag[1], false);
- cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4);
+ request.AddAttribute(new StunByteStringAttribute(STUN_ATTR_USE_CANDIDATE));
+ port->SignalUnknownAddress(port, rtc::SocketAddress("4.4.4.4", 4), PROTO_UDP,
+ &request, kIceUfrag[1], false);
+ Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4);
ASSERT_TRUE(conn4 != nullptr);
EXPECT_TRUE(port->sent_binding_response());
// conn4 is not the best connection yet because it is not writable.
@@ -2598,9 +2678,9 @@
port->set_sent_binding_response(false);
ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]);
ch.SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]);
- port->SignalUnknownAddress(port, rtc::SocketAddress("5.5.5.5", 5),
- cricket::PROTO_UDP, &request, kIceUfrag[2], false);
- cricket::Connection* conn5 = WaitForConnectionTo(&ch, "5.5.5.5", 5);
+ port->SignalUnknownAddress(port, rtc::SocketAddress("5.5.5.5", 5), PROTO_UDP,
+ &request, kIceUfrag[2], false);
+ Connection* conn5 = WaitForConnectionTo(&ch, "5.5.5.5", 5);
ASSERT_TRUE(conn5 != nullptr);
EXPECT_TRUE(port->sent_binding_response());
EXPECT_EQ(kIcePwd[2], conn5->remote_candidate().password());
@@ -2611,22 +2691,22 @@
// at which point the controlled side will select that connection as
// the "best connection".
TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("receiving state change", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("receiving state change", 1, &pa);
PrepareChannel(&ch);
- ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
+ ch.SetIceRole(ICEROLE_CONTROLLED);
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 10));
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 10));
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(conn1, ch.best_connection());
// If a data packet is received on conn2, the best connection should
// switch to conn2 because the controlled side must mirror the media path
// chosen by the controlling side.
- ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1));
- cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
+ Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
conn2->ReceivedPing(); // Start receiving.
// Do not switch because it is not writable.
@@ -2640,19 +2720,18 @@
// Now another STUN message with an unknown address and use_candidate will
// nominate the best connection.
- cricket::IceMessage request;
- request.SetType(cricket::STUN_BINDING_REQUEST);
- request.AddAttribute(new cricket::StunByteStringAttribute(
- cricket::STUN_ATTR_USERNAME, kIceUfrag[1]));
- uint32_t prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24;
- request.AddAttribute(new cricket::StunUInt32Attribute(
- cricket::STUN_ATTR_PRIORITY, prflx_priority));
+ IceMessage request;
+ request.SetType(STUN_BINDING_REQUEST);
request.AddAttribute(
- new cricket::StunByteStringAttribute(cricket::STUN_ATTR_USE_CANDIDATE));
- cricket::Port* port = GetPort(&ch);
- port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3),
- cricket::PROTO_UDP, &request, kIceUfrag[1], false);
- cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
+ new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1]));
+ uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
+ request.AddAttribute(
+ new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority));
+ request.AddAttribute(new StunByteStringAttribute(STUN_ATTR_USE_CANDIDATE));
+ Port* port = GetPort(&ch);
+ port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), PROTO_UDP,
+ &request, kIceUfrag[1], false);
+ Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
ASSERT_TRUE(conn3 != nullptr);
EXPECT_EQ(conn2, ch.best_connection()); // Not writable yet.
conn3->ReceivedPingResponse(LOW_RTT); // Become writable.
@@ -2669,8 +2748,8 @@
// Test that if a new remote candidate has the same address and port with
// an old one, it will be used to create a new connection.
TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithAddressReuse) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("candidate reuse", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("candidate reuse", 1, &pa);
PrepareChannel(&ch);
ch.Connect();
ch.MaybeStartGathering();
@@ -2678,16 +2757,16 @@
const int port_num = 1;
// kIceUfrag[1] is the current generation ufrag.
- cricket::Candidate candidate =
- CreateHostCandidate(host_address, port_num, 1, kIceUfrag[1]);
+ Candidate candidate = CreateUdpCandidate(LOCAL_PORT_TYPE, host_address,
+ port_num, 1, kIceUfrag[1]);
ch.AddRemoteCandidate(candidate);
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, host_address, port_num);
+ Connection* conn1 = WaitForConnectionTo(&ch, host_address, port_num);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(0u, conn1->remote_candidate().generation());
// Simply adding the same candidate again won't create a new connection.
ch.AddRemoteCandidate(candidate);
- cricket::Connection* conn2 = GetConnectionTo(&ch, host_address, port_num);
+ Connection* conn2 = GetConnectionTo(&ch, host_address, port_num);
EXPECT_EQ(conn1, conn2);
// Update the ufrag of the candidate and add it again.
@@ -2708,22 +2787,22 @@
// When the current best connection is strong, lower-priority connections will
// be pruned. Otherwise, lower-priority connections are kept.
TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("test channel", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("test channel", 1, &pa);
PrepareChannel(&ch);
- ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
+ ch.SetIceRole(ICEROLE_CONTROLLED);
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(conn1, ch.best_connection());
conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving
// When a higher-priority, nominated candidate comes in, the connections with
// lower-priority are pruned.
- ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 10));
- cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10));
+ Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving
conn2->set_nominated(true);
@@ -2734,8 +2813,8 @@
// Wait until conn2 becomes not receiving.
EXPECT_TRUE_WAIT(!conn2->receiving(), 3000);
- ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 1));
- cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1));
+ Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
ASSERT_TRUE(conn3 != nullptr);
// The best connection should still be conn2. Even through conn3 has lower
// priority and is not receiving/writable, it is not pruned because the best
@@ -2746,41 +2825,40 @@
// Test that GetState returns the state correctly.
TEST_F(P2PTransportChannelPingTest, TestGetState) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("test channel", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("test channel", 1, &pa);
PrepareChannel(&ch);
ch.Connect();
ch.MaybeStartGathering();
- EXPECT_EQ(cricket::TransportChannelState::STATE_INIT, ch.GetState());
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100));
- ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1));
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
- cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
+ EXPECT_EQ(TransportChannelState::STATE_INIT, ch.GetState());
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn1 != nullptr);
ASSERT_TRUE(conn2 != nullptr);
// Now there are two connections, so the transport channel is connecting.
- EXPECT_EQ(cricket::TransportChannelState::STATE_CONNECTING, ch.GetState());
+ EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState());
// |conn1| becomes writable and receiving; it then should prune |conn2|.
conn1->ReceivedPingResponse(LOW_RTT);
EXPECT_TRUE_WAIT(conn2->pruned(), 1000);
- EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState());
+ EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState());
conn1->Prune(); // All connections are pruned.
// Need to wait until the channel state is updated.
- EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_FAILED, ch.GetState(),
- 1000);
+ EXPECT_EQ_WAIT(TransportChannelState::STATE_FAILED, ch.GetState(), 1000);
}
// Test that when a low-priority connection is pruned, it is not deleted
// right away, and it can become active and be pruned again.
TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("test channel", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("test channel", 1, &pa);
PrepareChannel(&ch);
ch.SetIceConfig(CreateIceConfig(1000, false));
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100));
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(conn1, ch.best_connection());
conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving
@@ -2789,53 +2867,53 @@
// not be deleted right away. Once the current best connection becomes not
// receiving, |conn2| will start to ping and upon receiving the ping response,
// it will become the best connection.
- ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1));
- cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
+ Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
EXPECT_TRUE_WAIT(!conn2->active(), 1000);
// |conn2| should not send a ping yet.
- EXPECT_EQ(cricket::Connection::STATE_WAITING, conn2->state());
- EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState());
+ EXPECT_EQ(Connection::STATE_WAITING, conn2->state());
+ EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState());
// Wait for |conn1| becoming not receiving.
EXPECT_TRUE_WAIT(!conn1->receiving(), 3000);
// Make sure conn2 is not deleted.
conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
- EXPECT_EQ_WAIT(cricket::Connection::STATE_INPROGRESS, conn2->state(), 1000);
+ EXPECT_EQ_WAIT(Connection::STATE_INPROGRESS, conn2->state(), 1000);
conn2->ReceivedPingResponse(LOW_RTT);
EXPECT_EQ_WAIT(conn2, ch.best_connection(), 1000);
- EXPECT_EQ(cricket::TransportChannelState::STATE_CONNECTING, ch.GetState());
+ EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState());
// When |conn1| comes back again, |conn2| will be pruned again.
conn1->ReceivedPingResponse(LOW_RTT);
EXPECT_EQ_WAIT(conn1, ch.best_connection(), 1000);
EXPECT_TRUE_WAIT(!conn2->active(), 1000);
- EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState());
+ EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState());
}
// Test that if all connections in a channel has timed out on writing, they
// will all be deleted. We use Prune to simulate write_time_out.
TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("test channel", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("test channel", 1, &pa);
PrepareChannel(&ch);
ch.Connect();
ch.MaybeStartGathering();
// Have one connection only but later becomes write-time-out.
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100));
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
conn1->ReceivedPing(); // Becomes receiving
conn1->Prune();
EXPECT_TRUE_WAIT(ch.connections().empty(), 1000);
// Have two connections but both become write-time-out later.
- ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1));
- cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
+ Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
conn2->ReceivedPing(); // Becomes receiving
- ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 2));
- cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 2));
+ Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
ASSERT_TRUE(conn3 != nullptr);
conn3->ReceivedPing(); // Becomes receiving
// Now prune both conn2 and conn3; they will be deleted soon.
@@ -2849,14 +2927,14 @@
// connection belonging to an old session becomes writable, it won't stop
// the current port allocator session.
TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("test channel", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("test channel", 1, &pa);
PrepareChannel(&ch);
ch.SetIceConfig(CreateIceConfig(2000, false));
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100));
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving
EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts());
@@ -2872,8 +2950,8 @@
// But if a new connection created from the new session becomes writable,
// it will stop the current session.
- ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 100));
- cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 100));
+ Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving
EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts());
@@ -2885,25 +2963,24 @@
// destroyed.
TEST_F(P2PTransportChannelPingTest,
TestIceRoleUpdatedOnPortAfterSignalNetworkInactive) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch(
- "test channel", cricket::ICE_CANDIDATE_COMPONENT_DEFAULT, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa);
// Starts with ICEROLE_CONTROLLING.
PrepareChannel(&ch);
- cricket::IceConfig config = CreateIceConfig(1000, true);
+ IceConfig config = CreateIceConfig(1000, true);
ch.SetIceConfig(config);
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
- cricket::Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn != nullptr);
// Make the fake port signal that its network is inactive, then change the
// ICE role and expect it to be updated.
conn->port()->SignalNetworkInactive(conn->port());
- ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
- EXPECT_EQ(cricket::ICEROLE_CONTROLLED, conn->port()->GetIceRole());
+ ch.SetIceRole(ICEROLE_CONTROLLED);
+ EXPECT_EQ(ICEROLE_CONTROLLED, conn->port()->GetIceRole());
}
// Test that the ICE role is updated even on ports with inactive networks.
@@ -2911,24 +2988,23 @@
// pings sent by those connections until they're replaced by newer-generation
// connections.
TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnPortAfterIceRestart) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch(
- "test channel", cricket::ICE_CANDIDATE_COMPONENT_DEFAULT, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa);
// Starts with ICEROLE_CONTROLLING.
PrepareChannel(&ch);
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
- cricket::Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn != nullptr);
// Do an ICE restart, change the role, and expect the old port to have its
// role updated.
ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]);
ch.MaybeStartGathering();
- ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
- EXPECT_EQ(cricket::ICEROLE_CONTROLLED, conn->port()->GetIceRole());
+ ch.SetIceRole(ICEROLE_CONTROLLED);
+ EXPECT_EQ(ICEROLE_CONTROLLED, conn->port()->GetIceRole());
}
// Test that after some amount of time without receiving data, the connection
@@ -2936,17 +3012,16 @@
TEST_F(P2PTransportChannelPingTest, TestPortDestroyedAfterTimeout) {
rtc::ScopedFakeClock fake_clock;
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch(
- "test channel", cricket::ICE_CANDIDATE_COMPONENT_DEFAULT, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa);
PrepareChannel(&ch);
// Only a controlled channel should expect its ports to be destroyed.
- ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
+ ch.SetIceRole(ICEROLE_CONTROLLED);
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
- cricket::Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn != nullptr);
// Simulate 2 minutes going by. This should be enough time for the port to
@@ -2964,26 +3039,23 @@
P2PTransportChannelMostLikelyToWorkFirstTest()
: turn_server_(rtc::Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr) {
network_manager_.AddInterface(kPublicAddrs[0]);
- allocator_.reset(new cricket::BasicPortAllocator(
+ allocator_.reset(new BasicPortAllocator(
&network_manager_, ServerAddresses(), rtc::SocketAddress(),
rtc::SocketAddress(), rtc::SocketAddress()));
- allocator_->set_flags(allocator_->flags() |
- cricket::PORTALLOCATOR_DISABLE_STUN |
- cricket::PORTALLOCATOR_DISABLE_TCP);
- cricket::RelayServerConfig config(cricket::RELAY_TURN);
+ allocator_->set_flags(allocator_->flags() | PORTALLOCATOR_DISABLE_STUN |
+ PORTALLOCATOR_DISABLE_TCP);
+ RelayServerConfig config(RELAY_TURN);
config.credentials = kRelayCredentials;
- config.ports.push_back(
- cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
+ config.ports.push_back(ProtocolAddress(kTurnUdpIntAddr, PROTO_UDP, false));
allocator_->AddTurnServer(config);
allocator_->set_step_delay(kMinimumStepDelay);
}
- cricket::P2PTransportChannel& StartTransportChannel(
+ P2PTransportChannel& StartTransportChannel(
bool prioritize_most_likely_to_work,
int stable_writable_connection_ping_interval) {
- channel_.reset(
- new cricket::P2PTransportChannel("checks", 1, nullptr, allocator()));
- cricket::IceConfig config = channel_->config();
+ channel_.reset(new P2PTransportChannel("checks", 1, nullptr, allocator()));
+ IceConfig config = channel_->config();
config.prioritize_most_likely_candidate_pairs =
prioritize_most_likely_to_work;
config.stable_writable_connection_ping_interval =
@@ -2995,8 +3067,8 @@
return *channel_.get();
}
- cricket::BasicPortAllocator* allocator() { return allocator_.get(); }
- cricket::TestTurnServer* turn_server() { return &turn_server_; }
+ BasicPortAllocator* allocator() { return allocator_.get(); }
+ TestTurnServer* turn_server() { return &turn_server_; }
// This verifies the next pingable connection has the expected candidates'
// types and, for relay local candidate, the expected relay protocol and ping
@@ -3004,30 +3076,20 @@
void VerifyNextPingableConnection(
const std::string& local_candidate_type,
const std::string& remote_candidate_type,
- const std::string& relay_protocol_type = cricket::UDP_PROTOCOL_NAME) {
- cricket::Connection* conn =
- FindNextPingableConnectionAndPingIt(channel_.get());
+ const std::string& relay_protocol_type = UDP_PROTOCOL_NAME) {
+ Connection* conn = FindNextPingableConnectionAndPingIt(channel_.get());
EXPECT_EQ(conn->local_candidate().type(), local_candidate_type);
- if (conn->local_candidate().type() == cricket::RELAY_PORT_TYPE) {
+ if (conn->local_candidate().type() == RELAY_PORT_TYPE) {
EXPECT_EQ(conn->local_candidate().relay_protocol(), relay_protocol_type);
}
EXPECT_EQ(conn->remote_candidate().type(), remote_candidate_type);
}
- cricket::Candidate CreateRelayCandidate(const std::string& ip,
- int port,
- int priority,
- const std::string& ufrag = "") {
- cricket::Candidate c = CreateHostCandidate(ip, port, priority, ufrag);
- c.set_type(cricket::RELAY_PORT_TYPE);
- return c;
- }
-
private:
- std::unique_ptr<cricket::BasicPortAllocator> allocator_;
+ std::unique_ptr<BasicPortAllocator> allocator_;
rtc::FakeNetworkManager network_manager_;
- cricket::TestTurnServer turn_server_;
- std::unique_ptr<cricket::P2PTransportChannel> channel_;
+ TestTurnServer turn_server_;
+ std::unique_ptr<P2PTransportChannel> channel_;
};
// Test that Relay/Relay connections will be pinged first when no other
@@ -3036,33 +3098,32 @@
TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest,
TestRelayRelayFirstWhenNothingPingedYet) {
const int max_strong_interval = 100;
- cricket::P2PTransportChannel& ch =
- StartTransportChannel(true, max_strong_interval);
+ P2PTransportChannel& ch = StartTransportChannel(true, max_strong_interval);
EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000);
- EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE);
- EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE);
+ EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE);
+ EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE);
- ch.AddRemoteCandidate(CreateRelayCandidate("1.1.1.1", 1, 1));
- ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2));
+ ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "1.1.1.1", 1, 1));
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000);
// Relay/Relay should be the first pingable connection.
- cricket::Connection* conn = FindNextPingableConnectionAndPingIt(&ch);
- EXPECT_EQ(conn->local_candidate().type(), cricket::RELAY_PORT_TYPE);
- EXPECT_EQ(conn->remote_candidate().type(), cricket::RELAY_PORT_TYPE);
+ Connection* conn = FindNextPingableConnectionAndPingIt(&ch);
+ EXPECT_EQ(conn->local_candidate().type(), RELAY_PORT_TYPE);
+ EXPECT_EQ(conn->remote_candidate().type(), RELAY_PORT_TYPE);
// Unless that we have a trigger check waiting to be pinged.
- cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
- EXPECT_EQ(conn2->local_candidate().type(), cricket::LOCAL_PORT_TYPE);
- EXPECT_EQ(conn2->remote_candidate().type(), cricket::LOCAL_PORT_TYPE);
+ Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
+ EXPECT_EQ(conn2->local_candidate().type(), LOCAL_PORT_TYPE);
+ EXPECT_EQ(conn2->remote_candidate().type(), LOCAL_PORT_TYPE);
conn2->ReceivedPing();
EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch));
// Make conn3 the best connection.
- cricket::Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
- EXPECT_EQ(conn3->local_candidate().type(), cricket::LOCAL_PORT_TYPE);
- EXPECT_EQ(conn3->remote_candidate().type(), cricket::RELAY_PORT_TYPE);
+ Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ EXPECT_EQ(conn3->local_candidate().type(), LOCAL_PORT_TYPE);
+ EXPECT_EQ(conn3->remote_candidate().type(), RELAY_PORT_TYPE);
conn3->ReceivedPingResponse(LOW_RTT);
ASSERT_TRUE(conn3->writable());
conn3->ReceivedPing();
@@ -3092,107 +3153,95 @@
// in the first round.
TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest,
TestRelayRelayFirstWhenEverythingPinged) {
- cricket::P2PTransportChannel& ch = StartTransportChannel(true, 100);
+ P2PTransportChannel& ch = StartTransportChannel(true, 100);
EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000);
- EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE);
- EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE);
+ EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE);
+ EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE);
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
EXPECT_TRUE_WAIT(ch.connections().size() == 2, 5000);
// Initially, only have Local/Local and Local/Relay.
- VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE,
- cricket::LOCAL_PORT_TYPE);
- VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
- cricket::LOCAL_PORT_TYPE);
+ VerifyNextPingableConnection(LOCAL_PORT_TYPE, LOCAL_PORT_TYPE);
+ VerifyNextPingableConnection(RELAY_PORT_TYPE, LOCAL_PORT_TYPE);
// Remote Relay candidate arrives.
- ch.AddRemoteCandidate(CreateRelayCandidate("2.2.2.2", 2, 2));
+ ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "2.2.2.2", 2, 2));
EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000);
// Relay/Relay should be the first since it hasn't been pinged before.
- VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
- cricket::RELAY_PORT_TYPE);
+ VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE);
// Local/Relay is the final one.
- VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE,
- cricket::RELAY_PORT_TYPE);
+ VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE);
// Now, every connection has been pinged once. The next one should be
// Relay/Relay.
- VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
- cricket::RELAY_PORT_TYPE);
+ VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE);
}
// Test that when we receive a new remote candidate, they will be tried first
// before we re-ping Relay/Relay connections again.
TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest,
TestNoStarvationOnNonRelayConnection) {
- cricket::P2PTransportChannel& ch = StartTransportChannel(true, 100);
+ P2PTransportChannel& ch = StartTransportChannel(true, 100);
EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000);
- EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE);
- EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE);
+ EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE);
+ EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE);
- ch.AddRemoteCandidate(CreateRelayCandidate("1.1.1.1", 1, 1));
+ ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "1.1.1.1", 1, 1));
EXPECT_TRUE_WAIT(ch.connections().size() == 2, 5000);
// Initially, only have Relay/Relay and Local/Relay. Ping Relay/Relay first.
- VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
- cricket::RELAY_PORT_TYPE);
+ VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE);
// Next, ping Local/Relay.
- VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE,
- cricket::RELAY_PORT_TYPE);
+ VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE);
// Remote Local candidate arrives.
- ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2));
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000);
// Local/Local should be the first since it hasn't been pinged before.
- VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE,
- cricket::LOCAL_PORT_TYPE);
+ VerifyNextPingableConnection(LOCAL_PORT_TYPE, LOCAL_PORT_TYPE);
// Relay/Local is the final one.
- VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
- cricket::LOCAL_PORT_TYPE);
+ VerifyNextPingableConnection(RELAY_PORT_TYPE, LOCAL_PORT_TYPE);
// Now, every connection has been pinged once. The next one should be
// Relay/Relay.
- VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
- cricket::RELAY_PORT_TYPE);
+ VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE);
}
// Test the ping sequence is UDP Relay/Relay followed by TCP Relay/Relay,
// followed by the rest.
TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, TestTcpTurn) {
// Add a Tcp Turn server.
- turn_server()->AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP);
- cricket::RelayServerConfig config(cricket::RELAY_TURN);
+ turn_server()->AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP);
+ RelayServerConfig config(RELAY_TURN);
config.credentials = kRelayCredentials;
- config.ports.push_back(
- cricket::ProtocolAddress(kTurnTcpIntAddr, cricket::PROTO_TCP, false));
+ config.ports.push_back(ProtocolAddress(kTurnTcpIntAddr, PROTO_TCP, false));
allocator()->AddTurnServer(config);
- cricket::P2PTransportChannel& ch = StartTransportChannel(true, 100);
+ P2PTransportChannel& ch = StartTransportChannel(true, 100);
EXPECT_TRUE_WAIT(ch.ports().size() == 3, 5000);
- EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE);
- EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE);
- EXPECT_EQ(ch.ports()[2]->Type(), cricket::RELAY_PORT_TYPE);
+ EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE);
+ EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE);
+ EXPECT_EQ(ch.ports()[2]->Type(), RELAY_PORT_TYPE);
// Remote Relay candidate arrives.
- ch.AddRemoteCandidate(CreateRelayCandidate("1.1.1.1", 1, 1));
+ ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "1.1.1.1", 1, 1));
EXPECT_TRUE_WAIT(ch.connections().size() == 3, 5000);
// UDP Relay/Relay should be pinged first.
- VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
- cricket::RELAY_PORT_TYPE);
+ VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE);
// TCP Relay/Relay is the next.
- VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
- cricket::RELAY_PORT_TYPE,
- cricket::TCP_PROTOCOL_NAME);
+ VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE,
+ TCP_PROTOCOL_NAME);
// Finally, Local/Relay will be pinged.
- VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE,
- cricket::RELAY_PORT_TYPE);
+ VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE);
}
+
+} // namespace cricket {
diff --git a/p2p/base/port.h b/p2p/base/port.h
index 5d95b80..54f7acd 100644
--- a/p2p/base/port.h
+++ b/p2p/base/port.h
@@ -178,7 +178,7 @@
}
// Identifies the generation that this port was created in.
- uint32_t generation() { return generation_; }
+ uint32_t generation() const { return generation_; }
void set_generation(uint32_t generation) { generation_ = generation; }
const std::string username_fragment() const;
diff --git a/p2p/base/transport.h b/p2p/base/transport.h
index d50b8e5..1583b71 100644
--- a/p2p/base/transport.h
+++ b/p2p/base/transport.h
@@ -152,6 +152,8 @@
};
// Information about ICE configuration.
+// TODO(deadbeef): Use rtc::Optional to represent unset values, instead of
+// -1.
struct IceConfig {
// The ICE connection receiving timeout value in milliseconds.
int receiving_timeout = -1;
@@ -168,19 +170,26 @@
// Writable connections are pinged at a slower rate once stablized.
int stable_writable_connection_ping_interval = -1;
+ // If set to true, this means the ICE transport should presume TURN-to-TURN
+ // candidate pairs will succeed, even before a binding response is received.
+ bool presume_writable_when_fully_relayed = false;
+
IceConfig() {}
IceConfig(int receiving_timeout_ms,
int backup_connection_ping_interval,
bool gather_continually,
bool prioritize_most_likely_candidate_pairs,
- int stable_writable_connection_ping_interval_ms)
+ int stable_writable_connection_ping_interval_ms,
+ bool presume_writable_when_fully_relayed)
: receiving_timeout(receiving_timeout_ms),
backup_connection_ping_interval(backup_connection_ping_interval),
gather_continually(gather_continually),
prioritize_most_likely_candidate_pairs(
prioritize_most_likely_candidate_pairs),
stable_writable_connection_ping_interval(
- stable_writable_connection_ping_interval_ms) {}
+ stable_writable_connection_ping_interval_ms),
+ presume_writable_when_fully_relayed(
+ presume_writable_when_fully_relayed) {}
};
bool BadTransportDescription(const std::string& desc, std::string* err_desc);