| // Compiler errors in conflicting Windows headers if not included here. |
| 6 | #include <winsock2.h> |
| 7 | #endif // WEBRTC_WIN |
| 8 |
| 9 | #include "rtc_base/copy_on_write_buffer.h" |
| 10 | #include "rtc_base/third_party/sigslot/sigslot.h" |
| 11 | #include "api/candidate.h" |
| 12 | #include "media/base/media_channel.h" |
| 13 | #include "rtc_base/ssl_fingerprint.h" |
| 14 | #include "pc/sctp_data_channel.h" |
| 15 | #include "p2p/base/port.h" |
| 16 | #include "api/transport/field_trial_based_config.h" |
| 17 |
| 18 | #include <functional> |
| 19 | #include <memory> |
| 20 |
| 21 | #include "Message.h" |
| 22 | #include "ThreadLocalObject.h" |
| 23 | #include "Instance.h" |
| 24 |
| 25 | #include "third-party/json11.hpp" |
| 26 |
| 27 | namespace rtc { |
| 28 | class BasicPacketSocketFactory; |
| 29 | class BasicNetworkManager; |
| 30 | class PacketTransportInternal; |
| 31 | struct NetworkRoute; |
| 32 | } // namespace rtc |
| 33 |
| 34 | namespace cricket { |
| 35 | class BasicPortAllocator; |
| 36 | class P2PTransportChannel; |
| 37 | class IceTransportInternal; |
| 38 | class DtlsTransport; |
| 39 | class RelayPortFactoryInterface; |
| 40 | } // namespace cricket |
| 41 |
| 42 | namespace webrtc { |
| 43 | class TurnCustomizer; |
| 44 | class DtlsSrtpTransport; |
| 45 | class RtpTransport; |
| 46 | class AsyncDnsResolverFactoryInterface; |
| 47 | } // namespace webrtc |
| 48 |
| 49 | namespace tgcalls { |
| 50 |
| 51 | struct Message; |
| 52 | class SctpDataChannelProviderInterfaceImpl; |
| 53 | class Threads; |
| 54 |
| 55 | class InstanceNetworking { |
| 56 | public: |
| 57 | struct RouteDescription { |
| 58 | explicit RouteDescription(std::string const &localDescription_, std::string const &remoteDescription_) : |
| 59 | localDescription(localDescription_), |
| 60 | remoteDescription(remoteDescription_) { |
| 61 | } |
| 62 |
| 63 | std::string localDescription; |
| 64 | std::string remoteDescription; |
| 65 |
| 66 | bool operator==(RouteDescription const &rhs) const { |
| 67 | if (localDescription != rhs.localDescription) { |
| 68 | return false; |
| 69 | } |
| 70 | if (remoteDescription != rhs.remoteDescription) { |
| 71 | return false; |
| 72 | } |
| 73 |
| 74 | return true; |
| 75 | } |
| 76 |
| 77 | bool operator!=(const RouteDescription& rhs) const { |
| 78 | return !(*this == rhs); |
| 79 | } |
| 80 | }; |
| 81 |
| 82 | struct ConnectionDescription { |
| 83 | struct CandidateDescription { |
| 84 | std::string protocol; |
| 85 | std::string type; |
| 86 | std::string address; |
| 87 |
| 88 | bool operator==(CandidateDescription const &rhs) const { |
| 89 | if (protocol != rhs.protocol) { |
| 90 | return false; |
| 91 | } |
| 92 | if (type != rhs.type) { |
| 93 | return false; |
| 94 | } |
| 95 | if (address != rhs.address) { |
| 96 | return false; |
| 97 | } |
| 98 |
| 99 | return true; |
| 100 | } |
| 101 |
| 102 | bool operator!=(const CandidateDescription& rhs) const { |
| 103 | return !(*this == rhs); |
| 104 | } |
| 105 | }; |
| 106 |
| 107 | CandidateDescription local; |
| 108 | CandidateDescription remote; |
| 109 |
| 110 | bool operator==(ConnectionDescription const &rhs) const { |
| 111 | if (local != rhs.local) { |
| 112 | return false; |
| 113 | } |
| 114 | if (remote != rhs.remote) { |
| 115 | return false; |
| 116 | } |
| 117 |
| 118 | return true; |
| 119 | } |
| 120 |
| 121 | bool operator!=(const ConnectionDescription& rhs) const { |
| 122 | return !(*this == rhs); |
| 123 | } |
| 124 | }; |
| 125 |
| 126 | struct State { |
| 127 | bool isReadyToSendData = false; |
| 128 | bool isFailed = false; |
| 129 | absl::optional<RouteDescription> route; |
| 130 | absl::optional<ConnectionDescription> connection; |
| 131 | }; |
| 132 |
| 133 | struct Configuration { |
| 134 | EncryptionKey encryptionKey; |
| 135 | bool isOutgoing = false; |
| 136 | bool enableStunMarking = false; |
| 137 | bool enableTCP = false; |
| 138 | bool enableP2P = false; |
| 139 | std::vector<RtcServer> rtcServers; |
| 140 | absl::optional<Proxy> proxy; |
| 141 | std::function<void(const InstanceNetworking::State &)> stateUpdated; |
| 142 | std::function<void(const cricket::Candidate &)> candidateGathered; |
| 143 | std::function<void(rtc::CopyOnWriteBuffer const &, bool)> transportMessageReceived; |
| 144 | std::function<void(rtc::CopyOnWriteBuffer const &, int64_t)> rtcpPacketReceived; |
| 145 | std::function<void(bool)> dataChannelStateUpdated; |
| 146 | std::function<void(std::string const &)> dataChannelMessageReceived; |
| 147 | std::shared_ptr<Threads> threads; |
| 148 | std::shared_ptr<DirectConnectionChannel> directConnectionChannel; |
| 149 | std::map<std::string, json11::Json> customParameters; |
| 150 | }; |
| 151 |
| 152 | static webrtc::CryptoOptions getDefaulCryptoOptions(); |
| 153 | static ConnectionDescription::CandidateDescription connectionDescriptionFromCandidate(cricket::Candidate const &candidate); |
| 154 |
| 155 | virtual ~InstanceNetworking() = default; |
| 156 |
| 157 | virtual void start() = 0; |
| 158 | virtual void stop() = 0; |
| 159 |
| 160 | virtual PeerIceParameters getLocalIceParameters() = 0; |
| 161 | virtual std::unique_ptr<rtc::SSLFingerprint> getLocalFingerprint() = 0; |
| 162 | virtual void setRemoteParams(PeerIceParameters const &remoteIceParameters, rtc::SSLFingerprint *fingerprint, std::string const &sslSetup) = 0; |
| 163 | virtual void addCandidates(std::vector<cricket::Candidate> const &candidates) = 0; |
| 164 |
| 165 | virtual void sendDataChannelMessage(std::string const &message) = 0; |
| 166 |
| 167 | virtual webrtc::RtpTransport *getRtpTransport() = 0; |
| 168 | }; |
| 169 |
| 170 | } // namespace tgcalls |
| 171 |
| 172 | #endif |
| 173 |