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.
4
5 #include "third_party/blink/renderer/platform/p2p/port_allocator.h"
6
7 #include <stdint.h>
8
9 #include <memory>
10 #include <utility>
11
12 #include "base/check.h"
13 #include "third_party/blink/public/platform/platform.h"
14 #include "third_party/blink/renderer/platform/p2p/socket_dispatcher.h"
15
16 namespace blink {
17
P2PPortAllocator(const scoped_refptr<P2PSocketDispatcher> & socket_dispatcher,std::unique_ptr<rtc::NetworkManager> network_manager,rtc::PacketSocketFactory * socket_factory,const Config & config,const GURL & origin)18 P2PPortAllocator::P2PPortAllocator(
19 const scoped_refptr<P2PSocketDispatcher>& socket_dispatcher,
20 std::unique_ptr<rtc::NetworkManager> network_manager,
21 rtc::PacketSocketFactory* socket_factory,
22 const Config& config,
23 const GURL& origin)
24 : cricket::BasicPortAllocator(network_manager.get(), socket_factory),
25 network_manager_(std::move(network_manager)),
26 socket_dispatcher_(socket_dispatcher),
27 config_(config),
28 origin_(origin) {
29 DCHECK(socket_dispatcher);
30 DCHECK(network_manager_);
31 DCHECK(socket_factory);
32 uint32_t flags = 0;
33 if (!config_.enable_multiple_routes) {
34 flags |= cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION;
35 }
36 if (!config_.enable_default_local_candidate) {
37 flags |= cricket::PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE;
38 }
39 if (!config_.enable_nonproxied_udp) {
40 flags |= cricket::PORTALLOCATOR_DISABLE_UDP |
41 cricket::PORTALLOCATOR_DISABLE_STUN |
42 cricket::PORTALLOCATOR_DISABLE_UDP_RELAY;
43 }
44 set_flags(flags);
45 set_allow_tcp_listen(false);
46 bool enable_webrtc_stun_origin =
47 Platform::Current()->IsWebRtcStunOriginEnabled();
48 if (enable_webrtc_stun_origin) {
49 set_origin(origin_.spec());
50 }
51 }
52
~P2PPortAllocator()53 P2PPortAllocator::~P2PPortAllocator() {}
54
Initialize()55 void P2PPortAllocator::Initialize() {
56 BasicPortAllocator::Initialize();
57 network_manager_->Initialize();
58 }
59
60 } // namespace blink
61