xref: /aosp_15_r20/external/webrtc/p2p/client/relay_port_factory_interface.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright 2017 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_CLIENT_RELAY_PORT_FACTORY_INTERFACE_H_
12 #define P2P_CLIENT_RELAY_PORT_FACTORY_INTERFACE_H_
13 
14 #include <memory>
15 #include <string>
16 
17 #include "p2p/base/port_interface.h"
18 #include "rtc_base/ref_count.h"
19 
20 namespace rtc {
21 class AsyncPacketSocket;
22 class Network;
23 class PacketSocketFactory;
24 class Thread;
25 }  // namespace rtc
26 
27 namespace webrtc {
28 class TurnCustomizer;
29 class FieldTrialsView;
30 }  // namespace webrtc
31 
32 namespace cricket {
33 class Port;
34 struct ProtocolAddress;
35 struct RelayServerConfig;
36 
37 // A struct containing arguments to RelayPortFactory::Create()
38 struct CreateRelayPortArgs {
39   rtc::Thread* network_thread;
40   rtc::PacketSocketFactory* socket_factory;
41   const rtc::Network* network;
42   const ProtocolAddress* server_address;
43   const RelayServerConfig* config;
44   std::string username;
45   std::string password;
46   webrtc::TurnCustomizer* turn_customizer = nullptr;
47   const webrtc::FieldTrialsView* field_trials = nullptr;
48   // Relative priority of candidates from this TURN server in relation
49   // to the candidates from other servers. Required because ICE priorities
50   // need to be unique.
51   int relative_priority = 0;
52 };
53 
54 // A factory for creating RelayPort's.
55 class RelayPortFactoryInterface {
56  public:
~RelayPortFactoryInterface()57   virtual ~RelayPortFactoryInterface() {}
58 
59   // This variant is used for UDP connection to the relay server
60   // using a already existing shared socket.
61   virtual std::unique_ptr<Port> Create(const CreateRelayPortArgs& args,
62                                        rtc::AsyncPacketSocket* udp_socket) = 0;
63 
64   // This variant is used for the other cases.
65   virtual std::unique_ptr<Port> Create(const CreateRelayPortArgs& args,
66                                        int min_port,
67                                        int max_port) = 0;
68 };
69 
70 }  // namespace cricket
71 
72 #endif  // P2P_CLIENT_RELAY_PORT_FACTORY_INTERFACE_H_
73