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

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: Improving code readability. 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
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.h ('k') | webrtc/p2p/base/p2ptransportchannel_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 14 matching lines...) Expand all
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 // The minimum improvement in RTT that justifies a switch. 32 // The minimum improvement in RTT that justifies a switch.
33 static const double kMinImprovement = 10; 33 static const double kMinImprovement = 10;
34 34
35 bool IsRelayRelay(cricket::Connection* conn) { 35 bool IsRelayRelay(const cricket::Connection* conn) {
36 return conn->local_candidate().type() == cricket::RELAY_PORT_TYPE && 36 return conn->local_candidate().type() == cricket::RELAY_PORT_TYPE &&
37 conn->remote_candidate().type() == cricket::RELAY_PORT_TYPE; 37 conn->remote_candidate().type() == cricket::RELAY_PORT_TYPE;
38 } 38 }
39 39
40 bool IsUdp(cricket::Connection* conn) { 40 bool IsUdp(cricket::Connection* conn) {
41 return conn->local_candidate().relay_protocol() == cricket::UDP_PROTOCOL_NAME; 41 return conn->local_candidate().relay_protocol() == cricket::UDP_PROTOCOL_NAME;
42 } 42 }
43 43
44 cricket::PortInterface::CandidateOrigin GetOrigin(cricket::PortInterface* port, 44 cricket::PortInterface::CandidateOrigin GetOrigin(cricket::PortInterface* port,
45 cricket::PortInterface* origin_port) { 45 cricket::PortInterface* origin_port) {
46 if (!origin_port) 46 if (!origin_port)
47 return cricket::PortInterface::ORIGIN_MESSAGE; 47 return cricket::PortInterface::ORIGIN_MESSAGE;
48 else if (port == origin_port) 48 else if (port == origin_port)
49 return cricket::PortInterface::ORIGIN_THIS_PORT; 49 return cricket::PortInterface::ORIGIN_THIS_PORT;
50 else 50 else
51 return cricket::PortInterface::ORIGIN_OTHER_PORT; 51 return cricket::PortInterface::ORIGIN_OTHER_PORT;
52 } 52 }
53 53
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 54 } // unnamed namespace
204 55
205 namespace cricket { 56 namespace cricket {
206 57
207 // When the socket is unwritable, we will use 10 Kbps (ignoring IP+UDP headers) 58 // 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 59 // 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 60 // 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 61 // well on a 28.8K modem, which is the slowest connection on which the voice
211 // quality is reasonable at all. 62 // quality is reasonable at all.
212 static const int PING_PACKET_SIZE = 60 * 8; 63 static const int PING_PACKET_SIZE = 60 * 8;
(...skipping 30 matching lines...) Expand all
243 sort_dirty_(false), 94 sort_dirty_(false),
244 remote_ice_mode_(ICEMODE_FULL), 95 remote_ice_mode_(ICEMODE_FULL),
245 ice_role_(ICEROLE_UNKNOWN), 96 ice_role_(ICEROLE_UNKNOWN),
246 tiebreaker_(0), 97 tiebreaker_(0),
247 gathering_state_(kIceGatheringNew), 98 gathering_state_(kIceGatheringNew),
248 check_receiving_interval_(MIN_CHECK_RECEIVING_INTERVAL * 5), 99 check_receiving_interval_(MIN_CHECK_RECEIVING_INTERVAL * 5),
249 config_(MIN_CHECK_RECEIVING_INTERVAL * 50 /* receiving_timeout */, 100 config_(MIN_CHECK_RECEIVING_INTERVAL * 50 /* receiving_timeout */,
250 0 /* backup_connection_ping_interval */, 101 0 /* backup_connection_ping_interval */,
251 false /* gather_continually */, 102 false /* gather_continually */,
252 false /* prioritize_most_likely_candidate_pairs */, 103 false /* prioritize_most_likely_candidate_pairs */,
253 MAX_CURRENT_STRONG_INTERVAL /* max_strong_interval */) { 104 MAX_CURRENT_STRONG_INTERVAL /* max_strong_interval */,
105 true /* presume_writable_when_fully_relayed */) {
254 uint32_t weak_ping_interval = ::strtoul( 106 uint32_t weak_ping_interval = ::strtoul(
255 webrtc::field_trial::FindFullName("WebRTC-StunInterPacketDelay").c_str(), 107 webrtc::field_trial::FindFullName("WebRTC-StunInterPacketDelay").c_str(),
256 nullptr, 10); 108 nullptr, 10);
257 if (weak_ping_interval) { 109 if (weak_ping_interval) {
258 weak_ping_interval_ = static_cast<int>(weak_ping_interval); 110 weak_ping_interval_ = static_cast<int>(weak_ping_interval);
259 } 111 }
260 } 112 }
261 113
262 P2PTransportChannel::~P2PTransportChannel() { 114 P2PTransportChannel::~P2PTransportChannel() {
263 ASSERT(worker_thread_ == rtc::Thread::Current()); 115 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; 283 config.prioritize_most_likely_candidate_pairs;
432 LOG(LS_INFO) << "Set ping most likely connection to " 284 LOG(LS_INFO) << "Set ping most likely connection to "
433 << config_.prioritize_most_likely_candidate_pairs; 285 << config_.prioritize_most_likely_candidate_pairs;
434 286
435 if (config.max_strong_interval >= 0 && 287 if (config.max_strong_interval >= 0 &&
436 config_.max_strong_interval != config.max_strong_interval) { 288 config_.max_strong_interval != config.max_strong_interval) {
437 config_.max_strong_interval = config.max_strong_interval; 289 config_.max_strong_interval = config.max_strong_interval;
438 LOG(LS_INFO) << "Set max strong interval to " 290 LOG(LS_INFO) << "Set max strong interval to "
439 << config_.max_strong_interval; 291 << config_.max_strong_interval;
440 } 292 }
293
294 if (config.presume_writable_when_fully_relayed !=
295 config_.presume_writable_when_fully_relayed) {
296 if (!connections_.empty()) {
297 LOG(LS_ERROR) << "Trying to change 'presume writable' "
298 << "while connections already exist!";
299 } else {
300 config_.presume_writable_when_fully_relayed =
301 config.presume_writable_when_fully_relayed;
302 LOG(LS_INFO) << "Set presume writable when fully relayed to "
303 << config_.presume_writable_when_fully_relayed;
304 }
305 }
441 } 306 }
442 307
443 const IceConfig& P2PTransportChannel::config() const { 308 const IceConfig& P2PTransportChannel::config() const {
444 return config_; 309 return config_;
445 } 310 }
446 311
447 // Go into the state of processing candidates, and running in general 312 // Go into the state of processing candidates, and running in general
448 void P2PTransportChannel::Connect() { 313 void P2PTransportChannel::Connect() {
449 ASSERT(worker_thread_ == rtc::Thread::Current()); 314 ASSERT(worker_thread_ == rtc::Thread::Current());
450 if (ice_ufrag_.empty() || ice_pwd_.empty()) { 315 if (ice_ufrag_.empty() || ice_pwd_.empty()) {
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 } 921 }
1057 922
1058 // Prepare for best candidate sorting. 923 // Prepare for best candidate sorting.
1059 void P2PTransportChannel::RequestSort() { 924 void P2PTransportChannel::RequestSort() {
1060 if (!sort_dirty_) { 925 if (!sort_dirty_) {
1061 worker_thread_->Post(RTC_FROM_HERE, this, MSG_SORT); 926 worker_thread_->Post(RTC_FROM_HERE, this, MSG_SORT);
1062 sort_dirty_ = true; 927 sort_dirty_ = true;
1063 } 928 }
1064 } 929 }
1065 930
931 // Compare two connections based on their writing, receiving, and connected
932 // states.
933 int P2PTransportChannel::CompareConnectionStates(const Connection* a,
934 const Connection* b) const {
935 static constexpr int a_is_better = 1;
936 static constexpr int b_is_better = -1;
937 // Sort based on write-state. Better states have lower values.
938 if (a->write_state() < b->write_state()) {
939 return a_is_better;
940 }
941 if (b->write_state() < a->write_state()) {
honghaiz3 2016/06/22 16:48:01 I am not sure if this is the right behavior. A tu
Taylor Brandstetter 2016/06/22 17:15:46 You're right, I think that's what I was initially
pthatcher1 2016/06/22 17:20:19 Good catch. Should we have a unit test that catch
942 return b_is_better;
943 }
944
945 bool a_presumed_writable = PresumedWritable(a);
946 bool b_presumed_writable = PresumedWritable(b);
947 if (a_presumed_writable && !b_presumed_writable) {
948 return a_is_better;
949 }
950 if (!a_presumed_writable && b_presumed_writable) {
951 return b_is_better;
952 }
953
954 // We prefer a receiving connection to a non-receiving, higher-priority
955 // connection when sorting connections and choosing which connection to
956 // switch to.
957 if (a->receiving() && !b->receiving()) {
958 return a_is_better;
959 }
960 if (!a->receiving() && b->receiving()) {
961 return b_is_better;
962 }
963
964 // WARNING: Some complexity here about TCP reconnecting.
965 // When a TCP connection fails because of a TCP socket disconnecting, the
966 // active side of the connection will attempt to reconnect for 5 seconds while
967 // pretending to be writable (the connection is not set to the unwritable
968 // state). On the passive side, the connection also remains writable even
969 // though it is disconnected, and a new connection is created when the active
970 // side connects. At that point, there are two TCP connections on the passive
971 // side: 1. the old, disconnected one that is pretending to be writable, and
972 // 2. the new, connected one that is maybe not yet writable. For purposes of
973 // pruning, pinging, and selecting the best connection, we want to treat the
974 // new connection as "better" than the old one. We could add a method called
975 // something like Connection::ImReallyBadEvenThoughImWritable, but that is
976 // equivalent to the existing Connection::connected(), which we already have.
977 // So, in code throughout this file, we'll check whether the connection is
978 // connected() or not, and if it is not, treat it as "worse" than a connected
979 // one, even though it's writable. In the code below, we're doing so to make
980 // sure we treat a new writable connection as better than an old disconnected
981 // connection.
982
983 // In the case where we reconnect TCP connections, the original best
984 // connection is disconnected without changing to WRITE_TIMEOUT. In this case,
985 // the new connection, when it becomes writable, should have higher priority.
986 if (a->write_state() == Connection::STATE_WRITABLE &&
987 b->write_state() == Connection::STATE_WRITABLE) {
988 if (a->connected() && !b->connected()) {
989 return a_is_better;
990 }
991 if (!a->connected() && b->connected()) {
992 return b_is_better;
993 }
994 }
995 return 0;
996 }
997
998 // Compares two connections based only on the candidate and network information.
999 // Returns positive if |a| is better than |b|.
1000 int P2PTransportChannel::CompareConnectionCandidates(
1001 const Connection* a,
1002 const Connection* b) const {
1003 // Prefer lower network cost.
1004 uint32_t a_cost = a->ComputeNetworkCost();
1005 uint32_t b_cost = b->ComputeNetworkCost();
1006 // Smaller cost is better.
1007 if (a_cost < b_cost) {
1008 return 1;
1009 }
1010 if (a_cost > b_cost) {
1011 return -1;
1012 }
1013
1014 // Compare connection priority. Lower values get sorted last.
1015 if (a->priority() > b->priority()) {
1016 return 1;
1017 }
1018 if (a->priority() < b->priority()) {
1019 return -1;
1020 }
1021
1022 // If we're still tied at this point, prefer a younger generation.
1023 // (Younger generation means a larger generation number).
1024 return (a->remote_candidate().generation() + a->port()->generation()) -
1025 (b->remote_candidate().generation() + b->port()->generation());
1026 }
1027
1028 int P2PTransportChannel::CompareConnections(const Connection* a,
1029 const Connection* b) const {
1030 // Compare first on writability and static preferences.
1031 int state_cmp = CompareConnectionStates(a, b);
1032 if (state_cmp != 0) {
1033 return state_cmp;
1034 }
1035 // Then compare the candidate information.
1036 int candidates_cmp = CompareConnectionCandidates(a, b);
1037 if (candidates_cmp != 0) {
1038 return candidates_cmp;
1039 }
1040 // Otherwise, compare based on latency estimate.
1041 return b->rtt() - a->rtt();
1042
1043 // Should we bother checking for the last connection that last received
1044 // data? It would help rendezvous on the connection that is also receiving
1045 // packets.
1046 //
1047 // TODO(deadbeef): Yes we should definitely do this. The TCP protocol gains
1048 // efficiency by being used bidirectionally, as opposed to two separate
1049 // unidirectional streams. This test should probably occur before
1050 // comparison of local prefs (assuming combined prefs are the same). We
1051 // need to be careful though, not to bounce back and forth with both sides
1052 // trying to rendevous with the other.
1053 }
1054
1055 bool P2PTransportChannel::PresumedWritable(
1056 const cricket::Connection* conn) const {
1057 return (conn->write_state() == Connection::STATE_WRITE_INIT &&
1058 config_.presume_writable_when_fully_relayed &&
1059 conn->local_candidate().type() == RELAY_PORT_TYPE &&
1060 (conn->remote_candidate().type() == RELAY_PORT_TYPE ||
1061 conn->remote_candidate().type() == PRFLX_PORT_TYPE));
1062 }
1063
1064 // Determines whether we should switch between two connections, based first on
1065 // connection states, static preferences, and then (if those are equal) on
1066 // latency estimates.
1067 bool P2PTransportChannel::ShouldSwitchSelectedConnection(
1068 const Connection* selected,
1069 const Connection* conn) const {
1070 if (selected == conn) {
1071 return false;
1072 }
1073
1074 if (!selected || !conn) { // don't think the latter should happen
1075 return true;
1076 }
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(selected, conn);
1082 if (state_cmp != 0) {
1083 return state_cmp < 0;
1084 }
1085 if (ice_role_ == ICEROLE_CONTROLLED && selected->nominated()) {
1086 LOG(LS_VERBOSE) << "Controlled side did not switch due to nominated status";
1087 return false;
1088 }
1089
1090 int prefs_cmp = CompareConnectionCandidates(selected, conn);
1091 if (prefs_cmp != 0) {
1092 return prefs_cmp < 0;
1093 }
1094
1095 return selected->rtt() - conn->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 (ShouldSwitchSelectedConnection(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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 << old_best_connection->ToString(); 1209 << old_best_connection->ToString();
1176 } 1210 }
1177 LOG_J(LS_INFO, this) << "New best connection: " 1211 LOG_J(LS_INFO, this) << "New best connection: "
1178 << best_connection_->ToString(); 1212 << best_connection_->ToString();
1179 SignalRouteChange(this, best_connection_->remote_candidate()); 1213 SignalRouteChange(this, best_connection_->remote_candidate());
1180 // This is a temporary, but safe fix to webrtc issue 5705. 1214 // This is a temporary, but safe fix to webrtc issue 5705.
1181 // TODO(honghaiz): Make all EWOULDBLOCK error routed through the transport 1215 // TODO(honghaiz): Make all EWOULDBLOCK error routed through the transport
1182 // channel so that it knows whether the media channel is allowed to 1216 // channel so that it knows whether the media channel is allowed to
1183 // send; then it will only signal ready-to-send if the media channel 1217 // send; then it will only signal ready-to-send if the media channel
1184 // has been disallowed to send. 1218 // has been disallowed to send.
1185 if (best_connection_->writable()) { 1219 if (best_connection_->writable() || PresumedWritable(best_connection_)) {
1186 SignalReadyToSend(this); 1220 SignalReadyToSend(this);
1187 } 1221 }
1188 } else { 1222 } else {
1189 LOG_J(LS_INFO, this) << "No best connection"; 1223 LOG_J(LS_INFO, this) << "No best connection";
1190 } 1224 }
1191 // TODO(honghaiz): rename best_connection_ with selected_connection_ or 1225 // TODO(honghaiz): rename best_connection_ with selected_connection_ or
1192 // selected_candidate pair_. 1226 // selected_candidate pair_.
1193 SignalSelectedCandidatePairChanged(this, best_connection_, 1227 SignalSelectedCandidatePairChanged(this, best_connection_,
1194 last_sent_packet_id_); 1228 last_sent_packet_id_);
1195 } 1229 }
(...skipping 34 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 "presumed writable" (TURN-TURN with no
1241 set_writable(writable); 1275 // CreatePermission required), act like we're already writable to the upper
1276 // layers, so they can start media quicker.
1277 set_writable(best_connection_ && (best_connection_->writable() ||
1278 PresumedWritable(best_connection_)));
1242 1279
1243 bool receiving = false; 1280 bool receiving = false;
1244 for (const Connection* connection : connections_) { 1281 for (const Connection* connection : connections_) {
1245 if (connection->receiving()) { 1282 if (connection->receiving()) {
1246 receiving = true; 1283 receiving = true;
1247 break; 1284 break;
1248 } 1285 }
1249 } 1286 }
1250 set_receiving(receiving); 1287 set_receiving(receiving);
1251 } 1288 }
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
1688 1725
1689 // During the initial state when nothing has been pinged yet, return the first 1726 // During the initial state when nothing has been pinged yet, return the first
1690 // one in the ordered |connections_|. 1727 // one in the ordered |connections_|.
1691 return *(std::find_if(connections_.begin(), connections_.end(), 1728 return *(std::find_if(connections_.begin(), connections_.end(),
1692 [conn1, conn2](Connection* conn) { 1729 [conn1, conn2](Connection* conn) {
1693 return conn == conn1 || conn == conn2; 1730 return conn == conn1 || conn == conn2;
1694 })); 1731 }));
1695 } 1732 }
1696 1733
1697 } // namespace cricket 1734 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.h ('k') | webrtc/p2p/base/p2ptransportchannel_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698