Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 API_DTLSTRANSPORTINTERFACE_H_ |
| 12 | #define API_DTLSTRANSPORTINTERFACE_H_ |
| 13 | |
Harald Alvestrand | d02541e | 2019-01-03 12:43:28 +0100 | [diff] [blame^] | 14 | #include "api/rtcerror.h" |
Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 15 | #include "rtc_base/refcount.h" |
| 16 | |
| 17 | namespace webrtc { |
| 18 | |
Harald Alvestrand | d02541e | 2019-01-03 12:43:28 +0100 | [diff] [blame^] | 19 | // States of a DTLS transport, corresponding to the JS API specification. |
| 20 | // http://w3c.github.io/webrtc-pc/#dom-rtcdtlstransportstate |
| 21 | enum class DtlsTransportState { |
| 22 | kNew, // Has not started negotiating yet. |
| 23 | kConnecting, // In the process of negotiating a secure connection. |
| 24 | kConnected, // Completed negotiation and verified fingerprints. |
| 25 | kClosed, // Intentionally closed. |
| 26 | kFailed // Failure due to an error or failing to verify a remote fingerprint. |
| 27 | }; |
| 28 | |
| 29 | // This object gives snapshot information about the changeable state of a |
| 30 | // DTLSTransport. |
| 31 | class DtlsTransportInformation { |
| 32 | public: |
| 33 | explicit DtlsTransportInformation(DtlsTransportState state) : state_(state) {} |
| 34 | DtlsTransportState state() const { return state_; } |
| 35 | // TODO(hta): Add remote certificate access |
| 36 | private: |
| 37 | DtlsTransportState state_; |
| 38 | }; |
| 39 | |
| 40 | class DtlsTransportObserverInterface { |
| 41 | public: |
| 42 | // This callback carries information about the state of the transport. |
| 43 | // The argument is a pass-by-value snapshot of the state. |
| 44 | virtual void OnStateChange(DtlsTransportInformation info) = 0; |
| 45 | // This callback is called when an error occurs, causing the transport |
| 46 | // to go to the kFailed state. |
| 47 | virtual void OnError(RTCError error) = 0; |
| 48 | |
| 49 | protected: |
| 50 | virtual ~DtlsTransportObserverInterface() = default; |
| 51 | }; |
| 52 | |
Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 53 | // A DTLS transport, as represented to the outside world. |
Harald Alvestrand | d02541e | 2019-01-03 12:43:28 +0100 | [diff] [blame^] | 54 | // This object is created on the signaling thread, and can only be |
| 55 | // accessed on that thread. |
| 56 | // References can be held by other threads, and destruction can therefore |
| 57 | // be initiated by other threads. |
Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 58 | class DtlsTransportInterface : public rtc::RefCountInterface { |
| 59 | public: |
Harald Alvestrand | d02541e | 2019-01-03 12:43:28 +0100 | [diff] [blame^] | 60 | // These functions can only be called from the signalling thread. |
| 61 | virtual DtlsTransportInformation Information() = 0; |
| 62 | // Observer management. |
| 63 | virtual void RegisterObserver(DtlsTransportObserverInterface* observer) = 0; |
| 64 | virtual void UnregisterObserver() = 0; |
Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | } // namespace webrtc |
| 68 | |
| 69 | #endif // API_DTLSTRANSPORTINTERFACE_H_ |