OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2016 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 #include "webrtc/api/quictransport.h" | |
12 | |
13 #include "webrtc/base/bytebuffer.h" | |
14 #include "webrtc/base/logging.h" | |
15 #include "webrtc/p2p/quic/quictransportchannel.h" | |
16 #include "webrtc/p2p/quic/reliablequicstream.h" | |
17 | |
18 namespace webrtc { | |
19 | |
pthatcher1
2016/03/30 20:34:48
The more I think about it, the more I think this c
mikescarlett
2016/04/05 19:58:50
Done. This is necessary anyway because I'm impleme
| |
20 QuicTransport::QuicTransport( | |
21 cricket::QuicTransportChannel* quic_transport_channel) { | |
22 quic_transport_channel->SignalIncomingStream.connect( | |
23 this, &QuicTransport::OnIncomingStream); | |
24 } | |
25 | |
26 void QuicTransport::RegisterDataChannel(QuicDataChannel* data_channel) { | |
27 data_channel_map_[data_channel->id()] = data_channel; | |
28 } | |
29 | |
30 void QuicTransport::UnregisterDataChannel(int id) { | |
31 data_channel_map_.erase(id); | |
pthatcher1
2016/03/30 20:34:48
Hmmm.... it seems to me like the QuicDataTransport
mikescarlett
2016/04/05 19:58:50
That's a good idea. For the OPEN message, it would
| |
32 } | |
33 | |
34 // Called when a QUIC stream is created for incoming data. | |
35 void QuicTransport::OnIncomingStream(cricket::ReliableQuicStream* stream) { | |
36 RTC_DCHECK(stream != nullptr); | |
37 quic_stream_map_[stream->id()] = stream; | |
38 stream->SignalDataReceived.connect(this, &QuicTransport::OnDataReceived); | |
39 // stream->SignalClosed.connect(this, &QuicTransport::OnStreamClosed); | |
40 } | |
41 | |
42 // Called when the first QUIC stream frame is received for incoming data. | |
43 void QuicTransport::OnDataReceived(net::QuicStreamId id, | |
44 const char* data, | |
45 size_t len) { | |
46 RTC_DCHECK(quic_stream_map_.find(id) != quic_stream_map_.end()); | |
47 cricket::ReliableQuicStream* stream = quic_stream_map_[id]; | |
48 stream->SignalDataReceived.disconnect(this); | |
49 quic_stream_map_.erase(id); | |
pthatcher1
2016/03/30 20:34:48
Are we guaranteed to always get all the data all a
Taylor Brandstetter
2016/04/01 23:23:42
This is handled in QuicDataChannel. QuicTransport
mikescarlett
2016/04/05 19:58:51
I prefer to have QuicDataChannel buffer the data i
| |
50 | |
51 // Read data channel id | |
52 rtc::ByteBuffer byte_buffer(data, len, rtc::ByteBuffer::ORDER_HOST); | |
53 uint64_t data_channel_id; | |
54 byte_buffer.ReadVarint(&data_channel_id); | |
pthatcher1
2016/03/30 20:34:49
Shouldn't we check the return value?
mikescarlett
2016/04/05 19:58:51
We should.
| |
55 | |
56 // Retrieve the data channel which will handle the message. | |
57 const auto& kv = data_channel_map_.find(data_channel_id); | |
58 if (kv == data_channel_map_.end()) { | |
59 // TODO(mikescarlett): Implement listening for an OPEN message to create a | |
60 // new QuicDataChannel when messages are received for a nonexistent ID. | |
61 LOG(LS_ERROR) << "Data was received for QUIC data channel " | |
62 << data_channel_id | |
63 << " but it is not registered to the QuicTransport."; | |
64 } else { | |
65 // Otherwise get the existing data channel. | |
66 QuicDataChannel* data_channel = kv->second; | |
67 data_channel->OnIncomingStream(stream, &byte_buffer); | |
pthatcher1
2016/03/30 20:34:48
It seems like we should parse the message ID here
mikescarlett
2016/04/05 19:58:50
Sure this could parse the message ID. That also al
| |
68 } | |
69 } | |
70 | |
71 } // namespace webrtc | |
OLD | NEW |