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/packettransportinterface.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( |
368 LOG(LS_INFO) << name_ << ": Channel '" << channel->component() | 369 rtc::PacketTransportInterface* transport) { |
| 370 LOG(LS_INFO) << name_ << ": Channel '" << transport->debug_name() |
369 << "' is writable"; | 371 << "' is writable"; |
370 } | 372 } |
371 | 373 |
372 void OnTransportChannelReadPacket(cricket::TransportChannel* channel, | 374 void OnTransportChannelReadPacket(rtc::PacketTransportInterface* transport, |
373 const char* data, size_t size, | 375 const char* data, |
| 376 size_t size, |
374 const rtc::PacketTime& packet_time, | 377 const rtc::PacketTime& packet_time, |
375 int flags) { | 378 int flags) { |
376 uint32_t packet_num = 0; | 379 uint32_t packet_num = 0; |
377 ASSERT_TRUE(VerifyPacket(data, size, &packet_num)); | 380 ASSERT_TRUE(VerifyPacket(data, size, &packet_num)); |
378 received_.insert(packet_num); | 381 received_.insert(packet_num); |
379 // Only DTLS-SRTP packets should have the bypass flag set. | 382 // Only DTLS-SRTP packets should have the bypass flag set. |
380 int expected_flags = | 383 int expected_flags = |
381 (certificate_ && IsRtpLeadByte(data[0])) ? cricket::PF_SRTP_BYPASS : 0; | 384 (certificate_ && IsRtpLeadByte(data[0])) ? cricket::PF_SRTP_BYPASS : 0; |
382 ASSERT_EQ(expected_flags, flags); | 385 ASSERT_EQ(expected_flags, flags); |
383 } | 386 } |
384 | 387 |
385 void OnTransportChannelSentPacket(cricket::TransportChannel* channel, | 388 void OnTransportChannelSentPacket(rtc::PacketTransportInterface* transport, |
386 const rtc::SentPacket& sent_packet) { | 389 const rtc::SentPacket& sent_packet) { |
387 sent_packet_ = sent_packet; | 390 sent_packet_ = sent_packet; |
388 } | 391 } |
389 | 392 |
390 rtc::SentPacket sent_packet() const { return sent_packet_; } | 393 rtc::SentPacket sent_packet() const { return sent_packet_; } |
391 | 394 |
392 // Hook into the raw packet stream to make sure DTLS packets are encrypted. | 395 // Hook into the raw packet stream to make sure DTLS packets are encrypted. |
393 void OnFakeTransportChannelReadPacket(cricket::TransportChannel* channel, | 396 void OnFakeTransportChannelReadPacket( |
394 const char* data, size_t size, | 397 rtc::PacketTransportInterface* transport, |
395 const rtc::PacketTime& time, | 398 const char* data, |
396 int flags) { | 399 size_t size, |
| 400 const rtc::PacketTime& time, |
| 401 int flags) { |
397 // Flags shouldn't be set on the underlying TransportChannel packets. | 402 // Flags shouldn't be set on the underlying TransportChannel packets. |
398 ASSERT_EQ(0, flags); | 403 ASSERT_EQ(0, flags); |
399 | 404 |
400 // Look at the handshake packets to see what role we played. | 405 // Look at the handshake packets to see what role we played. |
401 // Check that non-handshake packets are DTLS data or SRTP bypass. | 406 // Check that non-handshake packets are DTLS data or SRTP bypass. |
402 if (data[0] == 22 && size > 17) { | 407 if (data[0] == 22 && size > 17) { |
403 if (data[13] == 1) { | 408 if (data[13] == 1) { |
404 ++received_dtls_client_hellos_; | 409 ++received_dtls_client_hellos_; |
405 } else if (data[13] == 2) { | 410 } else if (data[13] == 2) { |
406 ++received_dtls_server_hellos_; | 411 ++received_dtls_server_hellos_; |
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1166 std::vector<DtlsTransportEvent>{ | 1171 std::vector<DtlsTransportEvent>{ |
1167 CALLER_RECEIVES_CLIENTHELLO, CALLER_RECEIVES_FINGERPRINT, | 1172 CALLER_RECEIVES_CLIENTHELLO, CALLER_RECEIVES_FINGERPRINT, |
1168 CALLER_WRITABLE, HANDSHAKE_FINISHES}, | 1173 CALLER_WRITABLE, HANDSHAKE_FINISHES}, |
1169 std::vector<DtlsTransportEvent>{ | 1174 std::vector<DtlsTransportEvent>{ |
1170 CALLER_RECEIVES_CLIENTHELLO, CALLER_WRITABLE, | 1175 CALLER_RECEIVES_CLIENTHELLO, CALLER_WRITABLE, |
1171 CALLER_RECEIVES_FINGERPRINT, HANDSHAKE_FINISHES}, | 1176 CALLER_RECEIVES_FINGERPRINT, HANDSHAKE_FINISHES}, |
1172 std::vector<DtlsTransportEvent>{CALLER_RECEIVES_CLIENTHELLO, | 1177 std::vector<DtlsTransportEvent>{CALLER_RECEIVES_CLIENTHELLO, |
1173 CALLER_WRITABLE, HANDSHAKE_FINISHES, | 1178 CALLER_WRITABLE, HANDSHAKE_FINISHES, |
1174 CALLER_RECEIVES_FINGERPRINT}), | 1179 CALLER_RECEIVES_FINGERPRINT}), |
1175 ::testing::Bool())); | 1180 ::testing::Bool())); |
OLD | NEW |