blob: 1faf3f5e32eb5e93c11b5715e68ad7e1344cab39 [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
Steve Anton10542f22019-01-11 09:11:00 -080014#include "api/rtc_error.h"
15#include "rtc_base/ref_count.h"
Harald Alvestrandad88c882018-11-28 16:47:46 +010016
17namespace webrtc {
18
Harald Alvestrandd02541e2019-01-03 12:43:28 +010019// States of a DTLS transport, corresponding to the JS API specification.
20// http://w3c.github.io/webrtc-pc/#dom-rtcdtlstransportstate
21enum 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.
Harald Alvestrand4a7b3ac2019-01-17 10:39:40 +010026 kFailed, // Failure due to an error or failing to verify a remote
27 // fingerprint.
28 kNumValues
Harald Alvestrandd02541e2019-01-03 12:43:28 +010029};
30
31// This object gives snapshot information about the changeable state of a
32// DTLSTransport.
33class DtlsTransportInformation {
34 public:
35 explicit DtlsTransportInformation(DtlsTransportState state) : state_(state) {}
36 DtlsTransportState state() const { return state_; }
37 // TODO(hta): Add remote certificate access
38 private:
39 DtlsTransportState state_;
40};
41
42class DtlsTransportObserverInterface {
43 public:
44 // This callback carries information about the state of the transport.
45 // The argument is a pass-by-value snapshot of the state.
46 virtual void OnStateChange(DtlsTransportInformation info) = 0;
47 // This callback is called when an error occurs, causing the transport
48 // to go to the kFailed state.
49 virtual void OnError(RTCError error) = 0;
50
51 protected:
52 virtual ~DtlsTransportObserverInterface() = default;
53};
54
Harald Alvestrandad88c882018-11-28 16:47:46 +010055// A DTLS transport, as represented to the outside world.
Harald Alvestrandd02541e2019-01-03 12:43:28 +010056// This object is created on the signaling thread, and can only be
57// accessed on that thread.
58// References can be held by other threads, and destruction can therefore
59// be initiated by other threads.
Harald Alvestrandad88c882018-11-28 16:47:46 +010060class DtlsTransportInterface : public rtc::RefCountInterface {
61 public:
Harald Alvestrandd02541e2019-01-03 12:43:28 +010062 // These functions can only be called from the signalling thread.
63 virtual DtlsTransportInformation Information() = 0;
64 // Observer management.
65 virtual void RegisterObserver(DtlsTransportObserverInterface* observer) = 0;
66 virtual void UnregisterObserver() = 0;
Harald Alvestrandad88c882018-11-28 16:47:46 +010067};
68
69} // namespace webrtc
70
Steve Anton10542f22019-01-11 09:11:00 -080071#endif // API_DTLS_TRANSPORT_INTERFACE_H_