// // Created by xueyuegui on 19-12-7. // #ifndef MYWEBRTC_MYDTLSTRANSPORT_H #define MYWEBRTC_MYDTLSTRANSPORT_H #include #include #include "rtc_dtls_transport.h" class DtlsTransport : RTC::DtlsTransport::Listener { public: typedef std::shared_ptr Ptr; DtlsTransport(bool bServer); ~DtlsTransport(); void Start(); void Close(); void InputData(char *buf, size_t len); void OutputData(char *buf, size_t len); static bool IsDtlsPacket(const char *buf, size_t len); std::string GetMyFingerprint() { auto finger_prints = dtls_transport_->GetLocalFingerprints(); for (size_t i = 0; i < finger_prints.size(); i++) { if (finger_prints[i].algorithm == RTC::DtlsTransport::FingerprintAlgorithm::SHA256) { return finger_prints[i].value; } } return ""; }; void SetHandshakeCompletedCB(std::function cb) { handshake_completed_callback_ = std::move(cb); } void SetHandshakeFailedCB(std::function cb) { handshake_failed_callback_ = std::move(cb); } void SetOutPutCB(std::function cb) { output_callback_ = std::move(cb); } /* Pure virtual methods inherited from RTC::DtlsTransport::Listener. */ public: void OnDtlsTransportConnecting(const RTC::DtlsTransport *dtlsTransport) override; void OnDtlsTransportConnected(const RTC::DtlsTransport *dtlsTransport, RTC::CryptoSuite srtpCryptoSuite, uint8_t *srtpLocalKey, size_t srtpLocalKeyLen, uint8_t *srtpRemoteKey, size_t srtpRemoteKeyLen, std::string &remoteCert) override; void OnDtlsTransportFailed(const RTC::DtlsTransport *dtlsTransport) override; void OnDtlsTransportClosed(const RTC::DtlsTransport *dtlsTransport) override; void OnDtlsTransportSendData(const RTC::DtlsTransport *dtlsTransport, const uint8_t *data,size_t len) override; void OnDtlsTransportApplicationDataReceived(const RTC::DtlsTransport *dtlsTransport, const uint8_t *data, size_t len) override; private: bool is_server_ = false; std::function handshake_failed_callback_; std::shared_ptr dtls_transport_; std::function output_callback_; std::function handshake_completed_callback_; }; #endif// MYWEBRTC_MYDTLSTRANSPORT_H