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 }  // namespace webrtc
30 
31 namespace cricket {
32 class Port;
33 struct ProtocolAddress;
34 struct RelayServerConfig;
35 
36 // A struct containing arguments to RelayPortFactory::Create()
37 struct CreateRelayPortArgs {
38   CreateRelayPortArgs();
39   rtc::Thread* network_thread;
40   rtc::PacketSocketFactory* socket_factory;
41   rtc::Network* network;
42   const ProtocolAddress* server_address;
43   const RelayServerConfig* config;
44   std::string username;
45   std::string password;
46   std::string origin;
47   webrtc::TurnCustomizer* turn_customizer;
48 };
49 
CreateRelayPortArgs()50 inline CreateRelayPortArgs::CreateRelayPortArgs() {}
51 
52 // A factory for creating RelayPort's.
53 class RelayPortFactoryInterface {
54  public:
~RelayPortFactoryInterface()55   virtual ~RelayPortFactoryInterface() {}
56 
57   // This variant is used for UDP connection to the relay server
58   // using a already existing shared socket.
59   virtual std::unique_ptr<Port> Create(const CreateRelayPortArgs& args,
60                                        rtc::AsyncPacketSocket* udp_socket) = 0;
61 
62   // This variant is used for the other cases.
63   virtual std::unique_ptr<Port> Create(const CreateRelayPortArgs& args,
64                                        int min_port,
65                                        int max_port) = 0;
66 };
67 
68 }  // namespace cricket
69 
70 #endif  // P2P_CLIENT_RELAY_PORT_FACTORY_INTERFACE_H_
71