1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/renderer/p2p/port_allocator.h"
7 #include "base/command_line.h"
8 #include "content/public/common/content_switches.h"
12 P2PPortAllocator::Config::Config() {}
14 P2PPortAllocator::Config::~Config() {
17 P2PPortAllocator::Config::RelayServerConfig::RelayServerConfig()
21 P2PPortAllocator::Config::RelayServerConfig::~RelayServerConfig() {
24 P2PPortAllocator::P2PPortAllocator(
25 P2PSocketDispatcher
* socket_dispatcher
,
26 rtc::NetworkManager
* network_manager
,
27 rtc::PacketSocketFactory
* socket_factory
,
30 : cricket::BasicPortAllocator(network_manager
, socket_factory
),
31 socket_dispatcher_(socket_dispatcher
),
36 if (!config_
.enable_multiple_routes
)
37 flags
|= cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION
;
38 if (!config_
.enable_nonproxied_udp
) {
39 flags
|= cricket::PORTALLOCATOR_DISABLE_UDP
|
40 cricket::PORTALLOCATOR_DISABLE_STUN
|
41 cricket::PORTALLOCATOR_DISABLE_UDP_RELAY
;
44 set_allow_tcp_listen(false);
45 const base::CommandLine
* cmd_line
= base::CommandLine::ForCurrentProcess();
46 bool enable_webrtc_stun_origin
=
47 cmd_line
->HasSwitch(switches::kEnableWebRtcStunOrigin
);
48 if (enable_webrtc_stun_origin
) {
49 set_origin(origin
.spec());
53 P2PPortAllocator::~P2PPortAllocator() {
56 cricket::PortAllocatorSession
* P2PPortAllocator::CreateSessionInternal(
57 const std::string
& content_name
,
59 const std::string
& ice_username_fragment
,
60 const std::string
& ice_password
) {
61 return new P2PPortAllocatorSession(
62 this, content_name
, component
, ice_username_fragment
, ice_password
);
65 P2PPortAllocatorSession::P2PPortAllocatorSession(
66 P2PPortAllocator
* allocator
,
67 const std::string
& content_name
,
69 const std::string
& ice_username_fragment
,
70 const std::string
& ice_password
)
71 : cricket::BasicPortAllocatorSession(allocator
,
74 ice_username_fragment
,
76 allocator_(allocator
) {
79 P2PPortAllocatorSession::~P2PPortAllocatorSession() {
82 void P2PPortAllocatorSession::GetPortConfigurations() {
83 const P2PPortAllocator::Config
& config
= allocator_
->config_
;
84 cricket::PortConfiguration
* port_config
= new cricket::PortConfiguration(
85 config
.stun_servers
, std::string(), std::string());
87 for (size_t i
= 0; i
< config
.relays
.size(); ++i
) {
88 cricket::RelayCredentials
credentials(config
.relays
[i
].username
,
89 config
.relays
[i
].password
);
90 cricket::RelayServerConfig
relay_server(cricket::RELAY_TURN
);
91 cricket::ProtocolType protocol
;
92 if (!cricket::StringToProto(config
.relays
[i
].transport_type
.c_str(),
94 DLOG(WARNING
) << "Ignoring TURN server "
95 << config
.relays
[i
].server_address
<< ". "
96 << "Reason= Incorrect "
97 << config
.relays
[i
].transport_type
98 << " transport parameter.";
102 relay_server
.ports
.push_back(cricket::ProtocolAddress(
103 rtc::SocketAddress(config
.relays
[i
].server_address
,
104 config
.relays
[i
].port
),
106 config
.relays
[i
].secure
));
107 relay_server
.credentials
= credentials
;
108 port_config
->AddRelay(relay_server
);
110 ConfigReady(port_config
);
113 } // namespace content