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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 Construct(); | 199 Construct(); |
200 } | 200 } |
201 | 201 |
202 void BasicPortAllocator::Construct() { | 202 void BasicPortAllocator::Construct() { |
203 allow_tcp_listen_ = true; | 203 allow_tcp_listen_ = true; |
204 } | 204 } |
205 | 205 |
206 BasicPortAllocator::~BasicPortAllocator() { | 206 BasicPortAllocator::~BasicPortAllocator() { |
207 } | 207 } |
208 | 208 |
209 PortAllocatorSession *BasicPortAllocator::CreateSessionInternal( | 209 PortAllocatorSession* BasicPortAllocator::CreateSessionInternal( |
210 const std::string& content_name, int component, | 210 const std::string& content_name, int component, |
211 const std::string& ice_ufrag, const std::string& ice_pwd) { | 211 const std::string& ice_ufrag, const std::string& ice_pwd) { |
212 return new BasicPortAllocatorSession( | 212 return new BasicPortAllocatorSession( |
213 this, content_name, component, ice_ufrag, ice_pwd); | 213 this, content_name, component, ice_ufrag, ice_pwd); |
214 } | 214 } |
215 | 215 |
216 | 216 |
217 // BasicPortAllocatorSession | 217 // BasicPortAllocatorSession |
218 BasicPortAllocatorSession::BasicPortAllocatorSession( | 218 BasicPortAllocatorSession::BasicPortAllocatorSession( |
219 BasicPortAllocator *allocator, | 219 BasicPortAllocator *allocator, |
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
918 | 918 |
919 if (port) { | 919 if (port) { |
920 // If shared socket is enabled, STUN candidate will be allocated by the | 920 // If shared socket is enabled, STUN candidate will be allocated by the |
921 // UDPPort. | 921 // UDPPort. |
922 if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET)) { | 922 if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET)) { |
923 udp_port_ = port; | 923 udp_port_ = port; |
924 port->SignalDestroyed.connect(this, &AllocationSequence::OnPortDestroyed); | 924 port->SignalDestroyed.connect(this, &AllocationSequence::OnPortDestroyed); |
925 | 925 |
926 // If STUN is not disabled, setting stun server address to port. | 926 // If STUN is not disabled, setting stun server address to port. |
927 if (!IsFlagSet(PORTALLOCATOR_DISABLE_STUN)) { | 927 if (!IsFlagSet(PORTALLOCATOR_DISABLE_STUN)) { |
928 // If config has stun_servers, use it to get server reflexive candidate | |
929 // otherwise use first TURN server which supports UDP. | |
930 if (config_ && !config_->StunServers().empty()) { | 928 if (config_ && !config_->StunServers().empty()) { |
931 LOG(LS_INFO) << "AllocationSequence: UDPPort will be handling the " | 929 LOG(LS_INFO) << "AllocationSequence: UDPPort will be handling the " |
932 << "STUN candidate generation."; | 930 << "STUN candidate generation."; |
933 port->set_server_addresses(config_->StunServers()); | 931 port->set_server_addresses(config_->StunServers()); |
934 } else if (config_ && | |
935 config_->SupportsProtocol(RELAY_TURN, PROTO_UDP)) { | |
936 port->set_server_addresses(config_->GetRelayServerAddresses( | |
937 RELAY_TURN, PROTO_UDP)); | |
938 LOG(LS_INFO) << "AllocationSequence: TURN Server address will be " | |
939 << " used for generating STUN candidate."; | |
940 } | 932 } |
941 } | 933 } |
942 } | 934 } |
943 | 935 |
944 session_->AddAllocatedPort(port, this, true); | 936 session_->AddAllocatedPort(port, this, true); |
945 } | 937 } |
946 } | 938 } |
947 | 939 |
948 void AllocationSequence::CreateTCPPorts() { | 940 void AllocationSequence::CreateTCPPorts() { |
949 if (IsFlagSet(PORTALLOCATOR_DISABLE_TCP)) { | 941 if (IsFlagSet(PORTALLOCATOR_DISABLE_TCP)) { |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1162 password(password) { | 1154 password(password) { |
1163 if (!stun_servers.empty()) | 1155 if (!stun_servers.empty()) |
1164 stun_address = *(stun_servers.begin()); | 1156 stun_address = *(stun_servers.begin()); |
1165 } | 1157 } |
1166 | 1158 |
1167 ServerAddresses PortConfiguration::StunServers() { | 1159 ServerAddresses PortConfiguration::StunServers() { |
1168 if (!stun_address.IsNil() && | 1160 if (!stun_address.IsNil() && |
1169 stun_servers.find(stun_address) == stun_servers.end()) { | 1161 stun_servers.find(stun_address) == stun_servers.end()) { |
1170 stun_servers.insert(stun_address); | 1162 stun_servers.insert(stun_address); |
1171 } | 1163 } |
| 1164 // Every UDP TURN server should also be used as a STUN server. |
| 1165 ServerAddresses turn_servers = GetRelayServerAddresses(RELAY_TURN, PROTO_UDP); |
| 1166 for (const rtc::SocketAddress& turn_server : turn_servers) { |
| 1167 if (stun_servers.find(turn_server) == stun_servers.end()) { |
| 1168 stun_servers.insert(turn_server); |
| 1169 } |
| 1170 } |
1172 return stun_servers; | 1171 return stun_servers; |
1173 } | 1172 } |
1174 | 1173 |
1175 void PortConfiguration::AddRelay(const RelayServerConfig& config) { | 1174 void PortConfiguration::AddRelay(const RelayServerConfig& config) { |
1176 relays.push_back(config); | 1175 relays.push_back(config); |
1177 } | 1176 } |
1178 | 1177 |
1179 bool PortConfiguration::SupportsProtocol( | 1178 bool PortConfiguration::SupportsProtocol( |
1180 const RelayServerConfig& relay, ProtocolType type) const { | 1179 const RelayServerConfig& relay, ProtocolType type) const { |
1181 PortList::const_iterator relay_port; | 1180 PortList::const_iterator relay_port; |
(...skipping 21 matching lines...) Expand all Loading... |
1203 ServerAddresses servers; | 1202 ServerAddresses servers; |
1204 for (size_t i = 0; i < relays.size(); ++i) { | 1203 for (size_t i = 0; i < relays.size(); ++i) { |
1205 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { | 1204 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { |
1206 servers.insert(relays[i].ports.front().address); | 1205 servers.insert(relays[i].ports.front().address); |
1207 } | 1206 } |
1208 } | 1207 } |
1209 return servers; | 1208 return servers; |
1210 } | 1209 } |
1211 | 1210 |
1212 } // namespace cricket | 1211 } // namespace cricket |
OLD | NEW |