File: quicdatatransport.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (115 lines) | stat: -rw-r--r-- 4,548 bytes parent folder | download
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 *  Copyright 2016 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#ifndef WEBRTC_API_QUICDATATRANSPORT_H_
#define WEBRTC_API_QUICDATATRANSPORT_H_

#include <string>
#include <unordered_map>

#include "webrtc/api/datachannelinterface.h"
#include "webrtc/api/quicdatachannel.h"
#include "webrtc/base/scoped_ref_ptr.h"
#include "webrtc/base/sigslot.h"
#include "webrtc/base/thread.h"
#include "webrtc/p2p/base/transportcontroller.h"

namespace cricket {
class QuicTransportChannel;
class ReliableQuicStream;
}  // namepsace cricket

namespace webrtc {

// QuicDataTransport creates QuicDataChannels for the PeerConnection. It also
// handles QUIC stream demuxing by distributing incoming QUIC streams from the
// QuicTransportChannel among the QuicDataChannels that it has created.
//
// QuicDataTransport reads the data channel ID from the incoming QUIC stream,
// then looks it up in a map of ID => QuicDataChannel. If the data channel
// exists, it sends the QUIC stream to the QuicDataChannel.
class QuicDataTransport : public sigslot::has_slots<> {
 public:
  QuicDataTransport(rtc::Thread* signaling_thread,
                    rtc::Thread* worker_thread,
                    rtc::Thread* network_thread,
                    cricket::TransportController* transport_controller);
  ~QuicDataTransport() override;

  // The QuicDataTransport acts like a BaseChannel with these functions.
  bool SetTransport(const std::string& transport_name);
  const std::string& transport_name() const { return transport_name_; }
  const std::string& content_name() const { return content_name_; }
  void set_content_name(const std::string& content_name) {
    content_name_ = content_name;
  }

  // Creates a QuicDataChannel that uses this QuicDataTransport.
  rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
      const std::string& label,
      const DataChannelInit* config);

  // Removes a QuicDataChannel with the given ID from the QuicDataTransport's
  // data channel map.
  void DestroyDataChannel(int id);

  // True if the QuicDataTransport has a data channel with the given ID.
  bool HasDataChannel(int id) const;

  // True if the QuicDataTransport has data channels.
  bool HasDataChannels() const;

  cricket::QuicTransportChannel* quic_transport_channel() {
    return quic_transport_channel_;
  }

 private:
  // Sets the QUIC transport channel for the QuicDataChannels and the
  // QuicDataTransport. Returns false if a different QUIC transport channel is
  // already set, the QUIC transport channel cannot be set for any of the
  // QuicDataChannels, or |channel| is NULL.
  bool SetTransportChannel(cricket::QuicTransportChannel* channel);

  // Called from the QuicTransportChannel when a ReliableQuicStream is created
  // to receive incoming data.
  void OnIncomingStream(cricket::ReliableQuicStream* stream);
  // Called from the ReliableQuicStream when the first QUIC stream frame is
  // received for incoming data. The QuicDataTransport reads the data channel ID
  // and message ID from the incoming data, then dispatches the
  // ReliableQuicStream to the QuicDataChannel with the same data channel ID.
  void OnDataReceived(net::QuicStreamId stream_id,
                      const char* data,
                      size_t len);

  cricket::QuicTransportChannel* CreateTransportChannel(
      const std::string& transport_name);
  void DestroyTransportChannel(cricket::TransportChannel* transport_channel);

  // Map of data channel ID => QUIC data channel values.
  std::unordered_map<int, rtc::scoped_refptr<QuicDataChannel>>
      data_channel_by_id_;
  // Map of QUIC stream ID => ReliableQuicStream* values.
  std::unordered_map<net::QuicStreamId, cricket::ReliableQuicStream*>
      quic_stream_by_id_;
  // QuicTransportChannel for sending/receiving data.
  cricket::QuicTransportChannel* quic_transport_channel_ = nullptr;
  // Threads for the QUIC data channel.
  rtc::Thread* const signaling_thread_;
  rtc::Thread* const worker_thread_;
  rtc::Thread* const network_thread_;

  cricket::TransportController* transport_controller_;
  std::string content_name_;
  std::string transport_name_;
};

}  // namespace webrtc

#endif  // WEBRTC_API_QUICDATATRANSPORT_H_