xref: /aosp_15_r20/external/webrtc/p2p/base/basic_packet_socket_factory.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright 2011 The WebRTC Project Authors. All rights reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef P2P_BASE_BASIC_PACKET_SOCKET_FACTORY_H_
12 #define P2P_BASE_BASIC_PACKET_SOCKET_FACTORY_H_
13 
14 #include <stdint.h>
15 
16 #include <memory>
17 #include <string>
18 
19 #include "api/async_dns_resolver.h"
20 #include "api/packet_socket_factory.h"
21 #include "rtc_base/async_packet_socket.h"
22 #include "rtc_base/proxy_info.h"
23 #include "rtc_base/socket.h"
24 #include "rtc_base/socket_address.h"
25 #include "rtc_base/socket_factory.h"
26 
27 namespace rtc {
28 
29 class SocketFactory;
30 
31 class BasicPacketSocketFactory : public PacketSocketFactory {
32  public:
33   explicit BasicPacketSocketFactory(SocketFactory* socket_factory);
34   ~BasicPacketSocketFactory() override;
35 
36   AsyncPacketSocket* CreateUdpSocket(const SocketAddress& local_address,
37                                      uint16_t min_port,
38                                      uint16_t max_port) override;
39   AsyncListenSocket* CreateServerTcpSocket(const SocketAddress& local_address,
40                                            uint16_t min_port,
41                                            uint16_t max_port,
42                                            int opts) override;
43   AsyncPacketSocket* CreateClientTcpSocket(
44       const SocketAddress& local_address,
45       const SocketAddress& remote_address,
46       const ProxyInfo& proxy_info,
47       const std::string& user_agent,
48       const PacketSocketTcpOptions& tcp_options) override;
49 
50   // TODO(bugs.webrtc.org/12598) Remove when downstream stops using it.
51   ABSL_DEPRECATED("Use CreateAsyncDnsResolver")
52   AsyncResolverInterface* CreateAsyncResolver() override;
53 
54   std::unique_ptr<webrtc::AsyncDnsResolverInterface> CreateAsyncDnsResolver()
55       override;
56 
57  private:
58   int BindSocket(Socket* socket,
59                  const SocketAddress& local_address,
60                  uint16_t min_port,
61                  uint16_t max_port);
62 
63   SocketFactory* socket_factory_;
64 };
65 
66 }  // namespace rtc
67 
68 #endif  // P2P_BASE_BASIC_PACKET_SOCKET_FACTORY_H_
69