| // 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 | #include "EncryptedConnection.h" |
| 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 | class DirectPacketTransport; |
| 55 | class DirectRtpTransport; |
| 56 |
| 57 | class DirectNetworkingImpl : public InstanceNetworking, public sigslot::has_slots<>, public std::enable_shared_from_this<DirectNetworkingImpl> { |
| 58 | public: |
| 59 | static webrtc::CryptoOptions getDefaulCryptoOptions(); |
| 60 |
| 61 | DirectNetworkingImpl(Configuration &&configuration); |
| 62 | ~DirectNetworkingImpl(); |
| 63 |
| 64 | void start(); |
| 65 | void stop(); |
| 66 |
| 67 | PeerIceParameters getLocalIceParameters(); |
| 68 | std::unique_ptr<rtc::SSLFingerprint> getLocalFingerprint(); |
| 69 | void setRemoteParams(PeerIceParameters const &remoteIceParameters, rtc::SSLFingerprint *fingerprint, std::string const &sslSetup); |
| 70 | void addCandidates(std::vector<cricket::Candidate> const &candidates); |
| 71 |
| 72 | void sendDataChannelMessage(std::string const &message); |
| 73 |
| 74 | webrtc::RtpTransport *getRtpTransport(); |
| 75 |
| 76 | private: |
| 77 | void checkConnectionTimeout(); |
| 78 | void notifyStateUpdated(); |
| 79 |
| 80 | void resetDtlsSrtpTransport(); |
| 81 |
| 82 | void DtlsReadyToSend(bool DtlsReadyToSend); |
| 83 | void UpdateAggregateStates_n(); |
| 84 | void OnRtcpPacketReceived_n(rtc::CopyOnWriteBuffer *packet, int64_t packet_time_us); |
| 85 | void OnTransportWritableState_n(rtc::PacketTransportInternal *transport); |
| 86 | void OnTransportReceivingState_n(rtc::PacketTransportInternal *transport); |
| 87 |
| 88 | private: |
| 89 | std::shared_ptr<Threads> _threads; |
| 90 | bool _isOutgoing = false; |
| 91 |
| 92 | webrtc::scoped_refptr<rtc::RTCCertificate> _localCertificate; |
| 93 | std::vector<RtcServer> _rtcServers; |
| 94 | PeerIceParameters _localIceParameters; |
| 95 |
| 96 | std::unique_ptr<DirectConnectionChannel> _channel; |
| 97 |
| 98 | std::shared_ptr<DirectConnectionChannel> _directConnectionChannel; |
| 99 | std::shared_ptr<DirectPacketTransport> _packetTransport; |
| 100 | std::unique_ptr<DirectRtpTransport> _rtpTransport; |
| 101 | std::unique_ptr<SctpDataChannelProviderInterfaceImpl> _dataChannelInterface; |
| 102 |
| 103 | std::function<void(const DirectNetworkingImpl::State &)> _stateUpdated; |
| 104 | std::function<void(rtc::CopyOnWriteBuffer const &, bool)> _transportMessageReceived; |
| 105 | std::function<void(rtc::CopyOnWriteBuffer const &, int64_t)> _rtcpPacketReceived; |
| 106 | std::function<void(bool)> _dataChannelStateUpdated; |
| 107 | std::function<void(std::string const &)> _dataChannelMessageReceived; |
| 108 |
| 109 | bool _transportIsConnected = false; |
| 110 | bool _isConnected = false; |
| 111 | bool _isFailed = false; |
| 112 | int64_t _lastDisconnectedTimestamp = 0; |
| 113 | absl::optional<RouteDescription> _currentRouteDescription; |
| 114 | absl::optional<ConnectionDescription> _currentConnectionDescription; |
| 115 | }; |
| 116 |
| 117 | } // namespace tgcalls |
| 118 |
| 119 | #endif |
| 120 |