diff --git a/api/candidate.h b/api/candidate.h index b8aaebc14a..281f2f01a5 100644 --- a/api/candidate.h +++ b/api/candidate.h @@ -25,6 +25,10 @@ namespace cricket { +// TURN servers are limited to 32 in accordance with +// https://w3c.github.io/webrtc-pc/#dom-rtcconfiguration-iceservers +static constexpr size_t kMaxTurnServers = 32; + // Candidate for ICE based connection discovery. // TODO(phoglund): remove things in here that are not needed in the public API. diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc index d5af81e35f..0340866a59 100644 --- a/pc/peer_connection.cc +++ b/pc/peer_connection.cc @@ -605,6 +605,16 @@ RTCError PeerConnection::Initialize( return parse_error; } + // Restrict number of TURN servers. + if (!trials().IsDisabled("WebRTC-LimitTurnServers") && + turn_servers.size() > cricket::kMaxTurnServers) { + RTC_LOG(LS_WARNING) << "Number of configured TURN servers is " + << turn_servers.size() + << " which exceeds the maximum allowed number of " + << cricket::kMaxTurnServers; + turn_servers.resize(cricket::kMaxTurnServers); + } + // Add the turn logging id to all turn servers for (cricket::RelayServerConfig& turn_server : turn_servers) { turn_server.turn_logging_id = configuration.turn_logging_id; @@ -1549,6 +1559,17 @@ RTCError PeerConnection::SetConfiguration( if (!parse_error.ok()) { return parse_error; } + + // Restrict number of TURN servers. + if (!trials().IsDisabled("WebRTC-LimitTurnServers") && + turn_servers.size() > cricket::kMaxTurnServers) { + RTC_LOG(LS_WARNING) << "Number of configured TURN servers is " + << turn_servers.size() + << " which exceeds the maximum allowed number of " + << cricket::kMaxTurnServers; + turn_servers.resize(cricket::kMaxTurnServers); + } + // Add the turn logging id to all turn servers for (cricket::RelayServerConfig& turn_server : turn_servers) { turn_server.turn_logging_id = configuration.turn_logging_id;