Add TURN server to Emulated Network infrastructure

This can be used to test ICE behavior.

Bug: chromium:1024965
Change-Id: Ie4ba9cd5c3cf3c2f71bab3637f925263dbc6296e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/193701
Commit-Queue: Jonas Oreland <jonaso@webrtc.org>
Reviewed-by: Artem Titov <titovartem@webrtc.org>
Reviewed-by: Christoffer Rodbro <crodbro@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32625}
This commit is contained in:
Jonas Oreland
2020-11-17 21:30:33 +01:00
committed by Commit Bot
parent 26ce03e469
commit 97050115f0
9 changed files with 512 additions and 2 deletions

View File

@ -17,6 +17,7 @@
#include "api/units/timestamp.h"
#include "call/simulated_network.h"
#include "rtc_base/fake_network.h"
#include "test/network/emulated_turn_server.h"
#include "test/time_controller/real_time_controller.h"
#include "test/time_controller/simulated_time_controller.h"
@ -55,7 +56,11 @@ NetworkEmulationManagerImpl::NetworkEmulationManagerImpl(TimeMode mode)
// TODO(srte): Ensure that any pending task that must be run for consistency
// (such as stats collection tasks) are not cancelled when the task queue is
// destroyed.
NetworkEmulationManagerImpl::~NetworkEmulationManagerImpl() = default;
NetworkEmulationManagerImpl::~NetworkEmulationManagerImpl() {
for (auto& turn_server : turn_servers_) {
turn_server->Stop();
}
}
EmulatedNetworkNode* NetworkEmulationManagerImpl::CreateEmulatedNode(
BuiltInNetworkBehaviorConfig config) {
@ -332,5 +337,20 @@ Timestamp NetworkEmulationManagerImpl::Now() const {
return clock_->CurrentTime();
}
EmulatedTURNServerInterface* NetworkEmulationManagerImpl::CreateTURNServer(
EmulatedTURNServerConfig config) {
auto* client = CreateEndpoint(config.client_config);
auto* peer = CreateEndpoint(config.client_config);
char buf[128];
rtc::SimpleStringBuilder str(buf);
str.AppendFormat("turn_server_%u",
static_cast<unsigned>(turn_servers_.size()));
auto turn = std::make_unique<EmulatedTURNServer>(
time_controller_->CreateThread(str.str()), client, peer);
auto out = turn.get();
turn_servers_.push_back(std::move(turn));
return out;
}
} // namespace test
} // namespace webrtc