| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 MSG_CONFIG_READY, | 36 MSG_CONFIG_READY, |
| 37 MSG_ALLOCATE, | 37 MSG_ALLOCATE, |
| 38 MSG_ALLOCATION_PHASE, | 38 MSG_ALLOCATION_PHASE, |
| 39 MSG_SEQUENCEOBJECTS_CREATED, | 39 MSG_SEQUENCEOBJECTS_CREATED, |
| 40 MSG_CONFIG_STOP, | 40 MSG_CONFIG_STOP, |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 const int PHASE_UDP = 0; | 43 const int PHASE_UDP = 0; |
| 44 const int PHASE_RELAY = 1; | 44 const int PHASE_RELAY = 1; |
| 45 const int PHASE_TCP = 2; | 45 const int PHASE_TCP = 2; |
| 46 const int PHASE_SSLTCP = 3; | |
| 47 | 46 |
| 48 const int kNumPhases = 4; | 47 const int kNumPhases = 3; |
| 49 | 48 |
| 50 // Gets protocol priority: UDP > TCP > SSLTCP == TLS. | 49 // Gets protocol priority: UDP > TCP > SSLTCP == TLS. |
| 51 int GetProtocolPriority(cricket::ProtocolType protocol) { | 50 int GetProtocolPriority(cricket::ProtocolType protocol) { |
| 52 switch (protocol) { | 51 switch (protocol) { |
| 53 case cricket::PROTO_UDP: | 52 case cricket::PROTO_UDP: |
| 54 return 2; | 53 return 2; |
| 55 case cricket::PROTO_TCP: | 54 case cricket::PROTO_TCP: |
| 56 return 1; | 55 return 1; |
| 57 case cricket::PROTO_SSLTCP: | 56 case cricket::PROTO_SSLTCP: |
| 58 case cricket::PROTO_TLS: | 57 case cricket::PROTO_TLS: |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 } | 400 } |
| 402 | 401 |
| 403 void BasicPortAllocatorSession::GetCandidatesFromPort( | 402 void BasicPortAllocatorSession::GetCandidatesFromPort( |
| 404 const PortData& data, | 403 const PortData& data, |
| 405 std::vector<Candidate>* candidates) const { | 404 std::vector<Candidate>* candidates) const { |
| 406 RTC_CHECK(candidates != nullptr); | 405 RTC_CHECK(candidates != nullptr); |
| 407 for (const Candidate& candidate : data.port()->Candidates()) { | 406 for (const Candidate& candidate : data.port()->Candidates()) { |
| 408 if (!CheckCandidateFilter(candidate)) { | 407 if (!CheckCandidateFilter(candidate)) { |
| 409 continue; | 408 continue; |
| 410 } | 409 } |
| 411 ProtocolType pvalue; | |
| 412 if (!StringToProto(candidate.protocol().c_str(), &pvalue) || | |
| 413 !data.sequence()->ProtocolEnabled(pvalue)) { | |
| 414 continue; | |
| 415 } | |
| 416 candidates->push_back(SanitizeRelatedAddress(candidate)); | 410 candidates->push_back(SanitizeRelatedAddress(candidate)); |
| 417 } | 411 } |
| 418 } | 412 } |
| 419 | 413 |
| 420 Candidate BasicPortAllocatorSession::SanitizeRelatedAddress( | 414 Candidate BasicPortAllocatorSession::SanitizeRelatedAddress( |
| 421 const Candidate& c) const { | 415 const Candidate& c) const { |
| 422 Candidate copy = c; | 416 Candidate copy = c; |
| 423 // If adapter enumeration is disabled or host candidates are disabled, | 417 // If adapter enumeration is disabled or host candidates are disabled, |
| 424 // clear the raddr of STUN candidates to avoid local address leakage. | 418 // clear the raddr of STUN candidates to avoid local address leakage. |
| 425 bool filter_stun_related_address = | 419 bool filter_stun_related_address = |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 pruned = PruneTurnPorts(port); | 804 pruned = PruneTurnPorts(port); |
| 811 } | 805 } |
| 812 // If the current port is not pruned yet, SignalPortReady. | 806 // If the current port is not pruned yet, SignalPortReady. |
| 813 if (!data->pruned()) { | 807 if (!data->pruned()) { |
| 814 LOG_J(LS_INFO, port) << "Port ready."; | 808 LOG_J(LS_INFO, port) << "Port ready."; |
| 815 SignalPortReady(this, port); | 809 SignalPortReady(this, port); |
| 816 port->KeepAliveUntilPruned(); | 810 port->KeepAliveUntilPruned(); |
| 817 } | 811 } |
| 818 } | 812 } |
| 819 | 813 |
| 820 ProtocolType pvalue; | 814 if (data->ready() && CheckCandidateFilter(c)) { |
| 821 bool candidate_protocol_enabled = | |
| 822 StringToProto(c.protocol().c_str(), &pvalue) && | |
| 823 data->sequence()->ProtocolEnabled(pvalue); | |
| 824 | |
| 825 if (data->ready() && CheckCandidateFilter(c) && candidate_protocol_enabled) { | |
| 826 std::vector<Candidate> candidates; | 815 std::vector<Candidate> candidates; |
| 827 candidates.push_back(SanitizeRelatedAddress(c)); | 816 candidates.push_back(SanitizeRelatedAddress(c)); |
| 828 SignalCandidatesReady(this, candidates); | 817 SignalCandidatesReady(this, candidates); |
| 829 } else if (!candidate_protocol_enabled) { | |
| 830 LOG(LS_INFO) | |
| 831 << "Not yet signaling candidate because protocol is not yet enabled."; | |
| 832 } else { | 818 } else { |
| 833 LOG(LS_INFO) << "Discarding candidate because it doesn't match filter."; | 819 LOG(LS_INFO) << "Discarding candidate because it doesn't match filter."; |
| 834 } | 820 } |
| 835 | 821 |
| 836 // If we have pruned any port, maybe need to signal port allocation done. | 822 // If we have pruned any port, maybe need to signal port allocation done. |
| 837 if (pruned) { | 823 if (pruned) { |
| 838 MaybeSignalCandidatesAllocationDone(); | 824 MaybeSignalCandidatesAllocationDone(); |
| 839 } | 825 } |
| 840 } | 826 } |
| 841 | 827 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 918 return; | 904 return; |
| 919 } | 905 } |
| 920 | 906 |
| 921 // SignalAddressError is currently sent from StunPort/TurnPort. | 907 // SignalAddressError is currently sent from StunPort/TurnPort. |
| 922 // But this signal itself is generic. | 908 // But this signal itself is generic. |
| 923 data->set_error(); | 909 data->set_error(); |
| 924 // Send candidate allocation complete signal if this was the last port. | 910 // Send candidate allocation complete signal if this was the last port. |
| 925 MaybeSignalCandidatesAllocationDone(); | 911 MaybeSignalCandidatesAllocationDone(); |
| 926 } | 912 } |
| 927 | 913 |
| 928 void BasicPortAllocatorSession::OnProtocolEnabled(AllocationSequence* seq, | |
| 929 ProtocolType proto) { | |
| 930 std::vector<Candidate> candidates; | |
| 931 for (std::vector<PortData>::iterator it = ports_.begin(); | |
| 932 it != ports_.end(); ++it) { | |
| 933 if (it->sequence() != seq) | |
| 934 continue; | |
| 935 | |
| 936 const std::vector<Candidate>& potentials = it->port()->Candidates(); | |
| 937 for (size_t i = 0; i < potentials.size(); ++i) { | |
| 938 if (!CheckCandidateFilter(potentials[i])) { | |
| 939 continue; | |
| 940 } | |
| 941 ProtocolType pvalue; | |
| 942 bool candidate_protocol_enabled = | |
| 943 StringToProto(potentials[i].protocol().c_str(), &pvalue) && | |
| 944 pvalue == proto; | |
| 945 if (candidate_protocol_enabled) { | |
| 946 LOG(LS_INFO) << "Signaling candidate because protocol was enabled: " | |
| 947 << potentials[i].ToSensitiveString(); | |
| 948 candidates.push_back(potentials[i]); | |
| 949 } | |
| 950 } | |
| 951 } | |
| 952 | |
| 953 if (!candidates.empty()) { | |
| 954 SignalCandidatesReady(this, candidates); | |
| 955 } | |
| 956 } | |
| 957 | |
| 958 bool BasicPortAllocatorSession::CheckCandidateFilter(const Candidate& c) const { | 914 bool BasicPortAllocatorSession::CheckCandidateFilter(const Candidate& c) const { |
| 959 uint32_t filter = candidate_filter_; | 915 uint32_t filter = candidate_filter_; |
| 960 | 916 |
| 961 // When binding to any address, before sending packets out, the getsockname | 917 // When binding to any address, before sending packets out, the getsockname |
| 962 // returns all 0s, but after sending packets, it'll be the NIC used to | 918 // returns all 0s, but after sending packets, it'll be the NIC used to |
| 963 // send. All 0s is not a valid ICE candidate address and should be filtered | 919 // send. All 0s is not a valid ICE candidate address and should be filtered |
| 964 // out. | 920 // out. |
| 965 if (c.address().IsAnyIP()) { | 921 if (c.address().IsAnyIP()) { |
| 966 return false; | 922 return false; |
| 967 } | 923 } |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1182 if (state_ == kRunning) { | 1138 if (state_ == kRunning) { |
| 1183 state_ = kStopped; | 1139 state_ = kStopped; |
| 1184 session_->network_thread()->Clear(this, MSG_ALLOCATION_PHASE); | 1140 session_->network_thread()->Clear(this, MSG_ALLOCATION_PHASE); |
| 1185 } | 1141 } |
| 1186 } | 1142 } |
| 1187 | 1143 |
| 1188 void AllocationSequence::OnMessage(rtc::Message* msg) { | 1144 void AllocationSequence::OnMessage(rtc::Message* msg) { |
| 1189 RTC_DCHECK(rtc::Thread::Current() == session_->network_thread()); | 1145 RTC_DCHECK(rtc::Thread::Current() == session_->network_thread()); |
| 1190 RTC_DCHECK(msg->message_id == MSG_ALLOCATION_PHASE); | 1146 RTC_DCHECK(msg->message_id == MSG_ALLOCATION_PHASE); |
| 1191 | 1147 |
| 1192 const char* const PHASE_NAMES[kNumPhases] = { | 1148 const char* const PHASE_NAMES[kNumPhases] = {"Udp", "Relay", "Tcp"}; |
| 1193 "Udp", "Relay", "Tcp", "SslTcp" | |
| 1194 }; | |
| 1195 | 1149 |
| 1196 // Perform all of the phases in the current step. | 1150 // Perform all of the phases in the current step. |
| 1197 LOG_J(LS_INFO, network_) << "Allocation Phase=" | 1151 LOG_J(LS_INFO, network_) << "Allocation Phase=" |
| 1198 << PHASE_NAMES[phase_]; | 1152 << PHASE_NAMES[phase_]; |
| 1199 | 1153 |
| 1200 switch (phase_) { | 1154 switch (phase_) { |
| 1201 case PHASE_UDP: | 1155 case PHASE_UDP: |
| 1202 CreateUDPPorts(); | 1156 CreateUDPPorts(); |
| 1203 CreateStunPorts(); | 1157 CreateStunPorts(); |
| 1204 EnableProtocol(PROTO_UDP); | |
| 1205 break; | 1158 break; |
| 1206 | 1159 |
| 1207 case PHASE_RELAY: | 1160 case PHASE_RELAY: |
| 1208 CreateRelayPorts(); | 1161 CreateRelayPorts(); |
| 1209 break; | 1162 break; |
| 1210 | 1163 |
| 1211 case PHASE_TCP: | 1164 case PHASE_TCP: |
| 1212 CreateTCPPorts(); | 1165 CreateTCPPorts(); |
| 1213 EnableProtocol(PROTO_TCP); | |
| 1214 break; | |
| 1215 | |
| 1216 case PHASE_SSLTCP: | |
| 1217 state_ = kCompleted; | 1166 state_ = kCompleted; |
| 1218 EnableProtocol(PROTO_SSLTCP); | |
| 1219 break; | 1167 break; |
| 1220 | 1168 |
| 1221 default: | 1169 default: |
| 1222 RTC_NOTREACHED(); | 1170 RTC_NOTREACHED(); |
| 1223 } | 1171 } |
| 1224 | 1172 |
| 1225 if (state() == kRunning) { | 1173 if (state() == kRunning) { |
| 1226 ++phase_; | 1174 ++phase_; |
| 1227 session_->network_thread()->PostDelayed(RTC_FROM_HERE, | 1175 session_->network_thread()->PostDelayed(RTC_FROM_HERE, |
| 1228 session_->allocator()->step_delay(), | 1176 session_->allocator()->step_delay(), |
| 1229 this, MSG_ALLOCATION_PHASE); | 1177 this, MSG_ALLOCATION_PHASE); |
| 1230 } else { | 1178 } else { |
| 1231 // If all phases in AllocationSequence are completed, no allocation | 1179 // If all phases in AllocationSequence are completed, no allocation |
| 1232 // steps needed further. Canceling pending signal. | 1180 // steps needed further. Canceling pending signal. |
| 1233 session_->network_thread()->Clear(this, MSG_ALLOCATION_PHASE); | 1181 session_->network_thread()->Clear(this, MSG_ALLOCATION_PHASE); |
| 1234 SignalPortAllocationComplete(this); | 1182 SignalPortAllocationComplete(this); |
| 1235 } | 1183 } |
| 1236 } | 1184 } |
| 1237 | 1185 |
| 1238 void AllocationSequence::EnableProtocol(ProtocolType proto) { | |
| 1239 if (!ProtocolEnabled(proto)) { | |
| 1240 protocols_.push_back(proto); | |
| 1241 session_->OnProtocolEnabled(this, proto); | |
| 1242 } | |
| 1243 } | |
| 1244 | |
| 1245 bool AllocationSequence::ProtocolEnabled(ProtocolType proto) const { | |
| 1246 for (ProtocolList::const_iterator it = protocols_.begin(); | |
| 1247 it != protocols_.end(); ++it) { | |
| 1248 if (*it == proto) | |
| 1249 return true; | |
| 1250 } | |
| 1251 return false; | |
| 1252 } | |
| 1253 | |
| 1254 void AllocationSequence::CreateUDPPorts() { | 1186 void AllocationSequence::CreateUDPPorts() { |
| 1255 if (IsFlagSet(PORTALLOCATOR_DISABLE_UDP)) { | 1187 if (IsFlagSet(PORTALLOCATOR_DISABLE_UDP)) { |
| 1256 LOG(LS_VERBOSE) << "AllocationSequence: UDP ports disabled, skipping."; | 1188 LOG(LS_VERBOSE) << "AllocationSequence: UDP ports disabled, skipping."; |
| 1257 return; | 1189 return; |
| 1258 } | 1190 } |
| 1259 | 1191 |
| 1260 // TODO(mallinath) - Remove UDPPort creating socket after shared socket | 1192 // TODO(mallinath) - Remove UDPPort creating socket after shared socket |
| 1261 // is enabled completely. | 1193 // is enabled completely. |
| 1262 UDPPort* port = NULL; | 1194 UDPPort* port = NULL; |
| 1263 bool emit_local_candidate_for_anyaddress = | 1195 bool emit_local_candidate_for_anyaddress = |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1572 ServerAddresses servers; | 1504 ServerAddresses servers; |
| 1573 for (size_t i = 0; i < relays.size(); ++i) { | 1505 for (size_t i = 0; i < relays.size(); ++i) { |
| 1574 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { | 1506 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { |
| 1575 servers.insert(relays[i].ports.front().address); | 1507 servers.insert(relays[i].ports.front().address); |
| 1576 } | 1508 } |
| 1577 } | 1509 } |
| 1578 return servers; | 1510 return servers; |
| 1579 } | 1511 } |
| 1580 | 1512 |
| 1581 } // namespace cricket | 1513 } // namespace cricket |
| OLD | NEW |