TurnCustomizer - an interface for modifying stun messages sent by TurnPort

This patch adds an interface that allows modification of stun messages
sent by TurnPort. A user can inject a TurnCustomizer on the RTCConfig
and the TurnCustomizer will be invoked by TurnPort before sending
message. This allows user to e.g add custom attributes as described
in rtf5389.

BUG=webrtc:8313

Change-Id: I6f4333e9f8ff7fd20f32677be19285f15e1180b6
Reviewed-on: https://webrtc-review.googlesource.com/7618
Reviewed-by: Guido Urdaneta <guidou@webrtc.org>
Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Commit-Queue: Jonas Oreland <jonaso@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20233}
This commit is contained in:
Jonas Oreland
2017-10-10 14:01:40 +02:00
committed by Commit Bot
parent 2ff7ecfceb
commit bdcee28ee9
27 changed files with 559 additions and 36 deletions

View File

@ -96,11 +96,15 @@ const uint32_t DISABLE_ALL_PHASES =
PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY;
// BasicPortAllocator
BasicPortAllocator::BasicPortAllocator(rtc::NetworkManager* network_manager,
rtc::PacketSocketFactory* socket_factory)
BasicPortAllocator::BasicPortAllocator(
rtc::NetworkManager* network_manager,
rtc::PacketSocketFactory* socket_factory,
webrtc::TurnCustomizer* customizer)
: network_manager_(network_manager), socket_factory_(socket_factory) {
RTC_DCHECK(network_manager_ != nullptr);
RTC_DCHECK(socket_factory_ != nullptr);
SetConfiguration(ServerAddresses(), std::vector<RelayServerConfig>(),
0, false, customizer);
Construct();
}
@ -115,7 +119,8 @@ BasicPortAllocator::BasicPortAllocator(rtc::NetworkManager* network_manager,
const ServerAddresses& stun_servers)
: network_manager_(network_manager), socket_factory_(socket_factory) {
RTC_DCHECK(socket_factory_ != NULL);
SetConfiguration(stun_servers, std::vector<RelayServerConfig>(), 0, false);
SetConfiguration(stun_servers, std::vector<RelayServerConfig>(), 0, false,
nullptr);
Construct();
}
@ -142,7 +147,7 @@ BasicPortAllocator::BasicPortAllocator(
turn_servers.push_back(config);
}
SetConfiguration(stun_servers, turn_servers, 0, false);
SetConfiguration(stun_servers, turn_servers, 0, false, nullptr);
Construct();
}
@ -188,7 +193,7 @@ void BasicPortAllocator::AddTurnServer(const RelayServerConfig& turn_server) {
std::vector<RelayServerConfig> new_turn_servers = turn_servers();
new_turn_servers.push_back(turn_server);
SetConfiguration(stun_servers(), new_turn_servers, candidate_pool_size(),
prune_turn_ports());
prune_turn_ports(), turn_customizer());
}
// BasicPortAllocatorSession
@ -1374,7 +1379,6 @@ void AllocationSequence::CreateTurnPort(const RelayServerConfig& config) {
continue;
}
// Shared socket mode must be enabled only for UDP based ports. Hence
// don't pass shared socket for ports which will create TCP sockets.
// TODO(mallinath) - Enable shared socket mode for TURN ports. Disabled
@ -1386,7 +1390,8 @@ void AllocationSequence::CreateTurnPort(const RelayServerConfig& config) {
network_, udp_socket_.get(),
session_->username(), session_->password(),
*relay_port, config.credentials, config.priority,
session_->allocator()->origin());
session_->allocator()->origin(),
session_->allocator()->turn_customizer());
turn_ports_.push_back(port);
// Listen to the port destroyed signal, to allow AllocationSequence to
// remove entrt from it's map.
@ -1397,7 +1402,8 @@ void AllocationSequence::CreateTurnPort(const RelayServerConfig& config) {
session_->allocator()->min_port(), session_->allocator()->max_port(),
session_->username(), session_->password(), *relay_port,
config.credentials, config.priority, session_->allocator()->origin(),
config.tls_alpn_protocols, config.tls_elliptic_curves);
config.tls_alpn_protocols, config.tls_elliptic_curves,
session_->allocator()->turn_customizer());
}
RTC_DCHECK(port != NULL);
port->SetTlsCertPolicy(config.tls_cert_policy);