summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/modules/peerconnection/adapters/p2p_quic_transport.h
blob: ace4820ebcfa38fc1711fe976188579f0d439e1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_PEERCONNECTION_ADAPTERS_P2P_QUIC_TRANSPORT_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_PEERCONNECTION_ADAPTERS_P2P_QUIC_TRANSPORT_H_

#include "third_party/webrtc/rtc_base/sslfingerprint.h"

namespace blink {

class P2PQuicStream;

// Used by the RTCQuicTransport Web API. This transport creates and manages
// streams, handles negotiation, state changes and errors. Every
// P2PQuicTransport function maps directly to a method in the RTCQuicTransport
// Web API, i.e. RTCQuicTransport::stop() -->
// P2PQuicTransport::Stop(). This allows posting just one task across
// thread boundaries to execute a function.
//
// This object should be run entirely on the webrtc worker thread.
class P2PQuicTransport {
 public:
  // Used for receiving callbacks from the P2PQuicTransport regarding QUIC
  // connection changes, handshake success/failures and new QuicStreams being
  // added from the remote side.
  class Delegate {
   public:
    virtual ~Delegate() = default;
    // Called when receiving a close frame from the remote side, due to
    // calling P2PQuicTransport::Stop().
    virtual void OnRemoteStopped() {}
    // Called when the connection is closed due to a QUIC error. This can happen
    // locally by the framer, or remotely by the peer.
    virtual void OnConnectionFailed(const std::string& error_details,
                                    bool from_remote) {}
    // Called when the crypto handshake has completed and fingerprints have been
    // verified.
    virtual void OnConnected() {}

    // Called when an incoming stream is received from the remote side. This
    // stream is owned by the P2PQuicTransport. Its lifetime is managed by the
    // P2PQuicTransport, and can be deleted when:
    // - The P2PQuicStream becomes closed for reading and writing.
    // - Stop() is called.
    // - The P2PQuicTransport is deleted.
    virtual void OnStream(P2PQuicStream* stream) {}
  };

  virtual ~P2PQuicTransport() = default;

  // Closes the QuicConnection and sends a close frame to the remote side.
  // This will trigger P2PQuicTransport::Delegate::OnRemoteClosed() on the
  // remote side.
  virtual void Stop() = 0;

  // Starts the QUIC handshake negotiation and sets the remote fingerprints
  // that were signaled through a secure channel. These fingerprints are used to
  // verify the self signed remote certificate used in the QUIC handshake. See:
  // https://w3c.github.io/webrtc-quic/#quic-transport*
  virtual void Start(std::vector<std::unique_ptr<rtc::SSLFingerprint>>
                         remote_fingerprints) = 0;

  // Creates a new outgoing stream. This stream is owned by the
  // P2PQuicTransport. Its lifetime is managed by the P2PQuicTransport,
  // and can be deleted when:
  // - The P2PQuicStream becomes closed for reading and writing.
  // - Stop() is called.
  // - The P2PQuicTransport is deleted.
  virtual P2PQuicStream* CreateStream() = 0;

  // TODO(https://crbug.com/874296): Consider adding a getter for the
  // local fingerprints of the certificate(s) set in the constructor.
};
}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_MODULES_PEERCONNECTION_ADAPTERS_P2P_QUIC_TRANSPORT_H_