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

Side by Side Diff: webrtc/p2p/client/basicportallocator.cc

Issue 2989303002: Make Port (and subclasses) fully "Network"-based, instead of IP-based. (Closed)
Patch Set: Add back Port constructor that takes IP for backwards compatibility. Created 3 years, 4 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/client/basicportallocator.h ('k') | webrtc/rtc_base/virtualsocketserver.h » ('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 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 } 1089 }
1090 1090
1091 // AllocationSequence 1091 // AllocationSequence
1092 1092
1093 AllocationSequence::AllocationSequence(BasicPortAllocatorSession* session, 1093 AllocationSequence::AllocationSequence(BasicPortAllocatorSession* session,
1094 rtc::Network* network, 1094 rtc::Network* network,
1095 PortConfiguration* config, 1095 PortConfiguration* config,
1096 uint32_t flags) 1096 uint32_t flags)
1097 : session_(session), 1097 : session_(session),
1098 network_(network), 1098 network_(network),
1099 ip_(network->GetBestIP()),
1100 config_(config), 1099 config_(config),
1101 state_(kInit), 1100 state_(kInit),
1102 flags_(flags), 1101 flags_(flags),
1103 udp_socket_(), 1102 udp_socket_(),
1104 udp_port_(NULL), 1103 udp_port_(NULL),
1105 phase_(0) { 1104 phase_(0) {
1106 } 1105 }
1107 1106
1108 void AllocationSequence::Init() { 1107 void AllocationSequence::Init() {
1109 if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET)) { 1108 if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET)) {
1110 udp_socket_.reset(session_->socket_factory()->CreateUdpSocket( 1109 udp_socket_.reset(session_->socket_factory()->CreateUdpSocket(
1111 rtc::SocketAddress(ip_, 0), session_->allocator()->min_port(), 1110 rtc::SocketAddress(network_->GetBestIP(), 0),
1112 session_->allocator()->max_port())); 1111 session_->allocator()->min_port(), session_->allocator()->max_port()));
1113 if (udp_socket_) { 1112 if (udp_socket_) {
1114 udp_socket_->SignalReadPacket.connect( 1113 udp_socket_->SignalReadPacket.connect(
1115 this, &AllocationSequence::OnReadPacket); 1114 this, &AllocationSequence::OnReadPacket);
1116 } 1115 }
1117 // Continuing if |udp_socket_| is NULL, as local TCP and RelayPort using TCP 1116 // Continuing if |udp_socket_| is NULL, as local TCP and RelayPort using TCP
1118 // are next available options to setup a communication channel. 1117 // are next available options to setup a communication channel.
1119 } 1118 }
1120 } 1119 }
1121 1120
1122 void AllocationSequence::Clear() { 1121 void AllocationSequence::Clear() {
(...skipping 13 matching lines...) Expand all
1136 } 1135 }
1137 1136
1138 void AllocationSequence::DisableEquivalentPhases(rtc::Network* network, 1137 void AllocationSequence::DisableEquivalentPhases(rtc::Network* network,
1139 PortConfiguration* config, uint32_t* flags) { 1138 PortConfiguration* config, uint32_t* flags) {
1140 if (network_failed_) { 1139 if (network_failed_) {
1141 // If the network of this allocation sequence has ever become failed, 1140 // If the network of this allocation sequence has ever become failed,
1142 // it won't be equivalent to the new network. 1141 // it won't be equivalent to the new network.
1143 return; 1142 return;
1144 } 1143 }
1145 1144
1146 if (!((network == network_) && (ip_ == network->GetBestIP()))) { 1145 if (!((network == network_) && (previous_best_ip_ == network->GetBestIP()))) {
1147 // Different network setup; nothing is equivalent. 1146 // Different network setup; nothing is equivalent.
1148 return; 1147 return;
1149 } 1148 }
1150 1149
1151 // Else turn off the stuff that we've already got covered. 1150 // Else turn off the stuff that we've already got covered.
1152 1151
1153 // Every config implicitly specifies local, so turn that off right away. 1152 // Every config implicitly specifies local, so turn that off right away.
1154 *flags |= PORTALLOCATOR_DISABLE_UDP; 1153 *flags |= PORTALLOCATOR_DISABLE_UDP;
1155 *flags |= PORTALLOCATOR_DISABLE_TCP; 1154 *flags |= PORTALLOCATOR_DISABLE_TCP;
1156 1155
1157 if (config_ && config) { 1156 if (config_ && config) {
1158 if (config_->StunServers() == config->StunServers()) { 1157 if (config_->StunServers() == config->StunServers()) {
1159 // Already got this STUN servers covered. 1158 // Already got this STUN servers covered.
1160 *flags |= PORTALLOCATOR_DISABLE_STUN; 1159 *flags |= PORTALLOCATOR_DISABLE_STUN;
1161 } 1160 }
1162 if (!config_->relays.empty()) { 1161 if (!config_->relays.empty()) {
1163 // Already got relays covered. 1162 // Already got relays covered.
1164 // NOTE: This will even skip a _different_ set of relay servers if we 1163 // NOTE: This will even skip a _different_ set of relay servers if we
1165 // were to be given one, but that never happens in our codebase. Should 1164 // were to be given one, but that never happens in our codebase. Should
1166 // probably get rid of the list in PortConfiguration and just keep a 1165 // probably get rid of the list in PortConfiguration and just keep a
1167 // single relay server in each one. 1166 // single relay server in each one.
1168 *flags |= PORTALLOCATOR_DISABLE_RELAY; 1167 *flags |= PORTALLOCATOR_DISABLE_RELAY;
1169 } 1168 }
1170 } 1169 }
1171 } 1170 }
1172 1171
1173 void AllocationSequence::Start() { 1172 void AllocationSequence::Start() {
1174 state_ = kRunning; 1173 state_ = kRunning;
1175 session_->network_thread()->Post(RTC_FROM_HERE, this, MSG_ALLOCATION_PHASE); 1174 session_->network_thread()->Post(RTC_FROM_HERE, this, MSG_ALLOCATION_PHASE);
1175 // Take a snapshot of the best IP, so that when DisableEquivalentPhases is
1176 // called next time, we enable all phases if the best IP has since changed.
1177 previous_best_ip_ = network_->GetBestIP();
1176 } 1178 }
1177 1179
1178 void AllocationSequence::Stop() { 1180 void AllocationSequence::Stop() {
1179 // If the port is completed, don't set it to stopped. 1181 // If the port is completed, don't set it to stopped.
1180 if (state_ == kRunning) { 1182 if (state_ == kRunning) {
1181 state_ = kStopped; 1183 state_ = kStopped;
1182 session_->network_thread()->Clear(this, MSG_ALLOCATION_PHASE); 1184 session_->network_thread()->Clear(this, MSG_ALLOCATION_PHASE);
1183 } 1185 }
1184 } 1186 }
1185 1187
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1260 UDPPort* port = NULL; 1262 UDPPort* port = NULL;
1261 bool emit_local_candidate_for_anyaddress = 1263 bool emit_local_candidate_for_anyaddress =
1262 !IsFlagSet(PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE); 1264 !IsFlagSet(PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE);
1263 if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET) && udp_socket_) { 1265 if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET) && udp_socket_) {
1264 port = UDPPort::Create( 1266 port = UDPPort::Create(
1265 session_->network_thread(), session_->socket_factory(), network_, 1267 session_->network_thread(), session_->socket_factory(), network_,
1266 udp_socket_.get(), session_->username(), session_->password(), 1268 udp_socket_.get(), session_->username(), session_->password(),
1267 session_->allocator()->origin(), emit_local_candidate_for_anyaddress); 1269 session_->allocator()->origin(), emit_local_candidate_for_anyaddress);
1268 } else { 1270 } else {
1269 port = UDPPort::Create( 1271 port = UDPPort::Create(
1270 session_->network_thread(), session_->socket_factory(), network_, ip_, 1272 session_->network_thread(), session_->socket_factory(), network_,
1271 session_->allocator()->min_port(), session_->allocator()->max_port(), 1273 session_->allocator()->min_port(), session_->allocator()->max_port(),
1272 session_->username(), session_->password(), 1274 session_->username(), session_->password(),
1273 session_->allocator()->origin(), emit_local_candidate_for_anyaddress); 1275 session_->allocator()->origin(), emit_local_candidate_for_anyaddress);
1274 } 1276 }
1275 1277
1276 if (port) { 1278 if (port) {
1277 // If shared socket is enabled, STUN candidate will be allocated by the 1279 // If shared socket is enabled, STUN candidate will be allocated by the
1278 // UDPPort. 1280 // UDPPort.
1279 if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET)) { 1281 if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET)) {
1280 udp_port_ = port; 1282 udp_port_ = port;
(...skipping 12 matching lines...) Expand all
1293 session_->AddAllocatedPort(port, this, true); 1295 session_->AddAllocatedPort(port, this, true);
1294 } 1296 }
1295 } 1297 }
1296 1298
1297 void AllocationSequence::CreateTCPPorts() { 1299 void AllocationSequence::CreateTCPPorts() {
1298 if (IsFlagSet(PORTALLOCATOR_DISABLE_TCP)) { 1300 if (IsFlagSet(PORTALLOCATOR_DISABLE_TCP)) {
1299 LOG(LS_VERBOSE) << "AllocationSequence: TCP ports disabled, skipping."; 1301 LOG(LS_VERBOSE) << "AllocationSequence: TCP ports disabled, skipping.";
1300 return; 1302 return;
1301 } 1303 }
1302 1304
1303 Port* port = TCPPort::Create(session_->network_thread(), 1305 Port* port = TCPPort::Create(
1304 session_->socket_factory(), 1306 session_->network_thread(), session_->socket_factory(), network_,
1305 network_, ip_, 1307 session_->allocator()->min_port(), session_->allocator()->max_port(),
1306 session_->allocator()->min_port(), 1308 session_->username(), session_->password(),
1307 session_->allocator()->max_port(), 1309 session_->allocator()->allow_tcp_listen());
1308 session_->username(), session_->password(),
1309 session_->allocator()->allow_tcp_listen());
1310 if (port) { 1310 if (port) {
1311 session_->AddAllocatedPort(port, this, true); 1311 session_->AddAllocatedPort(port, this, true);
1312 // Since TCPPort is not created using shared socket, |port| will not be 1312 // Since TCPPort is not created using shared socket, |port| will not be
1313 // added to the dequeue. 1313 // added to the dequeue.
1314 } 1314 }
1315 } 1315 }
1316 1316
1317 void AllocationSequence::CreateStunPorts() { 1317 void AllocationSequence::CreateStunPorts() {
1318 if (IsFlagSet(PORTALLOCATOR_DISABLE_STUN)) { 1318 if (IsFlagSet(PORTALLOCATOR_DISABLE_STUN)) {
1319 LOG(LS_VERBOSE) << "AllocationSequence: STUN ports disabled, skipping."; 1319 LOG(LS_VERBOSE) << "AllocationSequence: STUN ports disabled, skipping.";
1320 return; 1320 return;
1321 } 1321 }
1322 1322
1323 if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET)) { 1323 if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET)) {
1324 return; 1324 return;
1325 } 1325 }
1326 1326
1327 if (!(config_ && !config_->StunServers().empty())) { 1327 if (!(config_ && !config_->StunServers().empty())) {
1328 LOG(LS_WARNING) 1328 LOG(LS_WARNING)
1329 << "AllocationSequence: No STUN server configured, skipping."; 1329 << "AllocationSequence: No STUN server configured, skipping.";
1330 return; 1330 return;
1331 } 1331 }
1332 1332
1333 StunPort* port = StunPort::Create(session_->network_thread(), 1333 StunPort* port = StunPort::Create(
1334 session_->socket_factory(), 1334 session_->network_thread(), session_->socket_factory(), network_,
1335 network_, ip_, 1335 session_->allocator()->min_port(), session_->allocator()->max_port(),
1336 session_->allocator()->min_port(), 1336 session_->username(), session_->password(), config_->StunServers(),
1337 session_->allocator()->max_port(), 1337 session_->allocator()->origin());
1338 session_->username(), session_->password(),
1339 config_->StunServers(),
1340 session_->allocator()->origin());
1341 if (port) { 1338 if (port) {
1342 session_->AddAllocatedPort(port, this, true); 1339 session_->AddAllocatedPort(port, this, true);
1343 // Since StunPort is not created using shared socket, |port| will not be 1340 // Since StunPort is not created using shared socket, |port| will not be
1344 // added to the dequeue. 1341 // added to the dequeue.
1345 } 1342 }
1346 } 1343 }
1347 1344
1348 void AllocationSequence::CreateRelayPorts() { 1345 void AllocationSequence::CreateRelayPorts() {
1349 if (IsFlagSet(PORTALLOCATOR_DISABLE_RELAY)) { 1346 if (IsFlagSet(PORTALLOCATOR_DISABLE_RELAY)) {
1350 LOG(LS_VERBOSE) << "AllocationSequence: Relay ports disabled, skipping."; 1347 LOG(LS_VERBOSE) << "AllocationSequence: Relay ports disabled, skipping.";
(...skipping 15 matching lines...) Expand all
1366 } else if (relay.type == RELAY_TURN) { 1363 } else if (relay.type == RELAY_TURN) {
1367 CreateTurnPort(relay); 1364 CreateTurnPort(relay);
1368 } else { 1365 } else {
1369 RTC_NOTREACHED(); 1366 RTC_NOTREACHED();
1370 } 1367 }
1371 } 1368 }
1372 } 1369 }
1373 1370
1374 void AllocationSequence::CreateGturnPort(const RelayServerConfig& config) { 1371 void AllocationSequence::CreateGturnPort(const RelayServerConfig& config) {
1375 // TODO(mallinath) - Rename RelayPort to GTurnPort. 1372 // TODO(mallinath) - Rename RelayPort to GTurnPort.
1376 RelayPort* port = RelayPort::Create(session_->network_thread(), 1373 RelayPort* port = RelayPort::Create(
1377 session_->socket_factory(), 1374 session_->network_thread(), session_->socket_factory(), network_,
1378 network_, ip_, 1375 session_->allocator()->min_port(), session_->allocator()->max_port(),
1379 session_->allocator()->min_port(), 1376 config_->username, config_->password);
1380 session_->allocator()->max_port(),
1381 config_->username, config_->password);
1382 if (port) { 1377 if (port) {
1383 // Since RelayPort is not created using shared socket, |port| will not be 1378 // Since RelayPort is not created using shared socket, |port| will not be
1384 // added to the dequeue. 1379 // added to the dequeue.
1385 // Note: We must add the allocated port before we add addresses because 1380 // Note: We must add the allocated port before we add addresses because
1386 // the latter will create candidates that need name and preference 1381 // the latter will create candidates that need name and preference
1387 // settings. However, we also can't prepare the address (normally 1382 // settings. However, we also can't prepare the address (normally
1388 // done by AddAllocatedPort) until we have these addresses. So we 1383 // done by AddAllocatedPort) until we have these addresses. So we
1389 // wait to do that until below. 1384 // wait to do that until below.
1390 session_->AddAllocatedPort(port, this, false); 1385 session_->AddAllocatedPort(port, this, false);
1391 1386
(...skipping 18 matching lines...) Expand all
1410 1405
1411 // Skip UDP connections to relay servers if it's disallowed. 1406 // Skip UDP connections to relay servers if it's disallowed.
1412 if (IsFlagSet(PORTALLOCATOR_DISABLE_UDP_RELAY) && 1407 if (IsFlagSet(PORTALLOCATOR_DISABLE_UDP_RELAY) &&
1413 relay_port->proto == PROTO_UDP) { 1408 relay_port->proto == PROTO_UDP) {
1414 continue; 1409 continue;
1415 } 1410 }
1416 1411
1417 // Do not create a port if the server address family is known and does 1412 // Do not create a port if the server address family is known and does
1418 // not match the local IP address family. 1413 // not match the local IP address family.
1419 int server_ip_family = relay_port->address.ipaddr().family(); 1414 int server_ip_family = relay_port->address.ipaddr().family();
1420 int local_ip_family = ip_.family(); 1415 int local_ip_family = network_->GetBestIP().family();
1421 if (server_ip_family != AF_UNSPEC && server_ip_family != local_ip_family) { 1416 if (server_ip_family != AF_UNSPEC && server_ip_family != local_ip_family) {
1422 LOG(LS_INFO) << "Server and local address families are not compatible. " 1417 LOG(LS_INFO) << "Server and local address families are not compatible. "
1423 << "Server address: " 1418 << "Server address: "
1424 << relay_port->address.ipaddr().ToString() 1419 << relay_port->address.ipaddr().ToString()
1425 << " Local address: " << ip_.ToString(); 1420 << " Local address: " << network_->GetBestIP().ToString();
1426 continue; 1421 continue;
1427 } 1422 }
1428 1423
1429 1424
1430 // Shared socket mode must be enabled only for UDP based ports. Hence 1425 // Shared socket mode must be enabled only for UDP based ports. Hence
1431 // don't pass shared socket for ports which will create TCP sockets. 1426 // don't pass shared socket for ports which will create TCP sockets.
1432 // TODO(mallinath) - Enable shared socket mode for TURN ports. Disabled 1427 // TODO(mallinath) - Enable shared socket mode for TURN ports. Disabled
1433 // due to webrtc bug https://code.google.com/p/webrtc/issues/detail?id=3537 1428 // due to webrtc bug https://code.google.com/p/webrtc/issues/detail?id=3537
1434 if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET) && 1429 if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET) &&
1435 relay_port->proto == PROTO_UDP && udp_socket_) { 1430 relay_port->proto == PROTO_UDP && udp_socket_) {
1436 port = TurnPort::Create(session_->network_thread(), 1431 port = TurnPort::Create(session_->network_thread(),
1437 session_->socket_factory(), 1432 session_->socket_factory(),
1438 network_, udp_socket_.get(), 1433 network_, udp_socket_.get(),
1439 session_->username(), session_->password(), 1434 session_->username(), session_->password(),
1440 *relay_port, config.credentials, config.priority, 1435 *relay_port, config.credentials, config.priority,
1441 session_->allocator()->origin()); 1436 session_->allocator()->origin());
1442 turn_ports_.push_back(port); 1437 turn_ports_.push_back(port);
1443 // Listen to the port destroyed signal, to allow AllocationSequence to 1438 // Listen to the port destroyed signal, to allow AllocationSequence to
1444 // remove entrt from it's map. 1439 // remove entrt from it's map.
1445 port->SignalDestroyed.connect(this, &AllocationSequence::OnPortDestroyed); 1440 port->SignalDestroyed.connect(this, &AllocationSequence::OnPortDestroyed);
1446 } else { 1441 } else {
1447 port = TurnPort::Create(session_->network_thread(), 1442 port = TurnPort::Create(
1448 session_->socket_factory(), 1443 session_->network_thread(), session_->socket_factory(), network_,
1449 network_, ip_, 1444 session_->allocator()->min_port(), session_->allocator()->max_port(),
1450 session_->allocator()->min_port(), 1445 session_->username(), session_->password(), *relay_port,
1451 session_->allocator()->max_port(), 1446 config.credentials, config.priority, session_->allocator()->origin());
1452 session_->username(),
1453 session_->password(),
1454 *relay_port, config.credentials, config.priority,
1455 session_->allocator()->origin());
1456 } 1447 }
1457 RTC_DCHECK(port != NULL); 1448 RTC_DCHECK(port != NULL);
1458 port->SetTlsCertPolicy(config.tls_cert_policy); 1449 port->SetTlsCertPolicy(config.tls_cert_policy);
1459 session_->AddAllocatedPort(port, this, true); 1450 session_->AddAllocatedPort(port, this, true);
1460 } 1451 }
1461 } 1452 }
1462 1453
1463 void AllocationSequence::OnReadPacket( 1454 void AllocationSequence::OnReadPacket(
1464 rtc::AsyncPacketSocket* socket, const char* data, size_t size, 1455 rtc::AsyncPacketSocket* socket, const char* data, size_t size,
1465 const rtc::SocketAddress& remote_addr, 1456 const rtc::SocketAddress& remote_addr,
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1579 ServerAddresses servers; 1570 ServerAddresses servers;
1580 for (size_t i = 0; i < relays.size(); ++i) { 1571 for (size_t i = 0; i < relays.size(); ++i) {
1581 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { 1572 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) {
1582 servers.insert(relays[i].ports.front().address); 1573 servers.insert(relays[i].ports.front().address);
1583 } 1574 }
1584 } 1575 }
1585 return servers; 1576 return servers;
1586 } 1577 }
1587 1578
1588 } // namespace cricket 1579 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/client/basicportallocator.h ('k') | webrtc/rtc_base/virtualsocketserver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698