OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <memory> | 11 #include <memory> |
12 #include <set> | 12 #include <set> |
13 | 13 |
14 #include "webrtc/p2p/base/dtlstransport.h" | 14 #include "webrtc/p2p/base/dtlstransport.h" |
15 #include "webrtc/p2p/base/faketransportcontroller.h" | 15 #include "webrtc/p2p/base/faketransportcontroller.h" |
| 16 #include "webrtc/p2p/base/packettransport.h" |
16 #include "webrtc/base/common.h" | 17 #include "webrtc/base/common.h" |
17 #include "webrtc/base/dscp.h" | 18 #include "webrtc/base/dscp.h" |
18 #include "webrtc/base/gunit.h" | 19 #include "webrtc/base/gunit.h" |
19 #include "webrtc/base/helpers.h" | 20 #include "webrtc/base/helpers.h" |
20 #include "webrtc/base/ssladapter.h" | 21 #include "webrtc/base/ssladapter.h" |
21 #include "webrtc/base/sslidentity.h" | 22 #include "webrtc/base/sslidentity.h" |
22 #include "webrtc/base/sslstreamadapter.h" | 23 #include "webrtc/base/sslstreamadapter.h" |
23 #include "webrtc/base/stringutils.h" | 24 #include "webrtc/base/stringutils.h" |
24 | 25 |
25 #define MAYBE_SKIP_TEST(feature) \ | 26 #define MAYBE_SKIP_TEST(feature) \ |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 int num_matches = 0; | 358 int num_matches = 0; |
358 for (size_t i = kPacketNumOffset; i < size; ++i) { | 359 for (size_t i = kPacketNumOffset; i < size; ++i) { |
359 if (static_cast<uint8_t>(data[i]) == (packet_num & 0xff)) { | 360 if (static_cast<uint8_t>(data[i]) == (packet_num & 0xff)) { |
360 ++num_matches; | 361 ++num_matches; |
361 } | 362 } |
362 } | 363 } |
363 return (num_matches < ((static_cast<int>(size) - 5) / 10)); | 364 return (num_matches < ((static_cast<int>(size) - 5) / 10)); |
364 } | 365 } |
365 | 366 |
366 // Transport channel callbacks | 367 // Transport channel callbacks |
367 void OnTransportChannelWritableState(cricket::TransportChannel* channel) { | 368 void OnTransportChannelWritableState(rtc::PacketTransport* pt) { |
368 LOG(LS_INFO) << name_ << ": Channel '" << channel->component() | 369 LOG(LS_INFO) << name_ << ": Channel '" << pt->component() |
369 << "' is writable"; | 370 << "' is writable"; |
370 } | 371 } |
371 | 372 |
372 void OnTransportChannelReadPacket(cricket::TransportChannel* channel, | 373 void OnTransportChannelReadPacket(rtc::PacketTransport* pt, |
373 const char* data, size_t size, | 374 const char* data, |
| 375 size_t size, |
374 const rtc::PacketTime& packet_time, | 376 const rtc::PacketTime& packet_time, |
375 int flags) { | 377 int flags) { |
376 uint32_t packet_num = 0; | 378 uint32_t packet_num = 0; |
377 ASSERT_TRUE(VerifyPacket(data, size, &packet_num)); | 379 ASSERT_TRUE(VerifyPacket(data, size, &packet_num)); |
378 received_.insert(packet_num); | 380 received_.insert(packet_num); |
379 // Only DTLS-SRTP packets should have the bypass flag set. | 381 // Only DTLS-SRTP packets should have the bypass flag set. |
380 int expected_flags = | 382 int expected_flags = |
381 (certificate_ && IsRtpLeadByte(data[0])) ? cricket::PF_SRTP_BYPASS : 0; | 383 (certificate_ && IsRtpLeadByte(data[0])) ? cricket::PF_SRTP_BYPASS : 0; |
382 ASSERT_EQ(expected_flags, flags); | 384 ASSERT_EQ(expected_flags, flags); |
383 } | 385 } |
384 | 386 |
385 void OnTransportChannelSentPacket(cricket::TransportChannel* channel, | 387 void OnTransportChannelSentPacket(rtc::PacketTransport* pt, |
386 const rtc::SentPacket& sent_packet) { | 388 const rtc::SentPacket& sent_packet) { |
387 sent_packet_ = sent_packet; | 389 sent_packet_ = sent_packet; |
388 } | 390 } |
389 | 391 |
390 rtc::SentPacket sent_packet() const { return sent_packet_; } | 392 rtc::SentPacket sent_packet() const { return sent_packet_; } |
391 | 393 |
392 // Hook into the raw packet stream to make sure DTLS packets are encrypted. | 394 // Hook into the raw packet stream to make sure DTLS packets are encrypted. |
393 void OnFakeTransportChannelReadPacket(cricket::TransportChannel* channel, | 395 void OnFakeTransportChannelReadPacket(rtc::PacketTransport* pt, |
394 const char* data, size_t size, | 396 const char* data, |
| 397 size_t size, |
395 const rtc::PacketTime& time, | 398 const rtc::PacketTime& time, |
396 int flags) { | 399 int flags) { |
397 // Flags shouldn't be set on the underlying TransportChannel packets. | 400 // Flags shouldn't be set on the underlying TransportChannel packets. |
398 ASSERT_EQ(0, flags); | 401 ASSERT_EQ(0, flags); |
399 | 402 |
400 // Look at the handshake packets to see what role we played. | 403 // Look at the handshake packets to see what role we played. |
401 // Check that non-handshake packets are DTLS data or SRTP bypass. | 404 // Check that non-handshake packets are DTLS data or SRTP bypass. |
402 if (data[0] == 22 && size > 17) { | 405 if (data[0] == 22 && size > 17) { |
403 if (data[13] == 1) { | 406 if (data[13] == 1) { |
404 ++received_dtls_client_hellos_; | 407 ++received_dtls_client_hellos_; |
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1166 std::vector<DtlsTransportEvent>{ | 1169 std::vector<DtlsTransportEvent>{ |
1167 CALLER_RECEIVES_CLIENTHELLO, CALLER_RECEIVES_FINGERPRINT, | 1170 CALLER_RECEIVES_CLIENTHELLO, CALLER_RECEIVES_FINGERPRINT, |
1168 CALLER_WRITABLE, HANDSHAKE_FINISHES}, | 1171 CALLER_WRITABLE, HANDSHAKE_FINISHES}, |
1169 std::vector<DtlsTransportEvent>{ | 1172 std::vector<DtlsTransportEvent>{ |
1170 CALLER_RECEIVES_CLIENTHELLO, CALLER_WRITABLE, | 1173 CALLER_RECEIVES_CLIENTHELLO, CALLER_WRITABLE, |
1171 CALLER_RECEIVES_FINGERPRINT, HANDSHAKE_FINISHES}, | 1174 CALLER_RECEIVES_FINGERPRINT, HANDSHAKE_FINISHES}, |
1172 std::vector<DtlsTransportEvent>{CALLER_RECEIVES_CLIENTHELLO, | 1175 std::vector<DtlsTransportEvent>{CALLER_RECEIVES_CLIENTHELLO, |
1173 CALLER_WRITABLE, HANDSHAKE_FINISHES, | 1176 CALLER_WRITABLE, HANDSHAKE_FINISHES, |
1174 CALLER_RECEIVES_FINGERPRINT}), | 1177 CALLER_RECEIVES_FINGERPRINT}), |
1175 ::testing::Bool())); | 1178 ::testing::Bool())); |
OLD | NEW |