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