blob: ff3b107bcc052407aa28c41332cd19e82cebb239 [file] [log] [blame]
Harald Alvestrandad88c882018-11-28 16:47:46 +01001/*
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 Anton10542f22019-01-11 09:11:00 -080011#ifndef API_DTLS_TRANSPORT_INTERFACE_H_
12#define API_DTLS_TRANSPORT_INTERFACE_H_
Harald Alvestrandad88c882018-11-28 16:47:46 +010013
Harald Alvestrand98462622019-01-30 14:57:03 +010014#include "api/ice_transport_interface.h"
Steve Anton10542f22019-01-11 09:11:00 -080015#include "api/rtc_error.h"
Harald Alvestrand98462622019-01-30 14:57:03 +010016#include "api/scoped_refptr.h"
Steve Anton10542f22019-01-11 09:11:00 -080017#include "rtc_base/ref_count.h"
Harald Alvestrandad88c882018-11-28 16:47:46 +010018
19namespace webrtc {
20
Harald Alvestrandd02541e2019-01-03 12:43:28 +010021// States of a DTLS transport, corresponding to the JS API specification.
22// http://w3c.github.io/webrtc-pc/#dom-rtcdtlstransportstate
23enum 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 Alvestrand4a7b3ac2019-01-17 10:39:40 +010028 kFailed, // Failure due to an error or failing to verify a remote
29 // fingerprint.
30 kNumValues
Harald Alvestrandd02541e2019-01-03 12:43:28 +010031};
32
33// This object gives snapshot information about the changeable state of a
34// DTLSTransport.
35class 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
44class 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 Alvestrandad88c882018-11-28 16:47:46 +010057// A DTLS transport, as represented to the outside world.
Harald Alvestrandd02541e2019-01-03 12:43:28 +010058// This object is created on the signaling thread, and can only be
59// accessed on that thread.
60// References can be held by other threads, and destruction can therefore
61// be initiated by other threads.
Harald Alvestrandad88c882018-11-28 16:47:46 +010062class DtlsTransportInterface : public rtc::RefCountInterface {
63 public:
Harald Alvestrand98462622019-01-30 14:57:03 +010064 // Returns a pointer to the ICE transport that is owned by the DTLS transport.
65 virtual rtc::scoped_refptr<IceTransportInterface> ice_transport() = 0;
Harald Alvestrandd02541e2019-01-03 12:43:28 +010066 // These functions can only be called from the signalling thread.
67 virtual DtlsTransportInformation Information() = 0;
68 // Observer management.
69 virtual void RegisterObserver(DtlsTransportObserverInterface* observer) = 0;
70 virtual void UnregisterObserver() = 0;
Harald Alvestrandad88c882018-11-28 16:47:46 +010071};
72
73} // namespace webrtc
74
Steve Anton10542f22019-01-11 09:11:00 -080075#endif // API_DTLS_TRANSPORT_INTERFACE_H_