blob: bff67520f02bac7815fbe1fe492d69dad235837f [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
11#ifndef API_DTLSTRANSPORTINTERFACE_H_
12#define API_DTLSTRANSPORTINTERFACE_H_
13
Harald Alvestrandd02541e2019-01-03 12:43:28 +010014#include "api/rtcerror.h"
Harald Alvestrandad88c882018-11-28 16:47:46 +010015#include "rtc_base/refcount.h"
16
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.
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.
31class 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
40class 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 Alvestrandad88c882018-11-28 16:47:46 +010053// A DTLS transport, as represented to the outside world.
Harald Alvestrandd02541e2019-01-03 12:43:28 +010054// 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 Alvestrandad88c882018-11-28 16:47:46 +010058class DtlsTransportInterface : public rtc::RefCountInterface {
59 public:
Harald Alvestrandd02541e2019-01-03 12:43:28 +010060 // 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 Alvestrandad88c882018-11-28 16:47:46 +010065};
66
67} // namespace webrtc
68
69#endif // API_DTLSTRANSPORTINTERFACE_H_