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"
9 P2PPortAllocator::Config::Config()
10 : disable_tcp_transport(false) {
13 P2PPortAllocator::Config::~Config() {
16 P2PPortAllocator::Config::RelayServerConfig::RelayServerConfig()
20 P2PPortAllocator::Config::RelayServerConfig::~RelayServerConfig() {
23 P2PPortAllocator::P2PPortAllocator(
24 P2PSocketDispatcher
* socket_dispatcher
,
25 rtc::NetworkManager
* network_manager
,
26 rtc::PacketSocketFactory
* socket_factory
,
28 : cricket::BasicPortAllocator(network_manager
, socket_factory
),
29 socket_dispatcher_(socket_dispatcher
),
32 if (config_
.disable_tcp_transport
)
33 flags
|= cricket::PORTALLOCATOR_DISABLE_TCP
;
34 if (!config_
.enable_multiple_routes
)
35 flags
|= cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION
;
37 set_allow_tcp_listen(false);
40 P2PPortAllocator::~P2PPortAllocator() {
43 cricket::PortAllocatorSession
* P2PPortAllocator::CreateSessionInternal(
44 const std::string
& content_name
,
46 const std::string
& ice_username_fragment
,
47 const std::string
& ice_password
) {
48 return new P2PPortAllocatorSession(
49 this, content_name
, component
, ice_username_fragment
, ice_password
);
52 P2PPortAllocatorSession::P2PPortAllocatorSession(
53 P2PPortAllocator
* allocator
,
54 const std::string
& content_name
,
56 const std::string
& ice_username_fragment
,
57 const std::string
& ice_password
)
58 : cricket::BasicPortAllocatorSession(allocator
,
61 ice_username_fragment
,
63 allocator_(allocator
) {
66 P2PPortAllocatorSession::~P2PPortAllocatorSession() {
69 void P2PPortAllocatorSession::GetPortConfigurations() {
70 const P2PPortAllocator::Config
& config
= allocator_
->config_
;
71 cricket::PortConfiguration
* port_config
= new cricket::PortConfiguration(
72 config
.stun_servers
, std::string(), std::string());
74 for (size_t i
= 0; i
< config
.relays
.size(); ++i
) {
75 cricket::RelayCredentials
credentials(config
.relays
[i
].username
,
76 config
.relays
[i
].password
);
77 cricket::RelayServerConfig
relay_server(cricket::RELAY_TURN
);
78 cricket::ProtocolType protocol
;
79 if (!cricket::StringToProto(config
.relays
[i
].transport_type
.c_str(),
81 DLOG(WARNING
) << "Ignoring TURN server "
82 << config
.relays
[i
].server_address
<< ". "
83 << "Reason= Incorrect "
84 << config
.relays
[i
].transport_type
85 << " transport parameter.";
89 relay_server
.ports
.push_back(cricket::ProtocolAddress(
90 rtc::SocketAddress(config
.relays
[i
].server_address
,
91 config
.relays
[i
].port
),
93 config
.relays
[i
].secure
));
94 relay_server
.credentials
= credentials
;
95 port_config
->AddRelay(relay_server
);
97 ConfigReady(port_config
);
100 } // namespace content