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

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

Issue 2063823008: Adding IceConfig option to assume TURN/TURN candidate pairs will work. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 11 matching lines...) Expand all
22 #include "webrtc/p2p/base/common.h" 22 #include "webrtc/p2p/base/common.h"
23 #include "webrtc/p2p/base/relayport.h" // For RELAY_PORT_TYPE. 23 #include "webrtc/p2p/base/relayport.h" // For RELAY_PORT_TYPE.
24 #include "webrtc/p2p/base/stunport.h" // For STUN_PORT_TYPE. 24 #include "webrtc/p2p/base/stunport.h" // For STUN_PORT_TYPE.
25 #include "webrtc/system_wrappers/include/field_trial.h" 25 #include "webrtc/system_wrappers/include/field_trial.h"
26 26
27 namespace { 27 namespace {
28 28
29 // messages for queuing up work for ourselves 29 // messages for queuing up work for ourselves
30 enum { MSG_SORT = 1, MSG_CHECK_AND_PING }; 30 enum { MSG_SORT = 1, MSG_CHECK_AND_PING };
31 31
32 // Mapped write states used by P2PTransportChannel::MappedWriteState.
33 enum {
34 MAPPED_WRITE_STATE_WRITABLE = 1,
35 MAPPED_WRITE_STATE_PROBABLY_WRITABLE,
36 MAPPED_WRITE_STATE_UNRELIABLE,
37 MAPPED_WRITE_STATE_INIT,
38 MAPPED_WRITE_STATE_TIMEOUT
39 };
40
32 // The minimum improvement in RTT that justifies a switch. 41 // The minimum improvement in RTT that justifies a switch.
33 static const double kMinImprovement = 10; 42 static const double kMinImprovement = 10;
34 43
35 bool IsRelayRelay(cricket::Connection* conn) { 44 bool IsRelayRelay(const cricket::Connection* conn) {
36 return conn->local_candidate().type() == cricket::RELAY_PORT_TYPE && 45 return conn->local_candidate().type() == cricket::RELAY_PORT_TYPE &&
37 conn->remote_candidate().type() == cricket::RELAY_PORT_TYPE; 46 conn->remote_candidate().type() == cricket::RELAY_PORT_TYPE;
38 } 47 }
39 48
40 bool IsUdp(cricket::Connection* conn) { 49 bool IsUdp(cricket::Connection* conn) {
41 return conn->local_candidate().relay_protocol() == cricket::UDP_PROTOCOL_NAME; 50 return conn->local_candidate().relay_protocol() == cricket::UDP_PROTOCOL_NAME;
42 } 51 }
43 52
44 cricket::PortInterface::CandidateOrigin GetOrigin(cricket::PortInterface* port, 53 cricket::PortInterface::CandidateOrigin GetOrigin(cricket::PortInterface* port,
45 cricket::PortInterface* origin_port) { 54 cricket::PortInterface* origin_port) {
46 if (!origin_port) 55 if (!origin_port)
47 return cricket::PortInterface::ORIGIN_MESSAGE; 56 return cricket::PortInterface::ORIGIN_MESSAGE;
48 else if (port == origin_port) 57 else if (port == origin_port)
49 return cricket::PortInterface::ORIGIN_THIS_PORT; 58 return cricket::PortInterface::ORIGIN_THIS_PORT;
50 else 59 else
51 return cricket::PortInterface::ORIGIN_OTHER_PORT; 60 return cricket::PortInterface::ORIGIN_OTHER_PORT;
52 } 61 }
53 62
54 // Compares two connections based only on the candidate and network information.
55 // Returns positive if |a| is better than |b|.
56 int CompareConnectionCandidates(cricket::Connection* a,
57 cricket::Connection* b) {
58 uint32_t a_cost = a->ComputeNetworkCost();
59 uint32_t b_cost = b->ComputeNetworkCost();
60 // Smaller cost is better.
61 if (a_cost < b_cost) {
62 return 1;
63 }
64 if (a_cost > b_cost) {
65 return -1;
66 }
67
68 // Compare connection priority. Lower values get sorted last.
69 if (a->priority() > b->priority())
70 return 1;
71 if (a->priority() < b->priority())
72 return -1;
73
74 // If we're still tied at this point, prefer a younger generation.
75 return (a->remote_candidate().generation() + a->port()->generation()) -
76 (b->remote_candidate().generation() + b->port()->generation());
77 }
78
79 // Compare two connections based on their writing, receiving, and connected
80 // states.
81 int CompareConnectionStates(cricket::Connection* a, cricket::Connection* b) {
82 // Sort based on write-state. Better states have lower values.
83 if (a->write_state() < b->write_state())
84 return 1;
85 if (a->write_state() > b->write_state())
86 return -1;
87
88 // We prefer a receiving connection to a non-receiving, higher-priority
89 // connection when sorting connections and choosing which connection to
90 // switch to.
91 if (a->receiving() && !b->receiving())
92 return 1;
93 if (!a->receiving() && b->receiving())
94 return -1;
95
96 // WARNING: Some complexity here about TCP reconnecting.
97 // When a TCP connection fails because of a TCP socket disconnecting, the
98 // active side of the connection will attempt to reconnect for 5 seconds while
99 // pretending to be writable (the connection is not set to the unwritable
100 // state). On the passive side, the connection also remains writable even
101 // though it is disconnected, and a new connection is created when the active
102 // side connects. At that point, there are two TCP connections on the passive
103 // side: 1. the old, disconnected one that is pretending to be writable, and
104 // 2. the new, connected one that is maybe not yet writable. For purposes of
105 // pruning, pinging, and selecting the best connection, we want to treat the
106 // new connection as "better" than the old one. We could add a method called
107 // something like Connection::ImReallyBadEvenThoughImWritable, but that is
108 // equivalent to the existing Connection::connected(), which we already have.
109 // So, in code throughout this file, we'll check whether the connection is
110 // connected() or not, and if it is not, treat it as "worse" than a connected
111 // one, even though it's writable. In the code below, we're doing so to make
112 // sure we treat a new writable connection as better than an old disconnected
113 // connection.
114
115 // In the case where we reconnect TCP connections, the original best
116 // connection is disconnected without changing to WRITE_TIMEOUT. In this case,
117 // the new connection, when it becomes writable, should have higher priority.
118 if (a->write_state() == cricket::Connection::STATE_WRITABLE &&
119 b->write_state() == cricket::Connection::STATE_WRITABLE) {
120 if (a->connected() && !b->connected()) {
121 return 1;
122 }
123 if (!a->connected() && b->connected()) {
124 return -1;
125 }
126 }
127 return 0;
128 }
129
130 int CompareConnections(cricket::Connection* a, cricket::Connection* b) {
131 int state_cmp = CompareConnectionStates(a, b);
132 if (state_cmp != 0) {
133 return state_cmp;
134 }
135 // Compare the candidate information.
136 return CompareConnectionCandidates(a, b);
137 }
138
139 // Wraps the comparison connection into a less than operator that puts higher
140 // priority writable connections first.
141 class ConnectionCompare {
142 public:
143 bool operator()(const cricket::Connection *ca,
144 const cricket::Connection *cb) {
145 cricket::Connection* a = const_cast<cricket::Connection*>(ca);
146 cricket::Connection* b = const_cast<cricket::Connection*>(cb);
147
148 // Compare first on writability and static preferences.
149 int cmp = CompareConnections(a, b);
150 if (cmp > 0)
151 return true;
152 if (cmp < 0)
153 return false;
154
155 // Otherwise, sort based on latency estimate.
156 return a->rtt() < b->rtt();
157
158 // Should we bother checking for the last connection that last received
159 // data? It would help rendezvous on the connection that is also receiving
160 // packets.
161 //
162 // TODO: Yes we should definitely do this. The TCP protocol gains
163 // efficiency by being used bidirectionally, as opposed to two separate
164 // unidirectional streams. This test should probably occur before
165 // comparison of local prefs (assuming combined prefs are the same). We
166 // need to be careful though, not to bounce back and forth with both sides
167 // trying to rendevous with the other.
168 }
169 };
170
171 // Determines whether we should switch between two connections, based first on
172 // connection states, static preferences, and then (if those are equal) on
173 // latency estimates.
174 bool ShouldSwitch(cricket::Connection* a_conn,
175 cricket::Connection* b_conn,
176 cricket::IceRole ice_role) {
177 if (a_conn == b_conn)
178 return false;
179
180 if (!a_conn || !b_conn) // don't think the latter should happen
181 return true;
182
183 // We prefer to switch to a writable and receiving connection over a
184 // non-writable or non-receiving connection, even if the latter has
185 // been nominated by the controlling side.
186 int state_cmp = CompareConnectionStates(a_conn, b_conn);
187 if (state_cmp != 0) {
188 return state_cmp < 0;
189 }
190 if (ice_role == cricket::ICEROLE_CONTROLLED && a_conn->nominated()) {
191 LOG(LS_VERBOSE) << "Controlled side did not switch due to nominated status";
192 return false;
193 }
194
195 int prefs_cmp = CompareConnectionCandidates(a_conn, b_conn);
196 if (prefs_cmp != 0) {
197 return prefs_cmp < 0;
198 }
199
200 return b_conn->rtt() <= a_conn->rtt() + kMinImprovement;
201 }
202
203 } // unnamed namespace 63 } // unnamed namespace
204 64
205 namespace cricket { 65 namespace cricket {
206 66
207 // When the socket is unwritable, we will use 10 Kbps (ignoring IP+UDP headers) 67 // When the socket is unwritable, we will use 10 Kbps (ignoring IP+UDP headers)
208 // for pinging. When the socket is writable, we will use only 1 Kbps because 68 // for pinging. When the socket is writable, we will use only 1 Kbps because
209 // we don't want to degrade the quality on a modem. These numbers should work 69 // we don't want to degrade the quality on a modem. These numbers should work
210 // well on a 28.8K modem, which is the slowest connection on which the voice 70 // well on a 28.8K modem, which is the slowest connection on which the voice
211 // quality is reasonable at all. 71 // quality is reasonable at all.
212 static const int PING_PACKET_SIZE = 60 * 8; 72 static const int PING_PACKET_SIZE = 60 * 8;
(...skipping 30 matching lines...) Expand all
243 sort_dirty_(false), 103 sort_dirty_(false),
244 remote_ice_mode_(ICEMODE_FULL), 104 remote_ice_mode_(ICEMODE_FULL),
245 ice_role_(ICEROLE_UNKNOWN), 105 ice_role_(ICEROLE_UNKNOWN),
246 tiebreaker_(0), 106 tiebreaker_(0),
247 gathering_state_(kIceGatheringNew), 107 gathering_state_(kIceGatheringNew),
248 check_receiving_interval_(MIN_CHECK_RECEIVING_INTERVAL * 5), 108 check_receiving_interval_(MIN_CHECK_RECEIVING_INTERVAL * 5),
249 config_(MIN_CHECK_RECEIVING_INTERVAL * 50 /* receiving_timeout */, 109 config_(MIN_CHECK_RECEIVING_INTERVAL * 50 /* receiving_timeout */,
250 0 /* backup_connection_ping_interval */, 110 0 /* backup_connection_ping_interval */,
251 false /* gather_continually */, 111 false /* gather_continually */,
252 false /* prioritize_most_likely_candidate_pairs */, 112 false /* prioritize_most_likely_candidate_pairs */,
253 MAX_CURRENT_STRONG_INTERVAL /* max_strong_interval */) { 113 MAX_CURRENT_STRONG_INTERVAL /* max_strong_interval */,
114 true /* turn_to_turn_createpermission_needed */) {
254 uint32_t weak_ping_interval = ::strtoul( 115 uint32_t weak_ping_interval = ::strtoul(
255 webrtc::field_trial::FindFullName("WebRTC-StunInterPacketDelay").c_str(), 116 webrtc::field_trial::FindFullName("WebRTC-StunInterPacketDelay").c_str(),
256 nullptr, 10); 117 nullptr, 10);
257 if (weak_ping_interval) { 118 if (weak_ping_interval) {
258 weak_ping_interval_ = static_cast<int>(weak_ping_interval); 119 weak_ping_interval_ = static_cast<int>(weak_ping_interval);
259 } 120 }
260 } 121 }
261 122
262 P2PTransportChannel::~P2PTransportChannel() { 123 P2PTransportChannel::~P2PTransportChannel() {
263 ASSERT(worker_thread_ == rtc::Thread::Current()); 124 ASSERT(worker_thread_ == rtc::Thread::Current());
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 config.prioritize_most_likely_candidate_pairs; 292 config.prioritize_most_likely_candidate_pairs;
432 LOG(LS_INFO) << "Set ping most likely connection to " 293 LOG(LS_INFO) << "Set ping most likely connection to "
433 << config_.prioritize_most_likely_candidate_pairs; 294 << config_.prioritize_most_likely_candidate_pairs;
434 295
435 if (config.max_strong_interval >= 0 && 296 if (config.max_strong_interval >= 0 &&
436 config_.max_strong_interval != config.max_strong_interval) { 297 config_.max_strong_interval != config.max_strong_interval) {
437 config_.max_strong_interval = config.max_strong_interval; 298 config_.max_strong_interval = config.max_strong_interval;
438 LOG(LS_INFO) << "Set max strong interval to " 299 LOG(LS_INFO) << "Set max strong interval to "
439 << config_.max_strong_interval; 300 << config_.max_strong_interval;
440 } 301 }
302
303 if (config.turn_to_turn_createpermission_needed !=
304 config_.turn_to_turn_createpermission_needed) {
305 if (!connections_.empty()) {
306 LOG(LS_ERROR) << "Trying to change TURN-TURN CreatePermission needed "
307 << "while connections already exist!";
308 } else {
309 config_.turn_to_turn_createpermission_needed =
310 config.turn_to_turn_createpermission_needed;
311 LOG(LS_INFO) << "Set TURN-TURN CreatePermission needed to "
312 << config_.turn_to_turn_createpermission_needed;
313 }
314 }
441 } 315 }
442 316
443 const IceConfig& P2PTransportChannel::config() const { 317 const IceConfig& P2PTransportChannel::config() const {
444 return config_; 318 return config_;
445 } 319 }
446 320
447 // Go into the state of processing candidates, and running in general 321 // Go into the state of processing candidates, and running in general
448 void P2PTransportChannel::Connect() { 322 void P2PTransportChannel::Connect() {
449 ASSERT(worker_thread_ == rtc::Thread::Current()); 323 ASSERT(worker_thread_ == rtc::Thread::Current());
450 if (ice_ufrag_.empty() || ice_pwd_.empty()) { 324 if (ice_ufrag_.empty() || ice_pwd_.empty()) {
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 } 930 }
1057 931
1058 // Prepare for best candidate sorting. 932 // Prepare for best candidate sorting.
1059 void P2PTransportChannel::RequestSort() { 933 void P2PTransportChannel::RequestSort() {
1060 if (!sort_dirty_) { 934 if (!sort_dirty_) {
1061 worker_thread_->Post(RTC_FROM_HERE, this, MSG_SORT); 935 worker_thread_->Post(RTC_FROM_HERE, this, MSG_SORT);
1062 sort_dirty_ = true; 936 sort_dirty_ = true;
1063 } 937 }
1064 } 938 }
1065 939
940 int P2PTransportChannel::MappedWriteState(const cricket::Connection* a) const {
941 switch (a->write_state()) {
942 case Connection::STATE_WRITABLE:
943 return MAPPED_WRITE_STATE_WRITABLE;
944 case Connection::STATE_WRITE_UNRELIABLE:
945 return MAPPED_WRITE_STATE_UNRELIABLE;
946 case Connection::STATE_WRITE_INIT:
947 // If the connection hasn't received a binding response, but it's a TURN-
948 // TURN connection and CreatePermission isn't needed, the connection is
949 // "probably writable" which is just a step below writable.
950 if (!config_.turn_to_turn_createpermission_needed && IsRelayRelay(a)) {
951 return MAPPED_WRITE_STATE_PROBABLY_WRITABLE;
952 }
953 return MAPPED_WRITE_STATE_INIT;
954 case Connection::STATE_WRITE_TIMEOUT:
955 return MAPPED_WRITE_STATE_TIMEOUT;
956 default:
957 RTC_DCHECK(false);
958 return MAPPED_WRITE_STATE_TIMEOUT;
959 }
960 }
961
962 // Compare two connections based on their writing, receiving, and connected
963 // states.
964 int P2PTransportChannel::CompareConnectionStates(const Connection* a,
965 const Connection* b) const {
966 // Sort based on write-state. Better states have lower values.
967 if (MappedWriteState(a) < MappedWriteState(b))
968 return 1;
969 if (MappedWriteState(a) > MappedWriteState(b))
970 return -1;
Taylor Brandstetter 2016/06/14 22:25:27 This is the only difference from the previous vers
971
972 // We prefer a receiving connection to a non-receiving, higher-priority
973 // connection when sorting connections and choosing which connection to
974 // switch to.
975 if (a->receiving() && !b->receiving())
976 return 1;
977 if (!a->receiving() && b->receiving())
978 return -1;
979
980 // WARNING: Some complexity here about TCP reconnecting.
981 // When a TCP connection fails because of a TCP socket disconnecting, the
982 // active side of the connection will attempt to reconnect for 5 seconds while
983 // pretending to be writable (the connection is not set to the unwritable
984 // state). On the passive side, the connection also remains writable even
985 // though it is disconnected, and a new connection is created when the active
986 // side connects. At that point, there are two TCP connections on the passive
987 // side: 1. the old, disconnected one that is pretending to be writable, and
988 // 2. the new, connected one that is maybe not yet writable. For purposes of
989 // pruning, pinging, and selecting the best connection, we want to treat the
990 // new connection as "better" than the old one. We could add a method called
991 // something like Connection::ImReallyBadEvenThoughImWritable, but that is
992 // equivalent to the existing Connection::connected(), which we already have.
993 // So, in code throughout this file, we'll check whether the connection is
994 // connected() or not, and if it is not, treat it as "worse" than a connected
995 // one, even though it's writable. In the code below, we're doing so to make
996 // sure we treat a new writable connection as better than an old disconnected
997 // connection.
998
999 // In the case where we reconnect TCP connections, the original best
1000 // connection is disconnected without changing to WRITE_TIMEOUT. In this case,
1001 // the new connection, when it becomes writable, should have higher priority.
1002 if (a->write_state() == Connection::STATE_WRITABLE &&
1003 b->write_state() == Connection::STATE_WRITABLE) {
1004 if (a->connected() && !b->connected()) {
1005 return 1;
1006 }
1007 if (!a->connected() && b->connected()) {
1008 return -1;
1009 }
1010 }
1011 return 0;
1012 }
1013
1014 // Compares two connections based only on the candidate and network information.
1015 // Returns positive if |a| is better than |b|.
1016 int P2PTransportChannel::CompareConnectionCandidates(
1017 const Connection* a,
1018 const Connection* b) const {
1019 uint32_t a_cost = a->ComputeNetworkCost();
1020 uint32_t b_cost = b->ComputeNetworkCost();
1021 // Smaller cost is better.
1022 if (a_cost < b_cost) {
1023 return 1;
1024 }
1025 if (a_cost > b_cost) {
1026 return -1;
1027 }
1028
1029 // Compare connection priority. Lower values get sorted last.
1030 if (a->priority() > b->priority())
1031 return 1;
1032 if (a->priority() < b->priority())
1033 return -1;
1034
1035 // If we're still tied at this point, prefer a younger generation.
1036 return (a->remote_candidate().generation() + a->port()->generation()) -
1037 (b->remote_candidate().generation() + b->port()->generation());
1038 }
1039
1040 int P2PTransportChannel::CompareConnections(const Connection* a,
1041 const Connection* b) const {
1042 // Compare first on writability and static preferences.
1043 int state_cmp = CompareConnectionStates(a, b);
1044 if (state_cmp != 0) {
1045 return state_cmp;
1046 }
1047 // Then compare the candidate information.
1048 int candidates_cmp = CompareConnectionCandidates(a, b);
1049 if (candidates_cmp != 0) {
1050 return candidates_cmp;
1051 }
1052 // Otherwise, compare based on latency estimate.
1053 return b->rtt() - a->rtt();
1054
1055 // Should we bother checking for the last connection that last received
1056 // data? It would help rendezvous on the connection that is also receiving
1057 // packets.
1058 //
1059 // TODO(deadbeef): Yes we should definitely do this. The TCP protocol gains
1060 // efficiency by being used bidirectionally, as opposed to two separate
1061 // unidirectional streams. This test should probably occur before
1062 // comparison of local prefs (assuming combined prefs are the same). We
1063 // need to be careful though, not to bounce back and forth with both sides
1064 // trying to rendevous with the other.
1065 }
1066
1067 // Determines whether we should switch between two connections, based first on
1068 // connection states, static preferences, and then (if those are equal) on
1069 // latency estimates.
1070 bool P2PTransportChannel::ShouldSwitch(const Connection* a,
1071 const Connection* b) const {
1072 if (a == b)
1073 return false;
1074
1075 if (!a || !b) // don't think the latter should happen
1076 return true;
1077
1078 // We prefer to switch to a writable and receiving connection over a
1079 // non-writable or non-receiving connection, even if the latter has
1080 // been nominated by the controlling side.
1081 int state_cmp = CompareConnectionStates(a, b);
1082 if (state_cmp != 0) {
1083 return state_cmp < 0;
1084 }
1085 if (ice_role_ == ICEROLE_CONTROLLED && a->nominated()) {
1086 LOG(LS_VERBOSE) << "Controlled side did not switch due to nominated status";
1087 return false;
1088 }
1089
1090 int prefs_cmp = CompareConnectionCandidates(a, b);
1091 if (prefs_cmp != 0) {
1092 return prefs_cmp < 0;
1093 }
1094
1095 return b->rtt() <= a->rtt() + kMinImprovement;
1096 }
1097
1066 // Sort the available connections to find the best one. We also monitor 1098 // Sort the available connections to find the best one. We also monitor
1067 // the number of available connections and the current state. 1099 // the number of available connections and the current state.
1068 void P2PTransportChannel::SortConnections() { 1100 void P2PTransportChannel::SortConnections() {
1069 ASSERT(worker_thread_ == rtc::Thread::Current()); 1101 ASSERT(worker_thread_ == rtc::Thread::Current());
1070 1102
1071 // Make sure the connection states are up-to-date since this affects how they 1103 // Make sure the connection states are up-to-date since this affects how they
1072 // will be sorted. 1104 // will be sorted.
1073 UpdateConnectionStates(); 1105 UpdateConnectionStates();
1074 1106
1075 // Any changes after this point will require a re-sort. 1107 // Any changes after this point will require a re-sort.
1076 sort_dirty_ = false; 1108 sort_dirty_ = false;
1077 1109
1078 // Find the best alternative connection by sorting. It is important to note 1110 // Find the best alternative connection by sorting. It is important to note
1079 // that amongst equal preference, writable connections, this will choose the 1111 // that amongst equal preference, writable connections, this will choose the
1080 // one whose estimated latency is lowest. So it is the only one that we 1112 // one whose estimated latency is lowest. So it is the only one that we
1081 // need to consider switching to. 1113 // need to consider switching to.
1082 ConnectionCompare cmp; 1114 std::stable_sort(connections_.begin(), connections_.end(),
1083 std::stable_sort(connections_.begin(), connections_.end(), cmp); 1115 [this](const Connection* a, const Connection* b) {
1116 return CompareConnections(a, b) > 0;
1117 });
1084 LOG(LS_VERBOSE) << "Sorting " << connections_.size() 1118 LOG(LS_VERBOSE) << "Sorting " << connections_.size()
1085 << " available connections:"; 1119 << " available connections:";
1086 for (size_t i = 0; i < connections_.size(); ++i) { 1120 for (size_t i = 0; i < connections_.size(); ++i) {
1087 LOG(LS_VERBOSE) << connections_[i]->ToString(); 1121 LOG(LS_VERBOSE) << connections_[i]->ToString();
1088 } 1122 }
1089 1123
1090 Connection* top_connection = 1124 Connection* top_connection =
1091 (connections_.size() > 0) ? connections_[0] : nullptr; 1125 (connections_.size() > 0) ? connections_[0] : nullptr;
1092 1126
1093 // If necessary, switch to the new choice. 1127 // If necessary, switch to the new choice.
1094 // Note that |top_connection| doesn't have to be writable to become the best 1128 // Note that |top_connection| doesn't have to be writable to become the best
1095 // connection although it will have higher priority if it is writable. 1129 // connection although it will have higher priority if it is writable.
1096 if (ShouldSwitch(best_connection_, top_connection, ice_role_)) { 1130 if (ShouldSwitch(best_connection_, top_connection)) {
1097 LOG(LS_INFO) << "Switching best connection: " << top_connection->ToString(); 1131 LOG(LS_INFO) << "Switching best connection: " << top_connection->ToString();
1098 SwitchBestConnectionTo(top_connection); 1132 SwitchBestConnectionTo(top_connection);
1099 } 1133 }
1100 1134
1101 // Controlled side can prune only if the best connection has been nominated. 1135 // Controlled side can prune only if the best connection has been nominated.
1102 // because otherwise it may delete the connection that will be selected by 1136 // because otherwise it may delete the connection that will be selected by
1103 // the controlling side. 1137 // the controlling side.
1104 if (ice_role_ == ICEROLE_CONTROLLING || best_nominated_connection()) { 1138 if (ice_role_ == ICEROLE_CONTROLLING || best_nominated_connection()) {
1105 PruneConnections(); 1139 PruneConnections();
1106 } 1140 }
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1230 RTC_DCHECK(state == STATE_CONNECTING || state == STATE_COMPLETED); 1264 RTC_DCHECK(state == STATE_CONNECTING || state == STATE_COMPLETED);
1231 break; 1265 break;
1232 default: 1266 default:
1233 RTC_DCHECK(false); 1267 RTC_DCHECK(false);
1234 break; 1268 break;
1235 } 1269 }
1236 state_ = state; 1270 state_ = state;
1237 SignalStateChanged(this); 1271 SignalStateChanged(this);
1238 } 1272 }
1239 1273
1240 bool writable = best_connection_ && best_connection_->writable(); 1274 // If our best connection is "probably writable" (TURN-TURN with no
1275 // CreatePermission required), act like we're already writable to the upper
1276 // layers, so they can start media quicker.
1277 bool writable =
1278 best_connection_ &&
1279 (MappedWriteState(best_connection_) == MAPPED_WRITE_STATE_WRITABLE ||
1280 MappedWriteState(best_connection_) ==
1281 MAPPED_WRITE_STATE_PROBABLY_WRITABLE);
1241 set_writable(writable); 1282 set_writable(writable);
1242 1283
1243 bool receiving = false; 1284 bool receiving = false;
1244 for (const Connection* connection : connections_) { 1285 for (const Connection* connection : connections_) {
1245 if (connection->receiving()) { 1286 if (connection->receiving()) {
1246 receiving = true; 1287 receiving = true;
1247 break; 1288 break;
1248 } 1289 }
1249 } 1290 }
1250 set_receiving(receiving); 1291 set_receiving(receiving);
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1688 1729
1689 // During the initial state when nothing has been pinged yet, return the first 1730 // During the initial state when nothing has been pinged yet, return the first
1690 // one in the ordered |connections_|. 1731 // one in the ordered |connections_|.
1691 return *(std::find_if(connections_.begin(), connections_.end(), 1732 return *(std::find_if(connections_.begin(), connections_.end(),
1692 [conn1, conn2](Connection* conn) { 1733 [conn1, conn2](Connection* conn) {
1693 return conn == conn1 || conn == conn2; 1734 return conn == conn1 || conn == conn2;
1694 })); 1735 }));
1695 } 1736 }
1696 1737
1697 } // namespace cricket 1738 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698