Removing webrtc::PortAllocatorFactoryInterface.
ICE servers are now passed directly into PortAllocator, making PortAllocatorFactoryInterface redundant. This CL also moves SetNetworkIgnoreMask to PortAllocator. R=phoglund@webrtc.org, pthatcher@webrtc.org, tkchin@webrtc.org Review URL: https://codereview.webrtc.org/1520963002 . Cr-Commit-Position: refs/heads/master@{#11139}
This commit is contained in:
parent
e86e15b2a2
commit
0c7e9f540b
@ -1,85 +0,0 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
// This file defines a fake port allocator factory used for testing.
|
||||
// This implementation creates instances of cricket::FakePortAllocator.
|
||||
|
||||
#ifndef TALK_APP_WEBRTC_FAKEPORTALLOCATORFACTORY_H_
|
||||
#define TALK_APP_WEBRTC_FAKEPORTALLOCATORFACTORY_H_
|
||||
|
||||
#include "talk/app/webrtc/peerconnectioninterface.h"
|
||||
#include "webrtc/p2p/client/fakeportallocator.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class FakePortAllocatorFactory : public PortAllocatorFactoryInterface {
|
||||
public:
|
||||
static FakePortAllocatorFactory* Create() {
|
||||
rtc::RefCountedObject<FakePortAllocatorFactory>* allocator =
|
||||
new rtc::RefCountedObject<FakePortAllocatorFactory>();
|
||||
return allocator;
|
||||
}
|
||||
|
||||
virtual cricket::PortAllocator* CreatePortAllocator(
|
||||
const std::vector<StunConfiguration>& stun_configurations,
|
||||
const std::vector<TurnConfiguration>& turn_configurations) {
|
||||
stun_configs_ = stun_configurations;
|
||||
turn_configs_ = turn_configurations;
|
||||
last_created_allocator_ =
|
||||
new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr);
|
||||
return last_created_allocator_;
|
||||
}
|
||||
|
||||
const std::vector<StunConfiguration>& stun_configs() const {
|
||||
return stun_configs_;
|
||||
}
|
||||
|
||||
const std::vector<TurnConfiguration>& turn_configs() const {
|
||||
return turn_configs_;
|
||||
}
|
||||
|
||||
void SetNetworkIgnoreMask(int network_ignore_mask) {}
|
||||
|
||||
// Up to caller to ensure this isn't called after the allocator has been
|
||||
// destroyed.
|
||||
cricket::FakePortAllocator* last_created_allocator() {
|
||||
return last_created_allocator_;
|
||||
}
|
||||
|
||||
protected:
|
||||
FakePortAllocatorFactory() {}
|
||||
~FakePortAllocatorFactory() {}
|
||||
|
||||
private:
|
||||
std::vector<PortAllocatorFactoryInterface::StunConfiguration> stun_configs_;
|
||||
std::vector<PortAllocatorFactoryInterface::TurnConfiguration> turn_configs_;
|
||||
cricket::FakePortAllocator* last_created_allocator_ = nullptr;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // TALK_APP_WEBRTC_FAKEPORTALLOCATORFACTORY_H_
|
||||
@ -271,11 +271,13 @@ class RTCStatsObserver : public StatsObserver {
|
||||
- (instancetype)initWithFactory:(webrtc::PeerConnectionFactoryInterface*)factory
|
||||
iceServers:(const webrtc::PeerConnectionInterface::IceServers&)iceServers
|
||||
constraints:(const webrtc::MediaConstraintsInterface*)constraints {
|
||||
NSParameterAssert(factory != NULL);
|
||||
NSParameterAssert(factory != nullptr);
|
||||
if (self = [super init]) {
|
||||
webrtc::PeerConnectionInterface::RTCConfiguration config;
|
||||
config.servers = iceServers;
|
||||
_observer.reset(new webrtc::RTCPeerConnectionObserver(self));
|
||||
_peerConnection = factory->CreatePeerConnection(
|
||||
iceServers, constraints, NULL, NULL, _observer.get());
|
||||
config, constraints, nullptr, nullptr, _observer.get());
|
||||
_localStreams = [[NSMutableArray alloc] init];
|
||||
}
|
||||
return self;
|
||||
|
||||
@ -66,12 +66,6 @@ using webrtc::MediaStreamInterface;
|
||||
using webrtc::PeerConnectionInterface;
|
||||
using webrtc::RtpSenderInterface;
|
||||
using webrtc::StreamCollection;
|
||||
using webrtc::StunConfigurations;
|
||||
using webrtc::TurnConfigurations;
|
||||
typedef webrtc::PortAllocatorFactoryInterface::StunConfiguration
|
||||
StunConfiguration;
|
||||
typedef webrtc::PortAllocatorFactoryInterface::TurnConfiguration
|
||||
TurnConfiguration;
|
||||
|
||||
static const char kDefaultStreamLabel[] = "default";
|
||||
static const char kDefaultAudioTrackLabel[] = "defaulta0";
|
||||
@ -86,8 +80,6 @@ static const size_t kTurnTransportTokensNum = 2;
|
||||
static const int kDefaultStunPort = 3478;
|
||||
static const int kDefaultStunTlsPort = 5349;
|
||||
static const char kTransport[] = "transport";
|
||||
static const char kUdpTransportType[] = "udp";
|
||||
static const char kTcpTransportType[] = "tcp";
|
||||
|
||||
// NOTE: Must be in the same order as the ServiceType enum.
|
||||
static const char* kValidIceServiceTypes[] = {"stun", "stuns", "turn", "turns"};
|
||||
@ -223,12 +215,12 @@ bool ParseHostnameAndPortFromString(const std::string& in_str,
|
||||
return !host->empty();
|
||||
}
|
||||
|
||||
// Adds a StunConfiguration or TurnConfiguration to the appropriate list,
|
||||
// Adds a STUN or TURN server to the appropriate list,
|
||||
// by parsing |url| and using the username/password in |server|.
|
||||
bool ParseIceServerUrl(const PeerConnectionInterface::IceServer& server,
|
||||
const std::string& url,
|
||||
StunConfigurations* stun_config,
|
||||
TurnConfigurations* turn_config) {
|
||||
cricket::ServerAddresses* stun_servers,
|
||||
std::vector<cricket::RelayServerConfig>* turn_servers) {
|
||||
// draft-nandakumar-rtcweb-stun-uri-01
|
||||
// stunURI = scheme ":" stun-host [ ":" stun-port ]
|
||||
// scheme = "stun" / "stuns"
|
||||
@ -243,10 +235,10 @@ bool ParseIceServerUrl(const PeerConnectionInterface::IceServer& server,
|
||||
// transport-ext = 1*unreserved
|
||||
// turn-host = IP-literal / IPv4address / reg-name
|
||||
// turn-port = *DIGIT
|
||||
RTC_DCHECK(stun_config != nullptr);
|
||||
RTC_DCHECK(turn_config != nullptr);
|
||||
RTC_DCHECK(stun_servers != nullptr);
|
||||
RTC_DCHECK(turn_servers != nullptr);
|
||||
std::vector<std::string> tokens;
|
||||
std::string turn_transport_type = kUdpTransportType;
|
||||
cricket::ProtocolType turn_transport_type = cricket::PROTO_UDP;
|
||||
RTC_DCHECK(!url.empty());
|
||||
rtc::tokenize(url, '?', &tokens);
|
||||
std::string uri_without_transport = tokens[0];
|
||||
@ -257,11 +249,12 @@ bool ParseIceServerUrl(const PeerConnectionInterface::IceServer& server,
|
||||
if (tokens[0] == kTransport) {
|
||||
// As per above grammar transport param will be consist of lower case
|
||||
// letters.
|
||||
if (tokens[1] != kUdpTransportType && tokens[1] != kTcpTransportType) {
|
||||
if (!cricket::StringToProto(tokens[1].c_str(), &turn_transport_type) ||
|
||||
(turn_transport_type != cricket::PROTO_UDP &&
|
||||
turn_transport_type != cricket::PROTO_TCP)) {
|
||||
LOG(LS_WARNING) << "Transport param should always be udp or tcp.";
|
||||
return false;
|
||||
}
|
||||
turn_transport_type = tokens[1];
|
||||
}
|
||||
}
|
||||
|
||||
@ -300,7 +293,7 @@ bool ParseIceServerUrl(const PeerConnectionInterface::IceServer& server,
|
||||
int port = kDefaultStunPort;
|
||||
if (service_type == TURNS) {
|
||||
port = kDefaultStunTlsPort;
|
||||
turn_transport_type = kTcpTransportType;
|
||||
turn_transport_type = cricket::PROTO_TCP;
|
||||
}
|
||||
|
||||
std::string address;
|
||||
@ -317,16 +310,14 @@ bool ParseIceServerUrl(const PeerConnectionInterface::IceServer& server,
|
||||
switch (service_type) {
|
||||
case STUN:
|
||||
case STUNS:
|
||||
stun_config->push_back(StunConfiguration(address, port));
|
||||
stun_servers->insert(rtc::SocketAddress(address, port));
|
||||
break;
|
||||
case TURN:
|
||||
case TURNS: {
|
||||
bool secure = (service_type == TURNS);
|
||||
turn_config->push_back(TurnConfiguration(address, port,
|
||||
username,
|
||||
server.password,
|
||||
turn_transport_type,
|
||||
secure));
|
||||
turn_servers->push_back(
|
||||
cricket::RelayServerConfig(address, port, username, server.password,
|
||||
turn_transport_type, secure));
|
||||
break;
|
||||
}
|
||||
case INVALID:
|
||||
@ -337,40 +328,6 @@ bool ParseIceServerUrl(const PeerConnectionInterface::IceServer& server,
|
||||
return true;
|
||||
}
|
||||
|
||||
void ConvertToCricketIceServers(
|
||||
const std::vector<StunConfiguration>& stuns,
|
||||
const std::vector<TurnConfiguration>& turns,
|
||||
cricket::ServerAddresses* cricket_stuns,
|
||||
std::vector<cricket::RelayServerConfig>* cricket_turns) {
|
||||
RTC_DCHECK(cricket_stuns && cricket_turns);
|
||||
for (const StunConfiguration& stun : stuns) {
|
||||
cricket_stuns->insert(stun.server);
|
||||
}
|
||||
|
||||
int priority = static_cast<int>(turns.size() - 1);
|
||||
for (const TurnConfiguration& turn : turns) {
|
||||
cricket::RelayCredentials credentials(turn.username, turn.password);
|
||||
cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
|
||||
cricket::ProtocolType protocol;
|
||||
// Using VERIFY because ParseIceServers should have already caught an
|
||||
// invalid transport type.
|
||||
if (!VERIFY(
|
||||
cricket::StringToProto(turn.transport_type.c_str(), &protocol))) {
|
||||
LOG(LS_WARNING) << "Ignoring TURN server " << turn.server << ". "
|
||||
<< "Reason= Incorrect " << turn.transport_type
|
||||
<< " transport parameter.";
|
||||
} else {
|
||||
relay_server.ports.push_back(
|
||||
cricket::ProtocolAddress(turn.server, protocol, turn.secure));
|
||||
relay_server.credentials = credentials;
|
||||
relay_server.priority = priority;
|
||||
cricket_turns->push_back(relay_server);
|
||||
}
|
||||
// First in the list gets highest priority.
|
||||
--priority;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if we can send |new_stream| on a PeerConnection.
|
||||
bool CanAddLocalMediaStream(webrtc::StreamCollectionInterface* current_streams,
|
||||
webrtc::MediaStreamInterface* new_stream) {
|
||||
@ -563,8 +520,8 @@ bool ParseConstraintsForAnswer(const MediaConstraintsInterface* constraints,
|
||||
}
|
||||
|
||||
bool ParseIceServers(const PeerConnectionInterface::IceServers& servers,
|
||||
StunConfigurations* stun_config,
|
||||
TurnConfigurations* turn_config) {
|
||||
cricket::ServerAddresses* stun_servers,
|
||||
std::vector<cricket::RelayServerConfig>* turn_servers) {
|
||||
for (const webrtc::PeerConnectionInterface::IceServer& server : servers) {
|
||||
if (!server.urls.empty()) {
|
||||
for (const std::string& url : server.urls) {
|
||||
@ -572,13 +529,13 @@ bool ParseIceServers(const PeerConnectionInterface::IceServers& servers,
|
||||
LOG(LS_ERROR) << "Empty uri.";
|
||||
return false;
|
||||
}
|
||||
if (!ParseIceServerUrl(server, url, stun_config, turn_config)) {
|
||||
if (!ParseIceServerUrl(server, url, stun_servers, turn_servers)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else if (!server.uri.empty()) {
|
||||
// Fallback to old .uri if new .urls isn't present.
|
||||
if (!ParseIceServerUrl(server, server.uri, stun_config, turn_config)) {
|
||||
if (!ParseIceServerUrl(server, server.uri, stun_servers, turn_servers)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
@ -586,6 +543,13 @@ bool ParseIceServers(const PeerConnectionInterface::IceServers& servers,
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Candidates must have unique priorities, so that connectivity checks
|
||||
// are performed in a well-defined order.
|
||||
int priority = static_cast<int>(turn_servers->size() - 1);
|
||||
for (cricket::RelayServerConfig& turn_server : *turn_servers) {
|
||||
// First in the list gets highest priority.
|
||||
turn_server.priority = priority--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -613,30 +577,6 @@ PeerConnection::~PeerConnection() {
|
||||
}
|
||||
}
|
||||
|
||||
bool PeerConnection::Initialize(
|
||||
const PeerConnectionInterface::RTCConfiguration& configuration,
|
||||
const MediaConstraintsInterface* constraints,
|
||||
PortAllocatorFactoryInterface* allocator_factory,
|
||||
rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
|
||||
PeerConnectionObserver* observer) {
|
||||
RTC_DCHECK(observer != nullptr);
|
||||
if (!observer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// This Initialize function parses ICE servers an extra time, but it will
|
||||
// be removed once all PortAllocaotrs support SetIceServers.
|
||||
std::vector<PortAllocatorFactoryInterface::StunConfiguration> stun_config;
|
||||
std::vector<PortAllocatorFactoryInterface::TurnConfiguration> turn_config;
|
||||
if (!ParseIceServers(configuration.servers, &stun_config, &turn_config)) {
|
||||
return false;
|
||||
}
|
||||
rtc::scoped_ptr<cricket::PortAllocator> allocator(
|
||||
allocator_factory->CreatePortAllocator(stun_config, turn_config));
|
||||
return Initialize(configuration, constraints, std::move(allocator),
|
||||
std::move(dtls_identity_store), observer);
|
||||
}
|
||||
|
||||
bool PeerConnection::Initialize(
|
||||
const PeerConnectionInterface::RTCConfiguration& configuration,
|
||||
const MediaConstraintsInterface* constraints,
|
||||
@ -652,17 +592,12 @@ bool PeerConnection::Initialize(
|
||||
|
||||
port_allocator_ = std::move(allocator);
|
||||
|
||||
std::vector<PortAllocatorFactoryInterface::StunConfiguration> stun_config;
|
||||
std::vector<PortAllocatorFactoryInterface::TurnConfiguration> turn_config;
|
||||
if (!ParseIceServers(configuration.servers, &stun_config, &turn_config)) {
|
||||
cricket::ServerAddresses stun_servers;
|
||||
std::vector<cricket::RelayServerConfig> turn_servers;
|
||||
if (!ParseIceServers(configuration.servers, &stun_servers, &turn_servers)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
cricket::ServerAddresses cricket_stuns;
|
||||
std::vector<cricket::RelayServerConfig> cricket_turns;
|
||||
ConvertToCricketIceServers(stun_config, turn_config, &cricket_stuns,
|
||||
&cricket_turns);
|
||||
port_allocator_->SetIceServers(cricket_stuns, cricket_turns);
|
||||
port_allocator_->SetIceServers(stun_servers, turn_servers);
|
||||
|
||||
// To handle both internal and externally created port allocator, we will
|
||||
// enable BUNDLE here.
|
||||
@ -1185,16 +1120,12 @@ void PeerConnection::SetRemoteDescription(
|
||||
bool PeerConnection::SetConfiguration(const RTCConfiguration& config) {
|
||||
TRACE_EVENT0("webrtc", "PeerConnection::SetConfiguration");
|
||||
if (port_allocator_) {
|
||||
std::vector<PortAllocatorFactoryInterface::StunConfiguration> stuns;
|
||||
std::vector<PortAllocatorFactoryInterface::TurnConfiguration> turns;
|
||||
if (!ParseIceServers(config.servers, &stuns, &turns)) {
|
||||
cricket::ServerAddresses stun_servers;
|
||||
std::vector<cricket::RelayServerConfig> turn_servers;
|
||||
if (!ParseIceServers(config.servers, &stun_servers, &turn_servers)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
cricket::ServerAddresses cricket_stuns;
|
||||
std::vector<cricket::RelayServerConfig> cricket_turns;
|
||||
ConvertToCricketIceServers(stuns, turns, &cricket_stuns, &cricket_turns);
|
||||
port_allocator_->SetIceServers(cricket_stuns, cricket_turns);
|
||||
port_allocator_->SetIceServers(stun_servers, turn_servers);
|
||||
}
|
||||
session_->SetIceConfig(session_->ParseIceConfig(config));
|
||||
return session_->SetIceTransports(config.type);
|
||||
|
||||
@ -45,11 +45,6 @@ namespace webrtc {
|
||||
class MediaStreamObserver;
|
||||
class RemoteMediaStreamFactory;
|
||||
|
||||
typedef std::vector<PortAllocatorFactoryInterface::StunConfiguration>
|
||||
StunConfigurations;
|
||||
typedef std::vector<PortAllocatorFactoryInterface::TurnConfiguration>
|
||||
TurnConfigurations;
|
||||
|
||||
// Populates |session_options| from |rtc_options|, and returns true if options
|
||||
// are valid.
|
||||
bool ConvertRtcOptionsForOffer(
|
||||
@ -61,11 +56,11 @@ bool ConvertRtcOptionsForOffer(
|
||||
bool ParseConstraintsForAnswer(const MediaConstraintsInterface* constraints,
|
||||
cricket::MediaSessionOptions* session_options);
|
||||
|
||||
// Parses the URLs for each server in |servers| to build |stun_config| and
|
||||
// |turn_config|.
|
||||
// Parses the URLs for each server in |servers| to build |stun_servers| and
|
||||
// |turn_servers|.
|
||||
bool ParseIceServers(const PeerConnectionInterface::IceServers& servers,
|
||||
StunConfigurations* stun_config,
|
||||
TurnConfigurations* turn_config);
|
||||
cricket::ServerAddresses* stun_servers,
|
||||
std::vector<cricket::RelayServerConfig>* turn_servers);
|
||||
|
||||
// PeerConnection implements the PeerConnectionInterface interface.
|
||||
// It uses WebRtcSession to implement the PeerConnection functionality.
|
||||
@ -76,15 +71,6 @@ class PeerConnection : public PeerConnectionInterface,
|
||||
public:
|
||||
explicit PeerConnection(PeerConnectionFactory* factory);
|
||||
|
||||
// TODO(deadbeef): Remove this overload of Initialize once everyone is moved
|
||||
// to the new version.
|
||||
bool Initialize(
|
||||
const PeerConnectionInterface::RTCConfiguration& configuration,
|
||||
const MediaConstraintsInterface* constraints,
|
||||
PortAllocatorFactoryInterface* allocator_factory,
|
||||
rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
|
||||
PeerConnectionObserver* observer);
|
||||
|
||||
bool Initialize(
|
||||
const PeerConnectionInterface::RTCConfiguration& configuration,
|
||||
const MediaConstraintsInterface* constraints,
|
||||
|
||||
@ -35,7 +35,6 @@
|
||||
|
||||
#include "talk/app/webrtc/dtmfsender.h"
|
||||
#include "talk/app/webrtc/fakemetricsobserver.h"
|
||||
#include "talk/app/webrtc/fakeportallocatorfactory.h"
|
||||
#include "talk/app/webrtc/localaudiosource.h"
|
||||
#include "talk/app/webrtc/mediastreaminterface.h"
|
||||
#include "talk/app/webrtc/peerconnection.h"
|
||||
@ -59,6 +58,7 @@
|
||||
#include "webrtc/base/virtualsocketserver.h"
|
||||
#include "webrtc/p2p/base/constants.h"
|
||||
#include "webrtc/p2p/base/sessiondescription.h"
|
||||
#include "webrtc/p2p/client/fakeportallocator.h"
|
||||
|
||||
#define MAYBE_SKIP_TEST(feature) \
|
||||
if (!(feature())) { \
|
||||
@ -740,10 +740,8 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver,
|
||||
rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) {
|
||||
EXPECT_TRUE(!peer_connection_);
|
||||
EXPECT_TRUE(!peer_connection_factory_);
|
||||
allocator_factory_ = webrtc::FakePortAllocatorFactory::Create();
|
||||
if (!allocator_factory_) {
|
||||
return false;
|
||||
}
|
||||
rtc::scoped_ptr<cricket::PortAllocator> port_allocator(
|
||||
new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
|
||||
fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
|
||||
|
||||
if (fake_audio_capture_module_ == nullptr) {
|
||||
@ -762,23 +760,23 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver,
|
||||
peer_connection_factory_->SetOptions(*options);
|
||||
}
|
||||
peer_connection_ = CreatePeerConnection(
|
||||
allocator_factory_.get(), constraints, std::move(dtls_identity_store));
|
||||
std::move(port_allocator), constraints, std::move(dtls_identity_store));
|
||||
return peer_connection_.get() != nullptr;
|
||||
}
|
||||
|
||||
rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection(
|
||||
webrtc::PortAllocatorFactoryInterface* factory,
|
||||
rtc::scoped_ptr<cricket::PortAllocator> port_allocator,
|
||||
const MediaConstraintsInterface* constraints,
|
||||
rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) {
|
||||
// CreatePeerConnection with IceServers.
|
||||
webrtc::PeerConnectionInterface::IceServers ice_servers;
|
||||
// CreatePeerConnection with RTCConfiguration.
|
||||
webrtc::PeerConnectionInterface::RTCConfiguration config;
|
||||
webrtc::PeerConnectionInterface::IceServer ice_server;
|
||||
ice_server.uri = "stun:stun.l.google.com:19302";
|
||||
ice_servers.push_back(ice_server);
|
||||
config.servers.push_back(ice_server);
|
||||
|
||||
return peer_connection_factory_->CreatePeerConnection(
|
||||
ice_servers, constraints, factory, std::move(dtls_identity_store),
|
||||
this);
|
||||
config, constraints, std::move(port_allocator),
|
||||
std::move(dtls_identity_store), this);
|
||||
}
|
||||
|
||||
void HandleIncomingOffer(const std::string& msg) {
|
||||
@ -885,7 +883,6 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver,
|
||||
|
||||
std::string id_;
|
||||
|
||||
rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface> allocator_factory_;
|
||||
rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
|
||||
rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
|
||||
peer_connection_factory_;
|
||||
@ -1865,38 +1862,37 @@ class IceServerParsingTest : public testing::Test {
|
||||
server.username = username;
|
||||
server.password = password;
|
||||
servers.push_back(server);
|
||||
return webrtc::ParseIceServers(servers, &stun_configurations_,
|
||||
&turn_configurations_);
|
||||
return webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_);
|
||||
}
|
||||
|
||||
protected:
|
||||
webrtc::StunConfigurations stun_configurations_;
|
||||
webrtc::TurnConfigurations turn_configurations_;
|
||||
cricket::ServerAddresses stun_servers_;
|
||||
std::vector<cricket::RelayServerConfig> turn_servers_;
|
||||
};
|
||||
|
||||
// Make sure all STUN/TURN prefixes are parsed correctly.
|
||||
TEST_F(IceServerParsingTest, ParseStunPrefixes) {
|
||||
EXPECT_TRUE(ParseUrl("stun:hostname"));
|
||||
EXPECT_EQ(1U, stun_configurations_.size());
|
||||
EXPECT_EQ(0U, turn_configurations_.size());
|
||||
stun_configurations_.clear();
|
||||
EXPECT_EQ(1U, stun_servers_.size());
|
||||
EXPECT_EQ(0U, turn_servers_.size());
|
||||
stun_servers_.clear();
|
||||
|
||||
EXPECT_TRUE(ParseUrl("stuns:hostname"));
|
||||
EXPECT_EQ(1U, stun_configurations_.size());
|
||||
EXPECT_EQ(0U, turn_configurations_.size());
|
||||
stun_configurations_.clear();
|
||||
EXPECT_EQ(1U, stun_servers_.size());
|
||||
EXPECT_EQ(0U, turn_servers_.size());
|
||||
stun_servers_.clear();
|
||||
|
||||
EXPECT_TRUE(ParseUrl("turn:hostname"));
|
||||
EXPECT_EQ(0U, stun_configurations_.size());
|
||||
EXPECT_EQ(1U, turn_configurations_.size());
|
||||
EXPECT_FALSE(turn_configurations_[0].secure);
|
||||
turn_configurations_.clear();
|
||||
EXPECT_EQ(0U, stun_servers_.size());
|
||||
EXPECT_EQ(1U, turn_servers_.size());
|
||||
EXPECT_FALSE(turn_servers_[0].ports[0].secure);
|
||||
turn_servers_.clear();
|
||||
|
||||
EXPECT_TRUE(ParseUrl("turns:hostname"));
|
||||
EXPECT_EQ(0U, stun_configurations_.size());
|
||||
EXPECT_EQ(1U, turn_configurations_.size());
|
||||
EXPECT_TRUE(turn_configurations_[0].secure);
|
||||
turn_configurations_.clear();
|
||||
EXPECT_EQ(0U, stun_servers_.size());
|
||||
EXPECT_EQ(1U, turn_servers_.size());
|
||||
EXPECT_TRUE(turn_servers_[0].ports[0].secure);
|
||||
turn_servers_.clear();
|
||||
|
||||
// invalid prefixes
|
||||
EXPECT_FALSE(ParseUrl("stunn:hostname"));
|
||||
@ -1908,67 +1904,69 @@ TEST_F(IceServerParsingTest, ParseStunPrefixes) {
|
||||
TEST_F(IceServerParsingTest, VerifyDefaults) {
|
||||
// TURNS defaults
|
||||
EXPECT_TRUE(ParseUrl("turns:hostname"));
|
||||
EXPECT_EQ(1U, turn_configurations_.size());
|
||||
EXPECT_EQ(5349, turn_configurations_[0].server.port());
|
||||
EXPECT_EQ("tcp", turn_configurations_[0].transport_type);
|
||||
turn_configurations_.clear();
|
||||
EXPECT_EQ(1U, turn_servers_.size());
|
||||
EXPECT_EQ(5349, turn_servers_[0].ports[0].address.port());
|
||||
EXPECT_EQ(cricket::PROTO_TCP, turn_servers_[0].ports[0].proto);
|
||||
turn_servers_.clear();
|
||||
|
||||
// TURN defaults
|
||||
EXPECT_TRUE(ParseUrl("turn:hostname"));
|
||||
EXPECT_EQ(1U, turn_configurations_.size());
|
||||
EXPECT_EQ(3478, turn_configurations_[0].server.port());
|
||||
EXPECT_EQ("udp", turn_configurations_[0].transport_type);
|
||||
turn_configurations_.clear();
|
||||
EXPECT_EQ(1U, turn_servers_.size());
|
||||
EXPECT_EQ(3478, turn_servers_[0].ports[0].address.port());
|
||||
EXPECT_EQ(cricket::PROTO_UDP, turn_servers_[0].ports[0].proto);
|
||||
turn_servers_.clear();
|
||||
|
||||
// STUN defaults
|
||||
EXPECT_TRUE(ParseUrl("stun:hostname"));
|
||||
EXPECT_EQ(1U, stun_configurations_.size());
|
||||
EXPECT_EQ(3478, stun_configurations_[0].server.port());
|
||||
stun_configurations_.clear();
|
||||
EXPECT_EQ(1U, stun_servers_.size());
|
||||
EXPECT_EQ(3478, stun_servers_.begin()->port());
|
||||
stun_servers_.clear();
|
||||
}
|
||||
|
||||
// Check that the 6 combinations of IPv4/IPv6/hostname and with/without port
|
||||
// can be parsed correctly.
|
||||
TEST_F(IceServerParsingTest, ParseHostnameAndPort) {
|
||||
EXPECT_TRUE(ParseUrl("stun:1.2.3.4:1234"));
|
||||
EXPECT_EQ(1U, stun_configurations_.size());
|
||||
EXPECT_EQ("1.2.3.4", stun_configurations_[0].server.hostname());
|
||||
EXPECT_EQ(1234, stun_configurations_[0].server.port());
|
||||
stun_configurations_.clear();
|
||||
EXPECT_EQ(1U, stun_servers_.size());
|
||||
EXPECT_EQ("1.2.3.4", stun_servers_.begin()->hostname());
|
||||
EXPECT_EQ(1234, stun_servers_.begin()->port());
|
||||
stun_servers_.clear();
|
||||
|
||||
EXPECT_TRUE(ParseUrl("stun:[1:2:3:4:5:6:7:8]:4321"));
|
||||
EXPECT_EQ(1U, stun_configurations_.size());
|
||||
EXPECT_EQ("1:2:3:4:5:6:7:8", stun_configurations_[0].server.hostname());
|
||||
EXPECT_EQ(4321, stun_configurations_[0].server.port());
|
||||
stun_configurations_.clear();
|
||||
EXPECT_EQ(1U, stun_servers_.size());
|
||||
EXPECT_EQ("1:2:3:4:5:6:7:8", stun_servers_.begin()->hostname());
|
||||
EXPECT_EQ(4321, stun_servers_.begin()->port());
|
||||
stun_servers_.clear();
|
||||
|
||||
EXPECT_TRUE(ParseUrl("stun:hostname:9999"));
|
||||
EXPECT_EQ(1U, stun_configurations_.size());
|
||||
EXPECT_EQ("hostname", stun_configurations_[0].server.hostname());
|
||||
EXPECT_EQ(9999, stun_configurations_[0].server.port());
|
||||
stun_configurations_.clear();
|
||||
EXPECT_EQ(1U, stun_servers_.size());
|
||||
EXPECT_EQ("hostname", stun_servers_.begin()->hostname());
|
||||
EXPECT_EQ(9999, stun_servers_.begin()->port());
|
||||
stun_servers_.clear();
|
||||
|
||||
EXPECT_TRUE(ParseUrl("stun:1.2.3.4"));
|
||||
EXPECT_EQ(1U, stun_configurations_.size());
|
||||
EXPECT_EQ("1.2.3.4", stun_configurations_[0].server.hostname());
|
||||
EXPECT_EQ(3478, stun_configurations_[0].server.port());
|
||||
stun_configurations_.clear();
|
||||
EXPECT_EQ(1U, stun_servers_.size());
|
||||
EXPECT_EQ("1.2.3.4", stun_servers_.begin()->hostname());
|
||||
EXPECT_EQ(3478, stun_servers_.begin()->port());
|
||||
stun_servers_.clear();
|
||||
|
||||
EXPECT_TRUE(ParseUrl("stun:[1:2:3:4:5:6:7:8]"));
|
||||
EXPECT_EQ(1U, stun_configurations_.size());
|
||||
EXPECT_EQ("1:2:3:4:5:6:7:8", stun_configurations_[0].server.hostname());
|
||||
EXPECT_EQ(3478, stun_configurations_[0].server.port());
|
||||
stun_configurations_.clear();
|
||||
EXPECT_EQ(1U, stun_servers_.size());
|
||||
EXPECT_EQ("1:2:3:4:5:6:7:8", stun_servers_.begin()->hostname());
|
||||
EXPECT_EQ(3478, stun_servers_.begin()->port());
|
||||
stun_servers_.clear();
|
||||
|
||||
EXPECT_TRUE(ParseUrl("stun:hostname"));
|
||||
EXPECT_EQ(1U, stun_configurations_.size());
|
||||
EXPECT_EQ("hostname", stun_configurations_[0].server.hostname());
|
||||
EXPECT_EQ(3478, stun_configurations_[0].server.port());
|
||||
stun_configurations_.clear();
|
||||
EXPECT_EQ(1U, stun_servers_.size());
|
||||
EXPECT_EQ("hostname", stun_servers_.begin()->hostname());
|
||||
EXPECT_EQ(3478, stun_servers_.begin()->port());
|
||||
stun_servers_.clear();
|
||||
|
||||
// Try some invalid hostname:port strings.
|
||||
EXPECT_FALSE(ParseUrl("stun:hostname:99a99"));
|
||||
EXPECT_FALSE(ParseUrl("stun:hostname:-1"));
|
||||
EXPECT_FALSE(ParseUrl("stun:hostname:port:more"));
|
||||
EXPECT_FALSE(ParseUrl("stun:hostname:port more"));
|
||||
EXPECT_FALSE(ParseUrl("stun:hostname:"));
|
||||
EXPECT_FALSE(ParseUrl("stun:[1:2:3:4:5:6:7:8]junk:1000"));
|
||||
EXPECT_FALSE(ParseUrl("stun::5555"));
|
||||
@ -1978,14 +1976,14 @@ TEST_F(IceServerParsingTest, ParseHostnameAndPort) {
|
||||
// Test parsing the "?transport=xxx" part of the URL.
|
||||
TEST_F(IceServerParsingTest, ParseTransport) {
|
||||
EXPECT_TRUE(ParseUrl("turn:hostname:1234?transport=tcp"));
|
||||
EXPECT_EQ(1U, turn_configurations_.size());
|
||||
EXPECT_EQ("tcp", turn_configurations_[0].transport_type);
|
||||
turn_configurations_.clear();
|
||||
EXPECT_EQ(1U, turn_servers_.size());
|
||||
EXPECT_EQ(cricket::PROTO_TCP, turn_servers_[0].ports[0].proto);
|
||||
turn_servers_.clear();
|
||||
|
||||
EXPECT_TRUE(ParseUrl("turn:hostname?transport=udp"));
|
||||
EXPECT_EQ(1U, turn_configurations_.size());
|
||||
EXPECT_EQ("udp", turn_configurations_[0].transport_type);
|
||||
turn_configurations_.clear();
|
||||
EXPECT_EQ(1U, turn_servers_.size());
|
||||
EXPECT_EQ(cricket::PROTO_UDP, turn_servers_[0].ports[0].proto);
|
||||
turn_servers_.clear();
|
||||
|
||||
EXPECT_FALSE(ParseUrl("turn:hostname?transport=invalid"));
|
||||
}
|
||||
@ -1993,9 +1991,9 @@ TEST_F(IceServerParsingTest, ParseTransport) {
|
||||
// Test parsing ICE username contained in URL.
|
||||
TEST_F(IceServerParsingTest, ParseUsername) {
|
||||
EXPECT_TRUE(ParseUrl("turn:user@hostname"));
|
||||
EXPECT_EQ(1U, turn_configurations_.size());
|
||||
EXPECT_EQ("user", turn_configurations_[0].username);
|
||||
turn_configurations_.clear();
|
||||
EXPECT_EQ(1U, turn_servers_.size());
|
||||
EXPECT_EQ("user", turn_servers_[0].credentials.username);
|
||||
turn_servers_.clear();
|
||||
|
||||
EXPECT_FALSE(ParseUrl("turn:@hostname"));
|
||||
EXPECT_FALSE(ParseUrl("turn:username@"));
|
||||
@ -2004,12 +2002,12 @@ TEST_F(IceServerParsingTest, ParseUsername) {
|
||||
}
|
||||
|
||||
// Test that username and password from IceServer is copied into the resulting
|
||||
// TurnConfiguration.
|
||||
// RelayServerConfig.
|
||||
TEST_F(IceServerParsingTest, CopyUsernameAndPasswordFromIceServer) {
|
||||
EXPECT_TRUE(ParseUrl("turn:hostname", "username", "password"));
|
||||
EXPECT_EQ(1U, turn_configurations_.size());
|
||||
EXPECT_EQ("username", turn_configurations_[0].username);
|
||||
EXPECT_EQ("password", turn_configurations_[0].password);
|
||||
EXPECT_EQ(1U, turn_servers_.size());
|
||||
EXPECT_EQ("username", turn_servers_[0].credentials.username);
|
||||
EXPECT_EQ("password", turn_servers_[0].credentials.password);
|
||||
}
|
||||
|
||||
// Ensure that if a server has multiple URLs, each one is parsed.
|
||||
@ -2019,10 +2017,9 @@ TEST_F(IceServerParsingTest, ParseMultipleUrls) {
|
||||
server.urls.push_back("stun:hostname");
|
||||
server.urls.push_back("turn:hostname");
|
||||
servers.push_back(server);
|
||||
EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_configurations_,
|
||||
&turn_configurations_));
|
||||
EXPECT_EQ(1U, stun_configurations_.size());
|
||||
EXPECT_EQ(1U, turn_configurations_.size());
|
||||
EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_));
|
||||
EXPECT_EQ(1U, stun_servers_.size());
|
||||
EXPECT_EQ(1U, turn_servers_.size());
|
||||
}
|
||||
|
||||
#endif // if !defined(THREAD_SANITIZER)
|
||||
|
||||
@ -37,7 +37,6 @@
|
||||
#include "talk/app/webrtc/peerconnection.h"
|
||||
#include "talk/app/webrtc/peerconnectionfactoryproxy.h"
|
||||
#include "talk/app/webrtc/peerconnectionproxy.h"
|
||||
#include "talk/app/webrtc/portallocatorfactory.h"
|
||||
#include "talk/app/webrtc/videosource.h"
|
||||
#include "talk/app/webrtc/videosourceproxy.h"
|
||||
#include "talk/app/webrtc/videotrack.h"
|
||||
@ -157,7 +156,6 @@ PeerConnectionFactory::PeerConnectionFactory(
|
||||
PeerConnectionFactory::~PeerConnectionFactory() {
|
||||
RTC_DCHECK(signaling_thread_->IsCurrent());
|
||||
channel_manager_.reset(nullptr);
|
||||
default_allocator_factory_ = nullptr;
|
||||
|
||||
// Make sure |worker_thread_| and |signaling_thread_| outlive
|
||||
// |dtls_identity_store_|, |default_socket_factory_| and
|
||||
@ -177,11 +175,6 @@ bool PeerConnectionFactory::Initialize() {
|
||||
RTC_DCHECK(signaling_thread_->IsCurrent());
|
||||
rtc::InitRandom(rtc::Time());
|
||||
|
||||
default_allocator_factory_ = PortAllocatorFactory::Create(worker_thread_);
|
||||
if (!default_allocator_factory_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
default_network_manager_.reset(new rtc::BasicNetworkManager());
|
||||
if (!default_network_manager_) {
|
||||
return false;
|
||||
@ -252,37 +245,6 @@ void PeerConnectionFactory::StopRtcEventLog() {
|
||||
channel_manager_->StopRtcEventLog();
|
||||
}
|
||||
|
||||
rtc::scoped_refptr<PeerConnectionInterface>
|
||||
PeerConnectionFactory::CreatePeerConnection(
|
||||
const PeerConnectionInterface::RTCConfiguration& configuration,
|
||||
const MediaConstraintsInterface* constraints,
|
||||
PortAllocatorFactoryInterface* allocator_factory,
|
||||
rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
|
||||
PeerConnectionObserver* observer) {
|
||||
RTC_DCHECK(signaling_thread_->IsCurrent());
|
||||
RTC_DCHECK(allocator_factory || default_allocator_factory_);
|
||||
|
||||
if (!dtls_identity_store.get()) {
|
||||
// Because |pc|->Initialize takes ownership of the store we need a new
|
||||
// wrapper object that can be deleted without deleting the underlying
|
||||
// |dtls_identity_store_|, protecting it from being deleted multiple times.
|
||||
dtls_identity_store.reset(
|
||||
new DtlsIdentityStoreWrapper(dtls_identity_store_));
|
||||
}
|
||||
|
||||
PortAllocatorFactoryInterface* chosen_allocator_factory =
|
||||
allocator_factory ? allocator_factory : default_allocator_factory_.get();
|
||||
chosen_allocator_factory->SetNetworkIgnoreMask(options_.network_ignore_mask);
|
||||
|
||||
rtc::scoped_refptr<PeerConnection> pc(
|
||||
new rtc::RefCountedObject<PeerConnection>(this));
|
||||
if (!pc->Initialize(configuration, constraints, chosen_allocator_factory,
|
||||
std::move(dtls_identity_store), observer)) {
|
||||
return NULL;
|
||||
}
|
||||
return PeerConnectionProxy::Create(signaling_thread(), pc);
|
||||
}
|
||||
|
||||
rtc::scoped_refptr<PeerConnectionInterface>
|
||||
PeerConnectionFactory::CreatePeerConnection(
|
||||
const PeerConnectionInterface::RTCConfiguration& configuration,
|
||||
@ -304,8 +266,7 @@ PeerConnectionFactory::CreatePeerConnection(
|
||||
allocator.reset(new cricket::BasicPortAllocator(
|
||||
default_network_manager_.get(), default_socket_factory_.get()));
|
||||
}
|
||||
default_network_manager_->set_network_ignore_mask(
|
||||
options_.network_ignore_mask);
|
||||
allocator->SetNetworkIgnoreMask(options_.network_ignore_mask);
|
||||
|
||||
rtc::scoped_refptr<PeerConnection> pc(
|
||||
new rtc::RefCountedObject<PeerConnection>(this));
|
||||
|
||||
@ -55,17 +55,6 @@ class PeerConnectionFactory : public PeerConnectionFactoryInterface {
|
||||
options_ = options;
|
||||
}
|
||||
|
||||
// webrtc::PeerConnectionFactoryInterface override;
|
||||
// TODO(deadbeef): Get rid of this overload once clients are moved to the
|
||||
// new version.
|
||||
rtc::scoped_refptr<PeerConnectionInterface>
|
||||
CreatePeerConnection(
|
||||
const PeerConnectionInterface::RTCConfiguration& configuration,
|
||||
const MediaConstraintsInterface* constraints,
|
||||
PortAllocatorFactoryInterface* allocator_factory,
|
||||
rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
|
||||
PeerConnectionObserver* observer) override;
|
||||
|
||||
rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
|
||||
const PeerConnectionInterface::RTCConfiguration& configuration,
|
||||
const MediaConstraintsInterface* constraints,
|
||||
@ -121,7 +110,6 @@ class PeerConnectionFactory : public PeerConnectionFactoryInterface {
|
||||
rtc::Thread* signaling_thread_;
|
||||
rtc::Thread* worker_thread_;
|
||||
Options options_;
|
||||
rtc::scoped_refptr<PortAllocatorFactoryInterface> default_allocator_factory_;
|
||||
// External Audio device used for audio playback.
|
||||
rtc::scoped_refptr<AudioDeviceModule> default_adm_;
|
||||
rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
|
||||
|
||||
@ -28,7 +28,6 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "talk/app/webrtc/fakeportallocatorfactory.h"
|
||||
#include "talk/app/webrtc/mediastreaminterface.h"
|
||||
#include "talk/app/webrtc/peerconnectionfactory.h"
|
||||
#include "talk/app/webrtc/test/fakedtlsidentitystore.h"
|
||||
@ -40,6 +39,7 @@
|
||||
#include "webrtc/base/gunit.h"
|
||||
#include "webrtc/base/scoped_ptr.h"
|
||||
#include "webrtc/base/thread.h"
|
||||
#include "webrtc/p2p/client/fakeportallocator.h"
|
||||
|
||||
using webrtc::DataChannelInterface;
|
||||
using webrtc::DtlsIdentityStoreInterface;
|
||||
@ -48,17 +48,11 @@ using webrtc::MediaStreamInterface;
|
||||
using webrtc::PeerConnectionFactoryInterface;
|
||||
using webrtc::PeerConnectionInterface;
|
||||
using webrtc::PeerConnectionObserver;
|
||||
using webrtc::PortAllocatorFactoryInterface;
|
||||
using webrtc::VideoSourceInterface;
|
||||
using webrtc::VideoTrackInterface;
|
||||
|
||||
namespace {
|
||||
|
||||
typedef std::vector<PortAllocatorFactoryInterface::StunConfiguration>
|
||||
StunConfigurations;
|
||||
typedef std::vector<PortAllocatorFactoryInterface::TurnConfiguration>
|
||||
TurnConfigurations;
|
||||
|
||||
static const char kStunIceServer[] = "stun:stun.l.google.com:19302";
|
||||
static const char kTurnIceServer[] = "turn:test%40hello.com@test.com:1234";
|
||||
static const char kTurnIceServerWithTransport[] =
|
||||
@ -111,41 +105,39 @@ class PeerConnectionFactoryTest : public testing::Test {
|
||||
NULL);
|
||||
|
||||
ASSERT_TRUE(factory_.get() != NULL);
|
||||
allocator_factory_ = webrtc::FakePortAllocatorFactory::Create();
|
||||
port_allocator_.reset(
|
||||
new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
|
||||
raw_port_allocator_ = port_allocator_.get();
|
||||
}
|
||||
|
||||
protected:
|
||||
void VerifyStunConfigurations(StunConfigurations stun_config) {
|
||||
webrtc::FakePortAllocatorFactory* allocator =
|
||||
static_cast<webrtc::FakePortAllocatorFactory*>(
|
||||
allocator_factory_.get());
|
||||
ASSERT_TRUE(allocator != NULL);
|
||||
EXPECT_EQ(stun_config.size(), allocator->stun_configs().size());
|
||||
for (size_t i = 0; i < stun_config.size(); ++i) {
|
||||
EXPECT_EQ(stun_config[i].server.ToString(),
|
||||
allocator->stun_configs()[i].server.ToString());
|
||||
}
|
||||
void VerifyStunServers(cricket::ServerAddresses stun_servers) {
|
||||
EXPECT_EQ(stun_servers, raw_port_allocator_->stun_servers());
|
||||
}
|
||||
|
||||
void VerifyTurnConfigurations(TurnConfigurations turn_config) {
|
||||
webrtc::FakePortAllocatorFactory* allocator =
|
||||
static_cast<webrtc::FakePortAllocatorFactory*>(
|
||||
allocator_factory_.get());
|
||||
ASSERT_TRUE(allocator != NULL);
|
||||
EXPECT_EQ(turn_config.size(), allocator->turn_configs().size());
|
||||
for (size_t i = 0; i < turn_config.size(); ++i) {
|
||||
EXPECT_EQ(turn_config[i].server.ToString(),
|
||||
allocator->turn_configs()[i].server.ToString());
|
||||
EXPECT_EQ(turn_config[i].username, allocator->turn_configs()[i].username);
|
||||
EXPECT_EQ(turn_config[i].password, allocator->turn_configs()[i].password);
|
||||
EXPECT_EQ(turn_config[i].transport_type,
|
||||
allocator->turn_configs()[i].transport_type);
|
||||
void VerifyTurnServers(std::vector<cricket::RelayServerConfig> turn_servers) {
|
||||
EXPECT_EQ(turn_servers.size(), raw_port_allocator_->turn_servers().size());
|
||||
for (size_t i = 0; i < turn_servers.size(); ++i) {
|
||||
ASSERT_EQ(1u, turn_servers[i].ports.size());
|
||||
EXPECT_EQ(1u, raw_port_allocator_->turn_servers()[i].ports.size());
|
||||
EXPECT_EQ(
|
||||
turn_servers[i].ports[0].address.ToString(),
|
||||
raw_port_allocator_->turn_servers()[i].ports[0].address.ToString());
|
||||
EXPECT_EQ(turn_servers[i].ports[0].proto,
|
||||
raw_port_allocator_->turn_servers()[i].ports[0].proto);
|
||||
EXPECT_EQ(turn_servers[i].credentials.username,
|
||||
raw_port_allocator_->turn_servers()[i].credentials.username);
|
||||
EXPECT_EQ(turn_servers[i].credentials.password,
|
||||
raw_port_allocator_->turn_servers()[i].credentials.password);
|
||||
}
|
||||
}
|
||||
|
||||
rtc::scoped_refptr<PeerConnectionFactoryInterface> factory_;
|
||||
NullPeerConnectionObserver observer_;
|
||||
rtc::scoped_refptr<PortAllocatorFactoryInterface> allocator_factory_;
|
||||
rtc::scoped_ptr<cricket::FakePortAllocator> port_allocator_;
|
||||
// Since the PC owns the port allocator after it's been initialized,
|
||||
// this should only be used when known to be safe.
|
||||
cricket::FakePortAllocator* raw_port_allocator_;
|
||||
};
|
||||
|
||||
// Verify creation of PeerConnection using internal ADM, video factory and
|
||||
@ -155,12 +147,12 @@ TEST(PeerConnectionFactoryTestInternal, CreatePCUsingInternalModules) {
|
||||
webrtc::CreatePeerConnectionFactory());
|
||||
|
||||
NullPeerConnectionObserver observer;
|
||||
webrtc::PeerConnectionInterface::IceServers servers;
|
||||
webrtc::PeerConnectionInterface::RTCConfiguration config;
|
||||
|
||||
rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store(
|
||||
new FakeDtlsIdentityStore());
|
||||
rtc::scoped_refptr<PeerConnectionInterface> pc(factory->CreatePeerConnection(
|
||||
servers, nullptr, nullptr, std::move(dtls_identity_store), &observer));
|
||||
config, nullptr, nullptr, std::move(dtls_identity_store), &observer));
|
||||
|
||||
EXPECT_TRUE(pc.get() != nullptr);
|
||||
}
|
||||
@ -181,22 +173,21 @@ TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServers) {
|
||||
rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store(
|
||||
new FakeDtlsIdentityStore());
|
||||
rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
|
||||
config, nullptr, allocator_factory_.get(), std::move(dtls_identity_store),
|
||||
&observer_));
|
||||
EXPECT_TRUE(pc.get() != NULL);
|
||||
StunConfigurations stun_configs;
|
||||
webrtc::PortAllocatorFactoryInterface::StunConfiguration stun1(
|
||||
"stun.l.google.com", 19302);
|
||||
stun_configs.push_back(stun1);
|
||||
VerifyStunConfigurations(stun_configs);
|
||||
TurnConfigurations turn_configs;
|
||||
webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1(
|
||||
"test.com", 1234, "test@hello.com", kTurnPassword, "udp", false);
|
||||
turn_configs.push_back(turn1);
|
||||
webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn2(
|
||||
"hello.com", kDefaultStunPort, "test", kTurnPassword, "tcp", false);
|
||||
turn_configs.push_back(turn2);
|
||||
VerifyTurnConfigurations(turn_configs);
|
||||
config, nullptr, std::move(port_allocator_),
|
||||
std::move(dtls_identity_store), &observer_));
|
||||
ASSERT_TRUE(pc.get() != NULL);
|
||||
cricket::ServerAddresses stun_servers;
|
||||
rtc::SocketAddress stun1("stun.l.google.com", 19302);
|
||||
stun_servers.insert(stun1);
|
||||
VerifyStunServers(stun_servers);
|
||||
std::vector<cricket::RelayServerConfig> turn_servers;
|
||||
cricket::RelayServerConfig turn1("test.com", 1234, "test@hello.com",
|
||||
kTurnPassword, cricket::PROTO_UDP, false);
|
||||
turn_servers.push_back(turn1);
|
||||
cricket::RelayServerConfig turn2("hello.com", kDefaultStunPort, "test",
|
||||
kTurnPassword, cricket::PROTO_TCP, false);
|
||||
turn_servers.push_back(turn2);
|
||||
VerifyTurnServers(turn_servers);
|
||||
}
|
||||
|
||||
// This test verifies creation of PeerConnection with valid STUN and TURN
|
||||
@ -212,58 +203,21 @@ TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServersUrls) {
|
||||
rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store(
|
||||
new FakeDtlsIdentityStore());
|
||||
rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
|
||||
config, nullptr, allocator_factory_.get(), std::move(dtls_identity_store),
|
||||
&observer_));
|
||||
EXPECT_TRUE(pc.get() != NULL);
|
||||
StunConfigurations stun_configs;
|
||||
webrtc::PortAllocatorFactoryInterface::StunConfiguration stun1(
|
||||
"stun.l.google.com", 19302);
|
||||
stun_configs.push_back(stun1);
|
||||
VerifyStunConfigurations(stun_configs);
|
||||
TurnConfigurations turn_configs;
|
||||
webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1(
|
||||
"test.com", 1234, "test@hello.com", kTurnPassword, "udp", false);
|
||||
turn_configs.push_back(turn1);
|
||||
webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn2(
|
||||
"hello.com", kDefaultStunPort, "test", kTurnPassword, "tcp", false);
|
||||
turn_configs.push_back(turn2);
|
||||
VerifyTurnConfigurations(turn_configs);
|
||||
}
|
||||
|
||||
// This test verifies creation of PeerConnection with valid STUN and TURN
|
||||
// configuration. Also verifies the URL's parsed correctly as expected.
|
||||
// This version doesn't use RTCConfiguration.
|
||||
// TODO(mallinath) - Remove this method after clients start using RTCConfig.
|
||||
TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServersOldSignature) {
|
||||
webrtc::PeerConnectionInterface::IceServers ice_servers;
|
||||
webrtc::PeerConnectionInterface::IceServer ice_server;
|
||||
ice_server.uri = kStunIceServer;
|
||||
ice_servers.push_back(ice_server);
|
||||
ice_server.uri = kTurnIceServer;
|
||||
ice_server.password = kTurnPassword;
|
||||
ice_servers.push_back(ice_server);
|
||||
ice_server.uri = kTurnIceServerWithTransport;
|
||||
ice_server.password = kTurnPassword;
|
||||
ice_servers.push_back(ice_server);
|
||||
rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store(
|
||||
new FakeDtlsIdentityStore());
|
||||
rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
|
||||
ice_servers, nullptr, allocator_factory_.get(),
|
||||
config, nullptr, std::move(port_allocator_),
|
||||
std::move(dtls_identity_store), &observer_));
|
||||
EXPECT_TRUE(pc.get() != NULL);
|
||||
StunConfigurations stun_configs;
|
||||
webrtc::PortAllocatorFactoryInterface::StunConfiguration stun1(
|
||||
"stun.l.google.com", 19302);
|
||||
stun_configs.push_back(stun1);
|
||||
VerifyStunConfigurations(stun_configs);
|
||||
TurnConfigurations turn_configs;
|
||||
webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1(
|
||||
"test.com", 1234, "test@hello.com", kTurnPassword, "udp", false);
|
||||
turn_configs.push_back(turn1);
|
||||
webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn2(
|
||||
"hello.com", kDefaultStunPort, "test", kTurnPassword, "tcp", false);
|
||||
turn_configs.push_back(turn2);
|
||||
VerifyTurnConfigurations(turn_configs);
|
||||
ASSERT_TRUE(pc.get() != NULL);
|
||||
cricket::ServerAddresses stun_servers;
|
||||
rtc::SocketAddress stun1("stun.l.google.com", 19302);
|
||||
stun_servers.insert(stun1);
|
||||
VerifyStunServers(stun_servers);
|
||||
std::vector<cricket::RelayServerConfig> turn_servers;
|
||||
cricket::RelayServerConfig turn1("test.com", 1234, "test@hello.com",
|
||||
kTurnPassword, cricket::PROTO_UDP, false);
|
||||
turn_servers.push_back(turn1);
|
||||
cricket::RelayServerConfig turn2("hello.com", kDefaultStunPort, "test",
|
||||
kTurnPassword, cricket::PROTO_TCP, false);
|
||||
turn_servers.push_back(turn2);
|
||||
VerifyTurnServers(turn_servers);
|
||||
}
|
||||
|
||||
TEST_F(PeerConnectionFactoryTest, CreatePCUsingNoUsernameInUri) {
|
||||
@ -278,14 +232,14 @@ TEST_F(PeerConnectionFactoryTest, CreatePCUsingNoUsernameInUri) {
|
||||
rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store(
|
||||
new FakeDtlsIdentityStore());
|
||||
rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
|
||||
config, nullptr, allocator_factory_.get(), std::move(dtls_identity_store),
|
||||
&observer_));
|
||||
EXPECT_TRUE(pc.get() != NULL);
|
||||
TurnConfigurations turn_configs;
|
||||
webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn(
|
||||
"test.com", 1234, kTurnUsername, kTurnPassword, "udp", false);
|
||||
turn_configs.push_back(turn);
|
||||
VerifyTurnConfigurations(turn_configs);
|
||||
config, nullptr, std::move(port_allocator_),
|
||||
std::move(dtls_identity_store), &observer_));
|
||||
ASSERT_TRUE(pc.get() != NULL);
|
||||
std::vector<cricket::RelayServerConfig> turn_servers;
|
||||
cricket::RelayServerConfig turn("test.com", 1234, kTurnUsername,
|
||||
kTurnPassword, cricket::PROTO_UDP, false);
|
||||
turn_servers.push_back(turn);
|
||||
VerifyTurnServers(turn_servers);
|
||||
}
|
||||
|
||||
// This test verifies the PeerConnection created properly with TURN url which
|
||||
@ -299,14 +253,14 @@ TEST_F(PeerConnectionFactoryTest, CreatePCUsingTurnUrlWithTransportParam) {
|
||||
rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store(
|
||||
new FakeDtlsIdentityStore());
|
||||
rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
|
||||
config, nullptr, allocator_factory_.get(), std::move(dtls_identity_store),
|
||||
&observer_));
|
||||
EXPECT_TRUE(pc.get() != NULL);
|
||||
TurnConfigurations turn_configs;
|
||||
webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn(
|
||||
"hello.com", kDefaultStunPort, "test", kTurnPassword, "tcp", false);
|
||||
turn_configs.push_back(turn);
|
||||
VerifyTurnConfigurations(turn_configs);
|
||||
config, nullptr, std::move(port_allocator_),
|
||||
std::move(dtls_identity_store), &observer_));
|
||||
ASSERT_TRUE(pc.get() != NULL);
|
||||
std::vector<cricket::RelayServerConfig> turn_servers;
|
||||
cricket::RelayServerConfig turn("hello.com", kDefaultStunPort, "test",
|
||||
kTurnPassword, cricket::PROTO_TCP, false);
|
||||
turn_servers.push_back(turn);
|
||||
VerifyTurnServers(turn_servers);
|
||||
}
|
||||
|
||||
TEST_F(PeerConnectionFactoryTest, CreatePCUsingSecureTurnUrl) {
|
||||
@ -324,22 +278,22 @@ TEST_F(PeerConnectionFactoryTest, CreatePCUsingSecureTurnUrl) {
|
||||
rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store(
|
||||
new FakeDtlsIdentityStore());
|
||||
rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
|
||||
config, nullptr, allocator_factory_.get(), std::move(dtls_identity_store),
|
||||
&observer_));
|
||||
EXPECT_TRUE(pc.get() != NULL);
|
||||
TurnConfigurations turn_configs;
|
||||
webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1(
|
||||
"hello.com", kDefaultStunTlsPort, "test", kTurnPassword, "tcp", true);
|
||||
turn_configs.push_back(turn1);
|
||||
config, nullptr, std::move(port_allocator_),
|
||||
std::move(dtls_identity_store), &observer_));
|
||||
ASSERT_TRUE(pc.get() != NULL);
|
||||
std::vector<cricket::RelayServerConfig> turn_servers;
|
||||
cricket::RelayServerConfig turn1("hello.com", kDefaultStunTlsPort, "test",
|
||||
kTurnPassword, cricket::PROTO_TCP, true);
|
||||
turn_servers.push_back(turn1);
|
||||
// TURNS with transport param should be default to tcp.
|
||||
webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn2(
|
||||
"hello.com", 443, "test_no_transport", kTurnPassword, "tcp", true);
|
||||
turn_configs.push_back(turn2);
|
||||
webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn3(
|
||||
"hello.com", kDefaultStunTlsPort, "test_no_transport",
|
||||
kTurnPassword, "tcp", true);
|
||||
turn_configs.push_back(turn3);
|
||||
VerifyTurnConfigurations(turn_configs);
|
||||
cricket::RelayServerConfig turn2("hello.com", 443, "test_no_transport",
|
||||
kTurnPassword, cricket::PROTO_TCP, true);
|
||||
turn_servers.push_back(turn2);
|
||||
cricket::RelayServerConfig turn3("hello.com", kDefaultStunTlsPort,
|
||||
"test_no_transport", kTurnPassword,
|
||||
cricket::PROTO_TCP, true);
|
||||
turn_servers.push_back(turn3);
|
||||
VerifyTurnServers(turn_servers);
|
||||
}
|
||||
|
||||
TEST_F(PeerConnectionFactoryTest, CreatePCUsingIPLiteralAddress) {
|
||||
@ -359,29 +313,25 @@ TEST_F(PeerConnectionFactoryTest, CreatePCUsingIPLiteralAddress) {
|
||||
rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store(
|
||||
new FakeDtlsIdentityStore());
|
||||
rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
|
||||
config, nullptr, allocator_factory_.get(), std::move(dtls_identity_store),
|
||||
&observer_));
|
||||
EXPECT_TRUE(pc.get() != NULL);
|
||||
StunConfigurations stun_configs;
|
||||
webrtc::PortAllocatorFactoryInterface::StunConfiguration stun1(
|
||||
"1.2.3.4", 1234);
|
||||
stun_configs.push_back(stun1);
|
||||
webrtc::PortAllocatorFactoryInterface::StunConfiguration stun2(
|
||||
"1.2.3.4", 3478);
|
||||
stun_configs.push_back(stun2); // Default port
|
||||
webrtc::PortAllocatorFactoryInterface::StunConfiguration stun3(
|
||||
"2401:fa00:4::", 1234);
|
||||
stun_configs.push_back(stun3);
|
||||
webrtc::PortAllocatorFactoryInterface::StunConfiguration stun4(
|
||||
"2401:fa00:4::", 3478);
|
||||
stun_configs.push_back(stun4); // Default port
|
||||
VerifyStunConfigurations(stun_configs);
|
||||
config, nullptr, std::move(port_allocator_),
|
||||
std::move(dtls_identity_store), &observer_));
|
||||
ASSERT_TRUE(pc.get() != NULL);
|
||||
cricket::ServerAddresses stun_servers;
|
||||
rtc::SocketAddress stun1("1.2.3.4", 1234);
|
||||
stun_servers.insert(stun1);
|
||||
rtc::SocketAddress stun2("1.2.3.4", 3478);
|
||||
stun_servers.insert(stun2); // Default port
|
||||
rtc::SocketAddress stun3("2401:fa00:4::", 1234);
|
||||
stun_servers.insert(stun3);
|
||||
rtc::SocketAddress stun4("2401:fa00:4::", 3478);
|
||||
stun_servers.insert(stun4); // Default port
|
||||
VerifyStunServers(stun_servers);
|
||||
|
||||
TurnConfigurations turn_configs;
|
||||
webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1(
|
||||
"2401:fa00:4::", 1234, "test", kTurnPassword, "udp", false);
|
||||
turn_configs.push_back(turn1);
|
||||
VerifyTurnConfigurations(turn_configs);
|
||||
std::vector<cricket::RelayServerConfig> turn_servers;
|
||||
cricket::RelayServerConfig turn1("2401:fa00:4::", 1234, "test", kTurnPassword,
|
||||
cricket::PROTO_UDP, false);
|
||||
turn_servers.push_back(turn1);
|
||||
VerifyTurnServers(turn_servers);
|
||||
}
|
||||
|
||||
// This test verifies the captured stream is rendered locally using a
|
||||
|
||||
@ -41,16 +41,6 @@ BEGIN_PROXY_MAP(PeerConnectionFactory)
|
||||
PROXY_METHOD1(void, SetOptions, const Options&)
|
||||
// Can't use PROXY_METHOD5 because scoped_ptr must be moved.
|
||||
// TODO(tommi,hbos): Use of templates to support scoped_ptr?
|
||||
rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
|
||||
const PeerConnectionInterface::RTCConfiguration& a1,
|
||||
const MediaConstraintsInterface* a2,
|
||||
PortAllocatorFactoryInterface* a3,
|
||||
rtc::scoped_ptr<DtlsIdentityStoreInterface> a4,
|
||||
PeerConnectionObserver* a5) override {
|
||||
return owner_thread_->Invoke<rtc::scoped_refptr<PeerConnectionInterface>>(
|
||||
rtc::Bind(&PeerConnectionFactoryProxy::CreatePeerConnection_ot1, this,
|
||||
a1, a2, a3, a4.release(), a5));
|
||||
}
|
||||
rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
|
||||
const PeerConnectionInterface::RTCConfiguration& a1,
|
||||
const MediaConstraintsInterface* a2,
|
||||
@ -58,7 +48,7 @@ BEGIN_PROXY_MAP(PeerConnectionFactory)
|
||||
rtc::scoped_ptr<DtlsIdentityStoreInterface> a4,
|
||||
PeerConnectionObserver* a5) override {
|
||||
return owner_thread_->Invoke<rtc::scoped_refptr<PeerConnectionInterface>>(
|
||||
rtc::Bind(&PeerConnectionFactoryProxy::CreatePeerConnection_ot2, this,
|
||||
rtc::Bind(&PeerConnectionFactoryProxy::CreatePeerConnection_ot, this,
|
||||
a1, a2, a3.release(), a4.release(), a5));
|
||||
}
|
||||
PROXY_METHOD1(rtc::scoped_refptr<MediaStreamInterface>,
|
||||
@ -78,17 +68,7 @@ BEGIN_PROXY_MAP(PeerConnectionFactory)
|
||||
PROXY_METHOD0(void, StopRtcEventLog)
|
||||
|
||||
private:
|
||||
rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection_ot1(
|
||||
const PeerConnectionInterface::RTCConfiguration& a1,
|
||||
const MediaConstraintsInterface* a2,
|
||||
PortAllocatorFactoryInterface* a3,
|
||||
DtlsIdentityStoreInterface* a4,
|
||||
PeerConnectionObserver* a5) {
|
||||
rtc::scoped_ptr<DtlsIdentityStoreInterface> ptr_a4(a4);
|
||||
return c_->CreatePeerConnection(a1, a2, a3, std::move(ptr_a4), a5);
|
||||
}
|
||||
|
||||
rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection_ot2(
|
||||
rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection_ot(
|
||||
const PeerConnectionInterface::RTCConfiguration& a1,
|
||||
const MediaConstraintsInterface* a2,
|
||||
cricket::PortAllocator* a3,
|
||||
|
||||
@ -489,51 +489,6 @@ class PeerConnectionObserver {
|
||||
~PeerConnectionObserver() {}
|
||||
};
|
||||
|
||||
// Factory class used for creating cricket::PortAllocator that is used
|
||||
// for ICE negotiation.
|
||||
class PortAllocatorFactoryInterface : public rtc::RefCountInterface {
|
||||
public:
|
||||
struct StunConfiguration {
|
||||
StunConfiguration(const std::string& address, int port)
|
||||
: server(address, port) {}
|
||||
// STUN server address and port.
|
||||
rtc::SocketAddress server;
|
||||
};
|
||||
|
||||
struct TurnConfiguration {
|
||||
TurnConfiguration(const std::string& address,
|
||||
int port,
|
||||
const std::string& username,
|
||||
const std::string& password,
|
||||
const std::string& transport_type,
|
||||
bool secure)
|
||||
: server(address, port),
|
||||
username(username),
|
||||
password(password),
|
||||
transport_type(transport_type),
|
||||
secure(secure) {}
|
||||
rtc::SocketAddress server;
|
||||
std::string username;
|
||||
std::string password;
|
||||
std::string transport_type;
|
||||
bool secure;
|
||||
};
|
||||
|
||||
virtual cricket::PortAllocator* CreatePortAllocator(
|
||||
const std::vector<StunConfiguration>& stun_servers,
|
||||
const std::vector<TurnConfiguration>& turn_configurations) = 0;
|
||||
|
||||
// TODO(phoglund): Make pure virtual when Chrome's factory implements this.
|
||||
// After this method is called, the port allocator should consider loopback
|
||||
// network interfaces as well.
|
||||
virtual void SetNetworkIgnoreMask(int network_ignore_mask) {
|
||||
}
|
||||
|
||||
protected:
|
||||
PortAllocatorFactoryInterface() {}
|
||||
~PortAllocatorFactoryInterface() {}
|
||||
};
|
||||
|
||||
// PeerConnectionFactoryInterface is the factory interface use for creating
|
||||
// PeerConnection, MediaStream and media tracks.
|
||||
// PeerConnectionFactoryInterface will create required libjingle threads,
|
||||
@ -541,7 +496,7 @@ class PortAllocatorFactoryInterface : public rtc::RefCountInterface {
|
||||
// If an application decides to provide its own threads and network
|
||||
// implementation of these classes it should use the alternate
|
||||
// CreatePeerConnectionFactory method which accepts threads as input and use the
|
||||
// CreatePeerConnection version that takes a PortAllocatorFactoryInterface as
|
||||
// CreatePeerConnection version that takes a PortAllocator as an
|
||||
// argument.
|
||||
class PeerConnectionFactoryInterface : public rtc::RefCountInterface {
|
||||
public:
|
||||
@ -571,45 +526,12 @@ class PeerConnectionFactoryInterface : public rtc::RefCountInterface {
|
||||
|
||||
virtual void SetOptions(const Options& options) = 0;
|
||||
|
||||
// TODO(deadbeef): Remove this overload of CreatePeerConnection once clients
|
||||
// are moved to the new version.
|
||||
virtual rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
|
||||
const PeerConnectionInterface::RTCConfiguration& configuration,
|
||||
const MediaConstraintsInterface* constraints,
|
||||
PortAllocatorFactoryInterface* allocator_factory,
|
||||
rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
|
||||
PeerConnectionObserver* observer) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// TODO(deadbeef): Make this pure virtual once it's implemented by all
|
||||
// subclasses.
|
||||
virtual rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
|
||||
const PeerConnectionInterface::RTCConfiguration& configuration,
|
||||
const MediaConstraintsInterface* constraints,
|
||||
rtc::scoped_ptr<cricket::PortAllocator> allocator,
|
||||
rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
|
||||
PeerConnectionObserver* observer) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// TODO(hbos): Remove below version after clients are updated to above method.
|
||||
// In latest W3C WebRTC draft, PC constructor will take RTCConfiguration,
|
||||
// and not IceServers. RTCConfiguration is made up of ice servers and
|
||||
// ice transport type.
|
||||
// http://dev.w3.org/2011/webrtc/editor/webrtc.html
|
||||
inline rtc::scoped_refptr<PeerConnectionInterface>
|
||||
CreatePeerConnection(
|
||||
const PeerConnectionInterface::IceServers& servers,
|
||||
const MediaConstraintsInterface* constraints,
|
||||
PortAllocatorFactoryInterface* allocator_factory,
|
||||
rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
|
||||
PeerConnectionObserver* observer) {
|
||||
PeerConnectionInterface::RTCConfiguration rtc_config;
|
||||
rtc_config.servers = servers;
|
||||
return CreatePeerConnection(rtc_config, constraints, allocator_factory,
|
||||
std::move(dtls_identity_store), observer);
|
||||
}
|
||||
PeerConnectionObserver* observer) = 0;
|
||||
|
||||
virtual rtc::scoped_refptr<MediaStreamInterface>
|
||||
CreateLocalMediaStream(const std::string& label) = 0;
|
||||
|
||||
@ -29,7 +29,6 @@
|
||||
#include <utility>
|
||||
|
||||
#include "talk/app/webrtc/audiotrack.h"
|
||||
#include "talk/app/webrtc/fakeportallocatorfactory.h"
|
||||
#include "talk/app/webrtc/jsepsessiondescription.h"
|
||||
#include "talk/app/webrtc/mediastream.h"
|
||||
#include "talk/app/webrtc/mediastreaminterface.h"
|
||||
@ -53,6 +52,7 @@
|
||||
#include "webrtc/base/sslstreamadapter.h"
|
||||
#include "webrtc/base/stringutils.h"
|
||||
#include "webrtc/base/thread.h"
|
||||
#include "webrtc/p2p/client/fakeportallocator.h"
|
||||
|
||||
static const char kStreamLabel1[] = "local_stream_1";
|
||||
static const char kStreamLabel2[] = "local_stream_2";
|
||||
@ -259,7 +259,6 @@ using webrtc::AudioTrackInterface;
|
||||
using webrtc::DataBuffer;
|
||||
using webrtc::DataChannelInterface;
|
||||
using webrtc::FakeConstraints;
|
||||
using webrtc::FakePortAllocatorFactory;
|
||||
using webrtc::IceCandidateInterface;
|
||||
using webrtc::MediaConstraintsInterface;
|
||||
using webrtc::MediaStream;
|
||||
@ -271,7 +270,6 @@ using webrtc::MockSetSessionDescriptionObserver;
|
||||
using webrtc::MockStatsObserver;
|
||||
using webrtc::PeerConnectionInterface;
|
||||
using webrtc::PeerConnectionObserver;
|
||||
using webrtc::PortAllocatorFactoryInterface;
|
||||
using webrtc::RtpReceiverInterface;
|
||||
using webrtc::RtpSenderInterface;
|
||||
using webrtc::SdpParseError;
|
||||
@ -534,15 +532,17 @@ class PeerConnectionInterfaceTest : public testing::Test {
|
||||
void CreatePeerConnection(const std::string& uri,
|
||||
const std::string& password,
|
||||
webrtc::MediaConstraintsInterface* constraints) {
|
||||
PeerConnectionInterface::RTCConfiguration config;
|
||||
PeerConnectionInterface::IceServer server;
|
||||
PeerConnectionInterface::IceServers servers;
|
||||
if (!uri.empty()) {
|
||||
server.uri = uri;
|
||||
server.password = password;
|
||||
servers.push_back(server);
|
||||
config.servers.push_back(server);
|
||||
}
|
||||
|
||||
port_allocator_factory_ = FakePortAllocatorFactory::Create();
|
||||
rtc::scoped_ptr<cricket::FakePortAllocator> port_allocator(
|
||||
new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
|
||||
port_allocator_ = port_allocator.get();
|
||||
|
||||
// DTLS does not work in a loopback call, so is disabled for most of the
|
||||
// tests in this file. We only create a FakeIdentityService if the test
|
||||
@ -564,7 +564,7 @@ class PeerConnectionInterfaceTest : public testing::Test {
|
||||
dtls_identity_store.reset(new FakeDtlsIdentityStore());
|
||||
}
|
||||
pc_ = pc_factory_->CreatePeerConnection(
|
||||
servers, constraints, port_allocator_factory_.get(),
|
||||
config, constraints, std::move(port_allocator),
|
||||
std::move(dtls_identity_store), &observer_);
|
||||
ASSERT_TRUE(pc_.get() != NULL);
|
||||
observer_.SetPeerConnectionInterface(pc_.get());
|
||||
@ -572,42 +572,38 @@ class PeerConnectionInterfaceTest : public testing::Test {
|
||||
}
|
||||
|
||||
void CreatePeerConnectionExpectFail(const std::string& uri) {
|
||||
PeerConnectionInterface::RTCConfiguration config;
|
||||
PeerConnectionInterface::IceServer server;
|
||||
PeerConnectionInterface::IceServers servers;
|
||||
server.uri = uri;
|
||||
servers.push_back(server);
|
||||
config.servers.push_back(server);
|
||||
|
||||
scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store;
|
||||
port_allocator_factory_ = FakePortAllocatorFactory::Create();
|
||||
scoped_refptr<PeerConnectionInterface> pc;
|
||||
pc = pc_factory_->CreatePeerConnection(
|
||||
servers, nullptr, port_allocator_factory_.get(),
|
||||
std::move(dtls_identity_store), &observer_);
|
||||
ASSERT_EQ(nullptr, pc);
|
||||
pc = pc_factory_->CreatePeerConnection(config, nullptr, nullptr, nullptr,
|
||||
&observer_);
|
||||
EXPECT_EQ(nullptr, pc);
|
||||
}
|
||||
|
||||
void CreatePeerConnectionWithDifferentConfigurations() {
|
||||
CreatePeerConnection(kStunAddressOnly, "", NULL);
|
||||
EXPECT_EQ(1u, port_allocator_factory_->stun_configs().size());
|
||||
EXPECT_EQ(0u, port_allocator_factory_->turn_configs().size());
|
||||
EXPECT_EQ("address",
|
||||
port_allocator_factory_->stun_configs()[0].server.hostname());
|
||||
EXPECT_EQ(1u, port_allocator_->stun_servers().size());
|
||||
EXPECT_EQ(0u, port_allocator_->turn_servers().size());
|
||||
EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
|
||||
EXPECT_EQ(kDefaultStunPort,
|
||||
port_allocator_factory_->stun_configs()[0].server.port());
|
||||
port_allocator_->stun_servers().begin()->port());
|
||||
|
||||
CreatePeerConnectionExpectFail(kStunInvalidPort);
|
||||
CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
|
||||
CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
|
||||
|
||||
CreatePeerConnection(kTurnIceServerUri, kTurnPassword, NULL);
|
||||
EXPECT_EQ(0u, port_allocator_factory_->stun_configs().size());
|
||||
EXPECT_EQ(1u, port_allocator_factory_->turn_configs().size());
|
||||
EXPECT_EQ(0u, port_allocator_->stun_servers().size());
|
||||
EXPECT_EQ(1u, port_allocator_->turn_servers().size());
|
||||
EXPECT_EQ(kTurnUsername,
|
||||
port_allocator_factory_->turn_configs()[0].username);
|
||||
port_allocator_->turn_servers()[0].credentials.username);
|
||||
EXPECT_EQ(kTurnPassword,
|
||||
port_allocator_factory_->turn_configs()[0].password);
|
||||
port_allocator_->turn_servers()[0].credentials.password);
|
||||
EXPECT_EQ(kTurnHostname,
|
||||
port_allocator_factory_->turn_configs()[0].server.hostname());
|
||||
port_allocator_->turn_servers()[0].ports[0].address.hostname());
|
||||
}
|
||||
|
||||
void ReleasePeerConnection() {
|
||||
@ -926,7 +922,7 @@ class PeerConnectionInterfaceTest : public testing::Test {
|
||||
ASSERT_TRUE(stream->AddTrack(video_track));
|
||||
}
|
||||
|
||||
scoped_refptr<FakePortAllocatorFactory> port_allocator_factory_;
|
||||
cricket::FakePortAllocator* port_allocator_ = nullptr;
|
||||
scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
|
||||
scoped_refptr<PeerConnectionInterface> pc_;
|
||||
MockPeerConnectionObserver observer_;
|
||||
@ -1729,10 +1725,9 @@ TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
|
||||
config.servers.push_back(server);
|
||||
EXPECT_TRUE(pc_->SetConfiguration(config));
|
||||
|
||||
cricket::FakePortAllocator* allocator =
|
||||
port_allocator_factory_->last_created_allocator();
|
||||
EXPECT_EQ(1u, allocator->stun_servers().size());
|
||||
EXPECT_EQ("test_hostname", allocator->stun_servers().begin()->hostname());
|
||||
EXPECT_EQ(1u, port_allocator_->stun_servers().size());
|
||||
EXPECT_EQ("test_hostname",
|
||||
port_allocator_->stun_servers().begin()->hostname());
|
||||
}
|
||||
|
||||
// Test that PeerConnection::Close changes the states to closed and all remote
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2004--2011 Google Inc.
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@ -24,69 +24,7 @@
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
// TODO(deadbeef): Remove this file once chromium build files no longer
|
||||
// reference it.
|
||||
|
||||
#include "talk/app/webrtc/portallocatorfactory.h"
|
||||
|
||||
#include "webrtc/p2p/base/basicpacketsocketfactory.h"
|
||||
#include "webrtc/p2p/client/basicportallocator.h"
|
||||
#include "webrtc/base/logging.h"
|
||||
#include "webrtc/base/network.h"
|
||||
#include "webrtc/base/thread.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
using rtc::scoped_ptr;
|
||||
|
||||
rtc::scoped_refptr<PortAllocatorFactoryInterface>
|
||||
PortAllocatorFactory::Create(
|
||||
rtc::Thread* worker_thread) {
|
||||
rtc::RefCountedObject<PortAllocatorFactory>* allocator =
|
||||
new rtc::RefCountedObject<PortAllocatorFactory>(worker_thread);
|
||||
return allocator;
|
||||
}
|
||||
|
||||
PortAllocatorFactory::PortAllocatorFactory(rtc::Thread* worker_thread)
|
||||
: network_manager_(new rtc::BasicNetworkManager()),
|
||||
socket_factory_(new rtc::BasicPacketSocketFactory(worker_thread)) {
|
||||
}
|
||||
|
||||
PortAllocatorFactory::~PortAllocatorFactory() {}
|
||||
|
||||
void PortAllocatorFactory::SetNetworkIgnoreMask(int network_ignore_mask) {
|
||||
network_manager_->set_network_ignore_mask(network_ignore_mask);
|
||||
}
|
||||
|
||||
cricket::PortAllocator* PortAllocatorFactory::CreatePortAllocator(
|
||||
const std::vector<StunConfiguration>& stun,
|
||||
const std::vector<TurnConfiguration>& turn) {
|
||||
cricket::ServerAddresses stun_hosts;
|
||||
typedef std::vector<StunConfiguration>::const_iterator StunIt;
|
||||
for (StunIt stun_it = stun.begin(); stun_it != stun.end(); ++stun_it) {
|
||||
stun_hosts.insert(stun_it->server);
|
||||
}
|
||||
|
||||
scoped_ptr<cricket::BasicPortAllocator> allocator(
|
||||
new cricket::BasicPortAllocator(
|
||||
network_manager_.get(), socket_factory_.get(), stun_hosts));
|
||||
|
||||
for (size_t i = 0; i < turn.size(); ++i) {
|
||||
cricket::RelayCredentials credentials(turn[i].username, turn[i].password);
|
||||
cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
|
||||
cricket::ProtocolType protocol;
|
||||
if (cricket::StringToProto(turn[i].transport_type.c_str(), &protocol)) {
|
||||
turn_server.ports.push_back(
|
||||
cricket::ProtocolAddress(turn[i].server, protocol, turn[i].secure));
|
||||
turn_server.credentials = credentials;
|
||||
// First in the list gets highest priority.
|
||||
turn_server.priority = static_cast<int>(turn.size() - i - 1);
|
||||
allocator->AddTurnServer(turn_server);
|
||||
} else {
|
||||
LOG(LS_WARNING) << "Ignoring TURN server " << turn[i].server << ". "
|
||||
<< "Reason= Incorrect " << turn[i].transport_type
|
||||
<< " transport parameter.";
|
||||
}
|
||||
}
|
||||
return allocator.release();
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -24,49 +24,10 @@
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
// This file defines the default implementation of
|
||||
// PortAllocatorFactoryInterface.
|
||||
// This implementation creates instances of cricket::HTTPPortAllocator and uses
|
||||
// the BasicNetworkManager and BasicPacketSocketFactory.
|
||||
// TODO(deadbeef): Remove this file once chromium build files no longer
|
||||
// reference it.
|
||||
|
||||
#ifndef TALK_APP_WEBRTC_PORTALLOCATORFACTORY_H_
|
||||
#define TALK_APP_WEBRTC_PORTALLOCATORFACTORY_H_
|
||||
|
||||
#include "talk/app/webrtc/peerconnectioninterface.h"
|
||||
#include "webrtc/base/scoped_ptr.h"
|
||||
|
||||
namespace cricket {
|
||||
class PortAllocator;
|
||||
}
|
||||
|
||||
namespace rtc {
|
||||
class BasicNetworkManager;
|
||||
class BasicPacketSocketFactory;
|
||||
}
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class PortAllocatorFactory : public PortAllocatorFactoryInterface {
|
||||
public:
|
||||
static rtc::scoped_refptr<PortAllocatorFactoryInterface> Create(
|
||||
rtc::Thread* worker_thread);
|
||||
|
||||
virtual cricket::PortAllocator* CreatePortAllocator(
|
||||
const std::vector<StunConfiguration>& stun,
|
||||
const std::vector<TurnConfiguration>& turn);
|
||||
|
||||
virtual void SetNetworkIgnoreMask(int network_ignore_mask);
|
||||
|
||||
protected:
|
||||
explicit PortAllocatorFactory(rtc::Thread* worker_thread);
|
||||
~PortAllocatorFactory();
|
||||
|
||||
private:
|
||||
rtc::scoped_ptr<rtc::BasicNetworkManager> network_manager_;
|
||||
rtc::scoped_ptr<rtc::BasicPacketSocketFactory> socket_factory_;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // TALK_APP_WEBRTC_PORTALLOCATORFACTORY_H_
|
||||
|
||||
@ -27,13 +27,13 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "talk/app/webrtc/fakeportallocatorfactory.h"
|
||||
#include "talk/app/webrtc/test/fakedtlsidentitystore.h"
|
||||
#include "talk/app/webrtc/test/fakeperiodicvideocapturer.h"
|
||||
#include "talk/app/webrtc/test/mockpeerconnectionobservers.h"
|
||||
#include "talk/app/webrtc/test/peerconnectiontestwrapper.h"
|
||||
#include "talk/app/webrtc/videosourceinterface.h"
|
||||
#include "webrtc/base/gunit.h"
|
||||
#include "webrtc/p2p/client/fakeportallocator.h"
|
||||
|
||||
static const char kStreamLabelBase[] = "stream_label";
|
||||
static const char kVideoTrackLabelBase[] = "video_track";
|
||||
@ -72,10 +72,8 @@ PeerConnectionTestWrapper::~PeerConnectionTestWrapper() {}
|
||||
|
||||
bool PeerConnectionTestWrapper::CreatePc(
|
||||
const MediaConstraintsInterface* constraints) {
|
||||
allocator_factory_ = webrtc::FakePortAllocatorFactory::Create();
|
||||
if (!allocator_factory_) {
|
||||
return false;
|
||||
}
|
||||
rtc::scoped_ptr<cricket::PortAllocator> port_allocator(
|
||||
new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
|
||||
|
||||
fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
|
||||
if (fake_audio_capture_module_ == NULL) {
|
||||
@ -89,16 +87,16 @@ bool PeerConnectionTestWrapper::CreatePc(
|
||||
return false;
|
||||
}
|
||||
|
||||
// CreatePeerConnection with IceServers.
|
||||
webrtc::PeerConnectionInterface::IceServers ice_servers;
|
||||
// CreatePeerConnection with RTCConfiguration.
|
||||
webrtc::PeerConnectionInterface::RTCConfiguration config;
|
||||
webrtc::PeerConnectionInterface::IceServer ice_server;
|
||||
ice_server.uri = "stun:stun.l.google.com:19302";
|
||||
ice_servers.push_back(ice_server);
|
||||
config.servers.push_back(ice_server);
|
||||
rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store(
|
||||
rtc::SSLStreamAdapter::HaveDtlsSrtp() ?
|
||||
new FakeDtlsIdentityStore() : nullptr);
|
||||
peer_connection_ = peer_connection_factory_->CreatePeerConnection(
|
||||
ice_servers, constraints, allocator_factory_.get(),
|
||||
config, constraints, std::move(port_allocator),
|
||||
std::move(dtls_identity_store), this);
|
||||
|
||||
return peer_connection_.get() != NULL;
|
||||
|
||||
@ -34,11 +34,6 @@
|
||||
#include "talk/app/webrtc/test/fakevideotrackrenderer.h"
|
||||
#include "webrtc/base/sigslot.h"
|
||||
|
||||
namespace webrtc {
|
||||
class DtlsIdentityStoreInterface;
|
||||
class PortAllocatorFactoryInterface;
|
||||
}
|
||||
|
||||
class PeerConnectionTestWrapper
|
||||
: public webrtc::PeerConnectionObserver,
|
||||
public webrtc::CreateSessionDescriptionObserver,
|
||||
@ -110,8 +105,6 @@ class PeerConnectionTestWrapper
|
||||
bool video, const webrtc::FakeConstraints& video_constraints);
|
||||
|
||||
std::string name_;
|
||||
rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface>
|
||||
allocator_factory_;
|
||||
rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
|
||||
rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
|
||||
peer_connection_factory_;
|
||||
|
||||
@ -731,7 +731,6 @@
|
||||
'app/webrtc/dtmfsender.cc',
|
||||
'app/webrtc/dtmfsender.h',
|
||||
'app/webrtc/dtmfsenderinterface.h',
|
||||
'app/webrtc/fakeportallocatorfactory.h',
|
||||
'app/webrtc/jsep.h',
|
||||
'app/webrtc/jsepicecandidate.cc',
|
||||
'app/webrtc/jsepicecandidate.h',
|
||||
@ -760,8 +759,6 @@
|
||||
'app/webrtc/peerconnectionfactoryproxy.h',
|
||||
'app/webrtc/peerconnectioninterface.h',
|
||||
'app/webrtc/peerconnectionproxy.h',
|
||||
'app/webrtc/portallocatorfactory.cc',
|
||||
'app/webrtc/portallocatorfactory.h',
|
||||
'app/webrtc/proxy.h',
|
||||
'app/webrtc/remoteaudiosource.cc',
|
||||
'app/webrtc/remoteaudiosource.h',
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
#define WEBRTC_BASE_FAKENETWORK_H_
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "webrtc/base/network.h"
|
||||
@ -31,7 +32,7 @@ class FakeNetworkManager : public NetworkManagerBase,
|
||||
public:
|
||||
FakeNetworkManager() : thread_(Thread::Current()) {}
|
||||
|
||||
typedef std::vector<SocketAddress> IfaceList;
|
||||
typedef std::vector<std::pair<SocketAddress, AdapterType>> IfaceList;
|
||||
|
||||
void AddInterface(const SocketAddress& iface) {
|
||||
// Ensure a unique name for the interface if its name is not given.
|
||||
@ -39,16 +40,22 @@ class FakeNetworkManager : public NetworkManagerBase,
|
||||
}
|
||||
|
||||
void AddInterface(const SocketAddress& iface, const std::string& if_name) {
|
||||
AddInterface(iface, if_name, ADAPTER_TYPE_UNKNOWN);
|
||||
}
|
||||
|
||||
void AddInterface(const SocketAddress& iface,
|
||||
const std::string& if_name,
|
||||
AdapterType type) {
|
||||
SocketAddress address(if_name, 0);
|
||||
address.SetResolvedIP(iface.ipaddr());
|
||||
ifaces_.push_back(address);
|
||||
ifaces_.push_back(std::make_pair(address, type));
|
||||
DoUpdateNetworks();
|
||||
}
|
||||
|
||||
void RemoveInterface(const SocketAddress& iface) {
|
||||
for (IfaceList::iterator it = ifaces_.begin();
|
||||
it != ifaces_.end(); ++it) {
|
||||
if (it->EqualIPs(iface)) {
|
||||
if (it->first.EqualIPs(iface)) {
|
||||
ifaces_.erase(it);
|
||||
break;
|
||||
}
|
||||
@ -86,18 +93,17 @@ class FakeNetworkManager : public NetworkManagerBase,
|
||||
for (IfaceList::iterator it = ifaces_.begin();
|
||||
it != ifaces_.end(); ++it) {
|
||||
int prefix_length = 0;
|
||||
if (it->ipaddr().family() == AF_INET) {
|
||||
if (it->first.ipaddr().family() == AF_INET) {
|
||||
prefix_length = kFakeIPv4NetworkPrefixLength;
|
||||
} else if (it->ipaddr().family() == AF_INET6) {
|
||||
} else if (it->first.ipaddr().family() == AF_INET6) {
|
||||
prefix_length = kFakeIPv6NetworkPrefixLength;
|
||||
}
|
||||
IPAddress prefix = TruncateIP(it->ipaddr(), prefix_length);
|
||||
scoped_ptr<Network> net(new Network(it->hostname(),
|
||||
it->hostname(),
|
||||
prefix,
|
||||
prefix_length));
|
||||
IPAddress prefix = TruncateIP(it->first.ipaddr(), prefix_length);
|
||||
scoped_ptr<Network> net(new Network(it->first.hostname(),
|
||||
it->first.hostname(), prefix,
|
||||
prefix_length, it->second));
|
||||
net->set_default_local_address_provider(this);
|
||||
net->AddIP(it->ipaddr());
|
||||
net->AddIP(it->first.ipaddr());
|
||||
networks.push_back(net.release());
|
||||
}
|
||||
bool changed;
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
#include "webrtc/base/gunit.h"
|
||||
@ -207,6 +208,12 @@ void TestPhysicalInternal(const SocketAddress& int_addr) {
|
||||
|
||||
std::vector<Network*> networks;
|
||||
network_manager.GetNetworks(&networks);
|
||||
networks.erase(std::remove_if(networks.begin(), networks.end(),
|
||||
[](rtc::Network* network) {
|
||||
return rtc::kDefaultNetworkIgnoreMask &
|
||||
network->type();
|
||||
}),
|
||||
networks.end());
|
||||
if (networks.empty()) {
|
||||
LOG(LS_WARNING) << "Not enough network adapters for test.";
|
||||
return;
|
||||
|
||||
@ -365,7 +365,6 @@ bool NetworkManagerBase::GetDefaultLocalAddress(int family,
|
||||
|
||||
BasicNetworkManager::BasicNetworkManager()
|
||||
: thread_(NULL), sent_first_update_(false), start_count_(0),
|
||||
network_ignore_mask_(kDefaultNetworkIgnoreMask),
|
||||
ignore_non_default_routes_(false) {
|
||||
}
|
||||
|
||||
@ -665,9 +664,6 @@ bool BasicNetworkManager::IsIgnoredNetwork(const Network& network) const {
|
||||
}
|
||||
}
|
||||
|
||||
if (network_ignore_mask_ & network.type()) {
|
||||
return true;
|
||||
}
|
||||
#if defined(WEBRTC_POSIX)
|
||||
// Filter out VMware/VirtualBox interfaces, typically named vmnet1,
|
||||
// vmnet8, or vboxnet0.
|
||||
|
||||
@ -207,18 +207,6 @@ class BasicNetworkManager : public NetworkManagerBase,
|
||||
network_ignore_list_ = list;
|
||||
}
|
||||
|
||||
// Sets the network types to ignore. For instance, calling this with
|
||||
// ADAPTER_TYPE_ETHERNET | ADAPTER_TYPE_LOOPBACK will ignore Ethernet and
|
||||
// loopback interfaces. Set to kDefaultNetworkIgnoreMask by default.
|
||||
void set_network_ignore_mask(int network_ignore_mask) {
|
||||
// TODO(phoglund): implement support for other types than loopback.
|
||||
// See https://code.google.com/p/webrtc/issues/detail?id=4288.
|
||||
// Then remove set_network_ignore_list.
|
||||
network_ignore_mask_ = network_ignore_mask;
|
||||
}
|
||||
|
||||
int network_ignore_mask() const { return network_ignore_mask_; }
|
||||
|
||||
#if defined(WEBRTC_LINUX)
|
||||
// Sets the flag for ignoring non-default routes.
|
||||
void set_ignore_non_default_routes(bool value) {
|
||||
@ -266,7 +254,6 @@ class BasicNetworkManager : public NetworkManagerBase,
|
||||
bool sent_first_update_;
|
||||
int start_count_;
|
||||
std::vector<std::string> network_ignore_list_;
|
||||
int network_ignore_mask_;
|
||||
bool ignore_non_default_routes_;
|
||||
scoped_ptr<NetworkMonitorInterface> network_monitor_;
|
||||
};
|
||||
|
||||
@ -159,26 +159,6 @@ TEST_F(NetworkTest, TestNetworkConstruct) {
|
||||
EXPECT_FALSE(ipv4_network1.ignored());
|
||||
}
|
||||
|
||||
// Tests that our ignore function works properly.
|
||||
TEST_F(NetworkTest, TestIsIgnoredNetworkIgnoresOnlyLoopbackByDefault) {
|
||||
Network ipv4_network1("test_eth0", "Test Network Adapter 1",
|
||||
IPAddress(0x12345600U), 24, ADAPTER_TYPE_ETHERNET);
|
||||
Network ipv4_network2("test_wlan0", "Test Network Adapter 2",
|
||||
IPAddress(0x12345601U), 16, ADAPTER_TYPE_WIFI);
|
||||
Network ipv4_network3("test_cell0", "Test Network Adapter 3",
|
||||
IPAddress(0x12345602U), 16, ADAPTER_TYPE_CELLULAR);
|
||||
Network ipv4_network4("test_vpn0", "Test Network Adapter 4",
|
||||
IPAddress(0x12345603U), 16, ADAPTER_TYPE_VPN);
|
||||
Network ipv4_network5("test_lo", "Test Network Adapter 5",
|
||||
IPAddress(0x12345604U), 16, ADAPTER_TYPE_LOOPBACK);
|
||||
BasicNetworkManager network_manager;
|
||||
EXPECT_FALSE(IsIgnoredNetwork(network_manager, ipv4_network1));
|
||||
EXPECT_FALSE(IsIgnoredNetwork(network_manager, ipv4_network2));
|
||||
EXPECT_FALSE(IsIgnoredNetwork(network_manager, ipv4_network3));
|
||||
EXPECT_FALSE(IsIgnoredNetwork(network_manager, ipv4_network4));
|
||||
EXPECT_TRUE(IsIgnoredNetwork(network_manager, ipv4_network5));
|
||||
}
|
||||
|
||||
TEST_F(NetworkTest, TestIsIgnoredNetworkIgnoresIPsStartingWith0) {
|
||||
Network ipv4_network1("test_eth0", "Test Network Adapter 1",
|
||||
IPAddress(0x12345600U), 24, ADAPTER_TYPE_ETHERNET);
|
||||
@ -189,21 +169,6 @@ TEST_F(NetworkTest, TestIsIgnoredNetworkIgnoresIPsStartingWith0) {
|
||||
EXPECT_TRUE(IsIgnoredNetwork(network_manager, ipv4_network2));
|
||||
}
|
||||
|
||||
TEST_F(NetworkTest, TestIsIgnoredNetworkIgnoresNetworksAccordingToIgnoreMask) {
|
||||
Network ipv4_network1("test_eth0", "Test Network Adapter 1",
|
||||
IPAddress(0x12345600U), 24, ADAPTER_TYPE_ETHERNET);
|
||||
Network ipv4_network2("test_wlan0", "Test Network Adapter 2",
|
||||
IPAddress(0x12345601U), 16, ADAPTER_TYPE_WIFI);
|
||||
Network ipv4_network3("test_cell0", "Test Network Adapter 3",
|
||||
IPAddress(0x12345602U), 16, ADAPTER_TYPE_CELLULAR);
|
||||
BasicNetworkManager network_manager;
|
||||
network_manager.set_network_ignore_mask(
|
||||
ADAPTER_TYPE_ETHERNET | ADAPTER_TYPE_LOOPBACK | ADAPTER_TYPE_WIFI);
|
||||
EXPECT_TRUE(IsIgnoredNetwork(network_manager, ipv4_network1));
|
||||
EXPECT_TRUE(IsIgnoredNetwork(network_manager, ipv4_network2));
|
||||
EXPECT_FALSE(IsIgnoredNetwork(network_manager, ipv4_network3));
|
||||
}
|
||||
|
||||
// TODO(phoglund): Remove when ignore list goes away.
|
||||
TEST_F(NetworkTest, TestIgnoreList) {
|
||||
Network ignore_me("ignore_me", "Ignore me please!",
|
||||
|
||||
@ -113,10 +113,10 @@ bool Conductor::CreatePeerConnection(bool dtls) {
|
||||
ASSERT(peer_connection_factory_.get() != NULL);
|
||||
ASSERT(peer_connection_.get() == NULL);
|
||||
|
||||
webrtc::PeerConnectionInterface::IceServers servers;
|
||||
webrtc::PeerConnectionInterface::RTCConfiguration config;
|
||||
webrtc::PeerConnectionInterface::IceServer server;
|
||||
server.uri = GetPeerConnectionString();
|
||||
servers.push_back(server);
|
||||
config.servers.push_back(server);
|
||||
|
||||
webrtc::FakeConstraints constraints;
|
||||
if (dtls) {
|
||||
@ -127,12 +127,8 @@ bool Conductor::CreatePeerConnection(bool dtls) {
|
||||
"false");
|
||||
}
|
||||
|
||||
peer_connection_ =
|
||||
peer_connection_factory_->CreatePeerConnection(servers,
|
||||
&constraints,
|
||||
NULL,
|
||||
NULL,
|
||||
this);
|
||||
peer_connection_ = peer_connection_factory_->CreatePeerConnection(
|
||||
config, &constraints, NULL, NULL, this);
|
||||
return peer_connection_.get() != NULL;
|
||||
}
|
||||
|
||||
|
||||
@ -91,6 +91,17 @@ typedef std::vector<ProtocolAddress> PortList;
|
||||
struct RelayServerConfig {
|
||||
RelayServerConfig(RelayType type) : type(type), priority(0) {}
|
||||
|
||||
RelayServerConfig(const std::string& address,
|
||||
int port,
|
||||
const std::string& username,
|
||||
const std::string& password,
|
||||
ProtocolType proto,
|
||||
bool secure)
|
||||
: type(RELAY_TURN), credentials(username, password) {
|
||||
ports.push_back(
|
||||
ProtocolAddress(rtc::SocketAddress(address, port), proto, secure));
|
||||
}
|
||||
|
||||
RelayType type;
|
||||
PortList ports;
|
||||
RelayCredentials credentials;
|
||||
@ -168,6 +179,13 @@ class PortAllocator : public sigslot::has_slots<> {
|
||||
const ServerAddresses& stun_servers,
|
||||
const std::vector<RelayServerConfig>& turn_servers) = 0;
|
||||
|
||||
// Sets the network types to ignore.
|
||||
// Values are defined by the AdapterType enum.
|
||||
// For instance, calling this with
|
||||
// ADAPTER_TYPE_ETHERNET | ADAPTER_TYPE_LOOPBACK will ignore Ethernet and
|
||||
// loopback interfaces.
|
||||
virtual void SetNetworkIgnoreMask(int network_ignore_mask) = 0;
|
||||
|
||||
PortAllocatorSession* CreateSession(
|
||||
const std::string& sid,
|
||||
const std::string& content_name,
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
|
||||
#include "webrtc/p2p/client/basicportallocator.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -70,15 +71,16 @@ BasicPortAllocator::BasicPortAllocator(
|
||||
: network_manager_(network_manager),
|
||||
socket_factory_(socket_factory),
|
||||
stun_servers_() {
|
||||
ASSERT(socket_factory_ != NULL);
|
||||
ASSERT(network_manager_ != nullptr);
|
||||
ASSERT(socket_factory_ != nullptr);
|
||||
Construct();
|
||||
}
|
||||
|
||||
BasicPortAllocator::BasicPortAllocator(
|
||||
rtc::NetworkManager* network_manager)
|
||||
BasicPortAllocator::BasicPortAllocator(rtc::NetworkManager* network_manager)
|
||||
: network_manager_(network_manager),
|
||||
socket_factory_(NULL),
|
||||
socket_factory_(nullptr),
|
||||
stun_servers_() {
|
||||
ASSERT(network_manager_ != nullptr);
|
||||
Construct();
|
||||
}
|
||||
|
||||
@ -327,6 +329,12 @@ void BasicPortAllocatorSession::GetNetworks(
|
||||
} else {
|
||||
network_manager->GetNetworks(networks);
|
||||
}
|
||||
networks->erase(std::remove_if(networks->begin(), networks->end(),
|
||||
[this](rtc::Network* network) {
|
||||
return allocator_->network_ignore_mask() &
|
||||
network->type();
|
||||
}),
|
||||
networks->end());
|
||||
}
|
||||
|
||||
// For each network, see if we have a sequence that covers it already. If not,
|
||||
|
||||
@ -44,6 +44,16 @@ class BasicPortAllocator : public PortAllocator {
|
||||
turn_servers_ = turn_servers;
|
||||
}
|
||||
|
||||
// Set to kDefaultNetworkIgnoreMask by default.
|
||||
void SetNetworkIgnoreMask(int network_ignore_mask) override {
|
||||
// TODO(phoglund): implement support for other types than loopback.
|
||||
// See https://code.google.com/p/webrtc/issues/detail?id=4288.
|
||||
// Then remove set_network_ignore_list from NetworkManager.
|
||||
network_ignore_mask_ = network_ignore_mask;
|
||||
}
|
||||
|
||||
int network_ignore_mask() const { return network_ignore_mask_; }
|
||||
|
||||
rtc::NetworkManager* network_manager() { return network_manager_; }
|
||||
|
||||
// If socket_factory() is set to NULL each PortAllocatorSession
|
||||
@ -75,6 +85,7 @@ class BasicPortAllocator : public PortAllocator {
|
||||
ServerAddresses stun_servers_;
|
||||
std::vector<RelayServerConfig> turn_servers_;
|
||||
bool allow_tcp_listen_;
|
||||
int network_ignore_mask_ = rtc::kDefaultNetworkIgnoreMask;
|
||||
};
|
||||
|
||||
struct PortConfiguration;
|
||||
|
||||
@ -157,6 +157,8 @@ class FakePortAllocator : public cricket::PortAllocator {
|
||||
turn_servers_ = turn_servers;
|
||||
}
|
||||
|
||||
void SetNetworkIgnoreMask(int network_ignore_mask) override {}
|
||||
|
||||
const ServerAddresses& stun_servers() const { return stun_servers_; }
|
||||
|
||||
const std::vector<RelayServerConfig>& turn_servers() const {
|
||||
|
||||
@ -32,6 +32,7 @@
|
||||
#include "webrtc/base/virtualsocketserver.h"
|
||||
|
||||
using cricket::ServerAddresses;
|
||||
using rtc::IPAddress;
|
||||
using rtc::SocketAddress;
|
||||
using rtc::Thread;
|
||||
|
||||
@ -114,6 +115,11 @@ class PortAllocatorTest : public testing::Test, public sigslot::has_slots<> {
|
||||
void AddInterface(const SocketAddress& addr, const std::string& if_name) {
|
||||
network_manager_.AddInterface(addr, if_name);
|
||||
}
|
||||
void AddInterface(const SocketAddress& addr,
|
||||
const std::string& if_name,
|
||||
rtc::AdapterType type) {
|
||||
network_manager_.AddInterface(addr, if_name, type);
|
||||
}
|
||||
// The default route is the public address that STUN server will observe when
|
||||
// the endpoint is sitting on the public internet and the local port is bound
|
||||
// to the "any" address. This may be different from the default local address
|
||||
@ -400,6 +406,50 @@ TEST_F(PortAllocatorTest, TestBasic) {
|
||||
EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
|
||||
}
|
||||
|
||||
// Tests that our network filtering works properly.
|
||||
TEST_F(PortAllocatorTest, TestIgnoreOnlyLoopbackNetworkByDefault) {
|
||||
AddInterface(SocketAddress(IPAddress(0x12345600U), 0), "test_eth0",
|
||||
rtc::ADAPTER_TYPE_ETHERNET);
|
||||
AddInterface(SocketAddress(IPAddress(0x12345601U), 0), "test_wlan0",
|
||||
rtc::ADAPTER_TYPE_WIFI);
|
||||
AddInterface(SocketAddress(IPAddress(0x12345602U), 0), "test_cell0",
|
||||
rtc::ADAPTER_TYPE_CELLULAR);
|
||||
AddInterface(SocketAddress(IPAddress(0x12345603U), 0), "test_vpn0",
|
||||
rtc::ADAPTER_TYPE_VPN);
|
||||
AddInterface(SocketAddress(IPAddress(0x12345604U), 0), "test_lo",
|
||||
rtc::ADAPTER_TYPE_LOOPBACK);
|
||||
EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
|
||||
session_->set_flags(cricket::PORTALLOCATOR_DISABLE_STUN |
|
||||
cricket::PORTALLOCATOR_DISABLE_RELAY |
|
||||
cricket::PORTALLOCATOR_DISABLE_TCP);
|
||||
session_->StartGettingPorts();
|
||||
EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
|
||||
EXPECT_EQ(4U, candidates_.size());
|
||||
for (cricket::Candidate candidate : candidates_) {
|
||||
EXPECT_LT(candidate.address().ip(), 0x12345604U);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(PortAllocatorTest, TestIgnoreNetworksAccordingToIgnoreMask) {
|
||||
AddInterface(SocketAddress(IPAddress(0x12345600U), 0), "test_eth0",
|
||||
rtc::ADAPTER_TYPE_ETHERNET);
|
||||
AddInterface(SocketAddress(IPAddress(0x12345601U), 0), "test_wlan0",
|
||||
rtc::ADAPTER_TYPE_WIFI);
|
||||
AddInterface(SocketAddress(IPAddress(0x12345602U), 0), "test_cell0",
|
||||
rtc::ADAPTER_TYPE_CELLULAR);
|
||||
allocator_->SetNetworkIgnoreMask(rtc::ADAPTER_TYPE_ETHERNET |
|
||||
rtc::ADAPTER_TYPE_LOOPBACK |
|
||||
rtc::ADAPTER_TYPE_WIFI);
|
||||
EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
|
||||
session_->set_flags(cricket::PORTALLOCATOR_DISABLE_STUN |
|
||||
cricket::PORTALLOCATOR_DISABLE_RELAY |
|
||||
cricket::PORTALLOCATOR_DISABLE_TCP);
|
||||
session_->StartGettingPorts();
|
||||
EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
|
||||
EXPECT_EQ(1U, candidates_.size());
|
||||
EXPECT_EQ(0x12345602U, candidates_[0].address().ip());
|
||||
}
|
||||
|
||||
// Tests that we allocator session not trying to allocate ports for every 250ms.
|
||||
TEST_F(PortAllocatorTest, TestNoNetworkInterface) {
|
||||
EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
|
||||
@ -415,7 +465,8 @@ TEST_F(PortAllocatorTest, TestNoNetworkInterface) {
|
||||
|
||||
// Test that we could use loopback interface as host candidate.
|
||||
TEST_F(PortAllocatorTest, TestLoopbackNetworkInterface) {
|
||||
AddInterface(kLoopbackAddr);
|
||||
AddInterface(kLoopbackAddr, "test_loopback", rtc::ADAPTER_TYPE_LOOPBACK);
|
||||
allocator_->SetNetworkIgnoreMask(0);
|
||||
EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
|
||||
session_->set_flags(cricket::PORTALLOCATOR_DISABLE_STUN |
|
||||
cricket::PORTALLOCATOR_DISABLE_RELAY |
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user