| // 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 "InstanceNetworking.h" |
| 22 | #include "Message.h" |
| 23 | #include "ThreadLocalObject.h" |
| 24 | #include "Instance.h" |
| 25 |
| 26 | namespace rtc { |
| 27 | class BasicPacketSocketFactory; |
| 28 | class BasicNetworkManager; |
| 29 | class PacketTransportInternal; |
| 30 | struct NetworkRoute; |
| 31 | } // namespace rtc |
| 32 |
| 33 | namespace cricket { |
| 34 | class BasicPortAllocator; |
| 35 | class P2PTransportChannel; |
| 36 | class IceTransportInternal; |
| 37 | class DtlsTransport; |
| 38 | class RelayPortFactoryInterface; |
| 39 | } // namespace cricket |
| 40 |
| 41 | namespace webrtc { |
| 42 | class TurnCustomizer; |
| 43 | class DtlsSrtpTransport; |
| 44 | class RtpTransport; |
| 45 | class AsyncDnsResolverFactoryInterface; |
| 46 | } // namespace webrtc |
| 47 |
| 48 | namespace tgcalls { |
| 49 |
| 50 | struct Message; |
| 51 | class SctpDataChannelProviderInterfaceImpl; |
| 52 | class Threads; |
| 53 |
| 54 | class NativeNetworkingImpl : public InstanceNetworking, public sigslot::has_slots<>, public std::enable_shared_from_this<NativeNetworkingImpl> { |
| 55 | public: |
| 56 | static webrtc::CryptoOptions getDefaulCryptoOptions(); |
| 57 |
| 58 | NativeNetworkingImpl(Configuration &&configuration); |
| 59 | virtual ~NativeNetworkingImpl(); |
| 60 |
| 61 | virtual void start() override; |
| 62 | virtual void stop() override; |
| 63 |
| 64 | virtual PeerIceParameters getLocalIceParameters() override; |
| 65 | virtual std::unique_ptr<rtc::SSLFingerprint> getLocalFingerprint() override; |
| 66 | virtual void setRemoteParams(PeerIceParameters const &remoteIceParameters, rtc::SSLFingerprint *fingerprint, std::string const &sslSetup) override; |
| 67 | virtual void addCandidates(std::vector<cricket::Candidate> const &candidates) override; |
| 68 |
| 69 | virtual void sendDataChannelMessage(std::string const &message) override; |
| 70 |
| 71 | virtual webrtc::RtpTransport *getRtpTransport() override; |
| 72 |
| 73 | private: |
| 74 | void resetDtlsSrtpTransport(); |
| 75 | void checkConnectionTimeout(); |
| 76 | void candidateGathered(cricket::IceTransportInternal *transport, const cricket::Candidate &candidate); |
| 77 | void candidateGatheringState(cricket::IceTransportInternal *transport); |
| 78 | void OnTransportWritableState_n(rtc::PacketTransportInternal *transport); |
| 79 | void OnTransportReceivingState_n(rtc::PacketTransportInternal *transport); |
| 80 | void transportStateChanged(cricket::IceTransportInternal *transport); |
| 81 | void transportReadyToSend(cricket::IceTransportInternal *transport); |
| 82 | void transportRouteChanged(absl::optional<rtc::NetworkRoute> route); |
| 83 | void candidatePairChanged(cricket::CandidatePairChangeEvent const &event); |
| 84 | void DtlsReadyToSend(bool DtlsReadyToSend); |
| 85 | void UpdateAggregateStates_n(); |
| 86 | void RtpPacketReceived_n(rtc::CopyOnWriteBuffer *packet, int64_t packet_time_us, bool isUnresolved); |
| 87 | void OnRtcpPacketReceived_n(rtc::CopyOnWriteBuffer *packet, int64_t packet_time_us); |
| 88 |
| 89 | void sctpReadyToSendData(); |
| 90 |
| 91 | void notifyStateUpdated(); |
| 92 |
| 93 | void processPendingLocalStandaloneReflectorCandidates(); |
| 94 |
| 95 | std::shared_ptr<Threads> _threads; |
| 96 | bool _isOutgoing = false; |
| 97 | EncryptionKey _encryptionKey; |
| 98 | bool _enableStunMarking = false; |
| 99 | bool _enableTCP = false; |
| 100 | bool _enableP2P = false; |
| 101 | std::vector<RtcServer> _rtcServers; |
| 102 | absl::optional<Proxy> _proxy; |
| 103 | std::map<std::string, json11::Json> _customParameters; |
| 104 |
| 105 | std::function<void(const InstanceNetworking::State &)> _stateUpdated; |
| 106 | std::function<void(const cricket::Candidate &)> _candidateGathered; |
| 107 | std::function<void(rtc::CopyOnWriteBuffer const &, bool)> _transportMessageReceived; |
| 108 | std::function<void(rtc::CopyOnWriteBuffer const &, int64_t)> _rtcpPacketReceived; |
| 109 | std::function<void(bool)> _dataChannelStateUpdated; |
| 110 | std::function<void(std::string const &)> _dataChannelMessageReceived; |
| 111 |
| 112 | std::unique_ptr<rtc::NetworkMonitorFactory> _networkMonitorFactory; |
| 113 | rtc::SocketFactory *_underlyingSocketFactory = nullptr; |
| 114 | std::unique_ptr<rtc::PacketSocketFactory> _socketFactory; |
| 115 | std::unique_ptr<rtc::NetworkManager> _networkManager; |
| 116 | std::unique_ptr<webrtc::TurnCustomizer> _turnCustomizer; |
| 117 | std::unique_ptr<cricket::RelayPortFactoryInterface> _relayPortFactory; |
| 118 | std::unique_ptr<cricket::BasicPortAllocator> _portAllocator; |
| 119 | std::unique_ptr<webrtc::AsyncDnsResolverFactoryInterface> _asyncResolverFactory; |
| 120 | std::unique_ptr<cricket::P2PTransportChannel> _transportChannel; |
| 121 | std::unique_ptr<webrtc::RtpTransport> _mtProtoRtpTransport; |
| 122 | std::unique_ptr<cricket::DtlsTransport> _dtlsTransport; |
| 123 | std::unique_ptr<webrtc::DtlsSrtpTransport> _dtlsSrtpTransport; |
| 124 |
| 125 | std::unique_ptr<SctpDataChannelProviderInterfaceImpl> _dataChannelInterface; |
| 126 |
| 127 | webrtc::scoped_refptr<rtc::RTCCertificate> _localCertificate; |
| 128 | PeerIceParameters _localIceParameters; |
| 129 | absl::optional<PeerIceParameters> _remoteIceParameters; |
| 130 |
| 131 | bool _isConnected = false; |
| 132 | bool _isFailed = false; |
| 133 | int64_t _lastDisconnectedTimestamp = 0; |
| 134 | absl::optional<RouteDescription> _currentRouteDescription; |
| 135 | absl::optional<ConnectionDescription> _currentConnectionDescription; |
| 136 |
| 137 | std::vector<cricket::Candidate> _pendingLocalStandaloneReflectorCandidates; |
| 138 | }; |
| 139 |
| 140 | } // namespace tgcalls |
| 141 |
| 142 | #endif |
| 143 |