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
;
35 set_allow_tcp_listen(false);
38 P2PPortAllocator::~P2PPortAllocator() {
41 cricket::PortAllocatorSession
* P2PPortAllocator::CreateSessionInternal(
42 const std::string
& content_name
,
44 const std::string
& ice_username_fragment
,
45 const std::string
& ice_password
) {
46 return new P2PPortAllocatorSession(
47 this, content_name
, component
, ice_username_fragment
, ice_password
);
50 P2PPortAllocatorSession::P2PPortAllocatorSession(
51 P2PPortAllocator
* allocator
,
52 const std::string
& content_name
,
54 const std::string
& ice_username_fragment
,
55 const std::string
& ice_password
)
56 : cricket::BasicPortAllocatorSession(allocator
,
59 ice_username_fragment
,
61 allocator_(allocator
) {
64 P2PPortAllocatorSession::~P2PPortAllocatorSession() {
67 void P2PPortAllocatorSession::GetPortConfigurations() {
68 const P2PPortAllocator::Config
& config
= allocator_
->config_
;
69 cricket::PortConfiguration
* port_config
= new cricket::PortConfiguration(
70 config
.stun_servers
, std::string(), std::string());
72 for (size_t i
= 0; i
< config
.relays
.size(); ++i
) {
73 cricket::RelayCredentials
credentials(config
.relays
[i
].username
,
74 config
.relays
[i
].password
);
75 cricket::RelayServerConfig
relay_server(cricket::RELAY_TURN
);
76 cricket::ProtocolType protocol
;
77 if (!cricket::StringToProto(config
.relays
[i
].transport_type
.c_str(),
79 DLOG(WARNING
) << "Ignoring TURN server "
80 << config
.relays
[i
].server_address
<< ". "
81 << "Reason= Incorrect "
82 << config
.relays
[i
].transport_type
83 << " transport parameter.";
87 relay_server
.ports
.push_back(cricket::ProtocolAddress(
88 rtc::SocketAddress(config
.relays
[i
].server_address
,
89 config
.relays
[i
].port
),
91 config
.relays
[i
].secure
));
92 relay_server
.credentials
= credentials
;
93 port_config
->AddRelay(relay_server
);
95 ConfigReady(port_config
);
98 } // namespace content