OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 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 "webrtc/api/statscollector.h" | 11 #include "webrtc/api/statscollector.h" |
12 | 12 |
| 13 #include <memory> |
13 #include <utility> | 14 #include <utility> |
14 #include <vector> | 15 #include <vector> |
15 | 16 |
16 #include "webrtc/api/peerconnection.h" | 17 #include "webrtc/api/peerconnection.h" |
17 #include "webrtc/base/base64.h" | 18 #include "webrtc/base/base64.h" |
18 #include "webrtc/base/checks.h" | 19 #include "webrtc/base/checks.h" |
19 #include "webrtc/base/scoped_ptr.h" | |
20 #include "webrtc/base/timing.h" | 20 #include "webrtc/base/timing.h" |
21 #include "webrtc/pc/channel.h" | 21 #include "webrtc/pc/channel.h" |
22 | 22 |
23 using rtc::scoped_ptr; | |
24 | |
25 namespace webrtc { | 23 namespace webrtc { |
26 namespace { | 24 namespace { |
27 | 25 |
28 // The following is the enum RTCStatsIceCandidateType from | 26 // The following is the enum RTCStatsIceCandidateType from |
29 // http://w3c.github.io/webrtc-stats/#rtcstatsicecandidatetype-enum such that | 27 // http://w3c.github.io/webrtc-stats/#rtcstatsicecandidatetype-enum such that |
30 // our stats report for ice candidate type could conform to that. | 28 // our stats report for ice candidate type could conform to that. |
31 const char STATSREPORT_LOCAL_PORT_TYPE[] = "host"; | 29 const char STATSREPORT_LOCAL_PORT_TYPE[] = "host"; |
32 const char STATSREPORT_STUN_PORT_TYPE[] = "serverreflexive"; | 30 const char STATSREPORT_STUN_PORT_TYPE[] = "serverreflexive"; |
33 const char STATSREPORT_PRFLX_PORT_TYPE[] = "peerreflexive"; | 31 const char STATSREPORT_PRFLX_PORT_TYPE[] = "peerreflexive"; |
34 const char STATSREPORT_RELAY_PORT_TYPE[] = "relayed"; | 32 const char STATSREPORT_RELAY_PORT_TYPE[] = "relayed"; |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); | 523 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
526 | 524 |
527 // TODO(bemasc): Move this computation to a helper class that caches these | 525 // TODO(bemasc): Move this computation to a helper class that caches these |
528 // values to reduce CPU use in GetStats. This will require adding a fast | 526 // values to reduce CPU use in GetStats. This will require adding a fast |
529 // SSLCertificate::Equals() method to detect certificate changes. | 527 // SSLCertificate::Equals() method to detect certificate changes. |
530 | 528 |
531 std::string digest_algorithm; | 529 std::string digest_algorithm; |
532 if (!cert->GetSignatureDigestAlgorithm(&digest_algorithm)) | 530 if (!cert->GetSignatureDigestAlgorithm(&digest_algorithm)) |
533 return nullptr; | 531 return nullptr; |
534 | 532 |
535 rtc::scoped_ptr<rtc::SSLFingerprint> ssl_fingerprint( | 533 std::unique_ptr<rtc::SSLFingerprint> ssl_fingerprint( |
536 rtc::SSLFingerprint::Create(digest_algorithm, cert)); | 534 rtc::SSLFingerprint::Create(digest_algorithm, cert)); |
537 | 535 |
538 // SSLFingerprint::Create can fail if the algorithm returned by | 536 // SSLFingerprint::Create can fail if the algorithm returned by |
539 // SSLCertificate::GetSignatureDigestAlgorithm is not supported by the | 537 // SSLCertificate::GetSignatureDigestAlgorithm is not supported by the |
540 // implementation of SSLCertificate::ComputeDigest. This currently happens | 538 // implementation of SSLCertificate::ComputeDigest. This currently happens |
541 // with MD5- and SHA-224-signed certificates when linked to libNSS. | 539 // with MD5- and SHA-224-signed certificates when linked to libNSS. |
542 if (!ssl_fingerprint) | 540 if (!ssl_fingerprint) |
543 return nullptr; | 541 return nullptr; |
544 | 542 |
545 std::string fingerprint = ssl_fingerprint->GetRfc4572Fingerprint(); | 543 std::string fingerprint = ssl_fingerprint->GetRfc4572Fingerprint(); |
(...skipping 21 matching lines...) Expand all Loading... |
567 const rtc::SSLCertificate* cert) { | 565 const rtc::SSLCertificate* cert) { |
568 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); | 566 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
569 // Produces a chain of StatsReports representing this certificate and the rest | 567 // Produces a chain of StatsReports representing this certificate and the rest |
570 // of its chain, and adds those reports to |reports_|. The return value is | 568 // of its chain, and adds those reports to |reports_|. The return value is |
571 // the id of the leaf report. The provided cert must be non-null, so at least | 569 // the id of the leaf report. The provided cert must be non-null, so at least |
572 // one report will always be provided and the returned string will never be | 570 // one report will always be provided and the returned string will never be |
573 // empty. | 571 // empty. |
574 RTC_DCHECK(cert != NULL); | 572 RTC_DCHECK(cert != NULL); |
575 | 573 |
576 StatsReport* issuer = nullptr; | 574 StatsReport* issuer = nullptr; |
577 rtc::scoped_ptr<rtc::SSLCertChain> chain = cert->GetChain(); | 575 std::unique_ptr<rtc::SSLCertChain> chain = cert->GetChain(); |
578 if (chain) { | 576 if (chain) { |
579 // This loop runs in reverse, i.e. from root to leaf, so that each | 577 // This loop runs in reverse, i.e. from root to leaf, so that each |
580 // certificate's issuer's report ID is known before the child certificate's | 578 // certificate's issuer's report ID is known before the child certificate's |
581 // report is generated. The root certificate does not have an issuer ID | 579 // report is generated. The root certificate does not have an issuer ID |
582 // value. | 580 // value. |
583 for (ptrdiff_t i = chain->GetSize() - 1; i >= 0; --i) { | 581 for (ptrdiff_t i = chain->GetSize() - 1; i >= 0; --i) { |
584 const rtc::SSLCertificate& cert_i = chain->Get(i); | 582 const rtc::SSLCertificate& cert_i = chain->Get(i); |
585 issuer = AddOneCertificateReport(&cert_i, issuer); | 583 issuer = AddOneCertificateReport(&cert_i, issuer); |
586 } | 584 } |
587 } | 585 } |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 // | 693 // |
696 StatsReport::Id local_cert_report_id, remote_cert_report_id; | 694 StatsReport::Id local_cert_report_id, remote_cert_report_id; |
697 rtc::scoped_refptr<rtc::RTCCertificate> certificate; | 695 rtc::scoped_refptr<rtc::RTCCertificate> certificate; |
698 if (pc_->session()->GetLocalCertificate( | 696 if (pc_->session()->GetLocalCertificate( |
699 transport_iter.second.transport_name, &certificate)) { | 697 transport_iter.second.transport_name, &certificate)) { |
700 StatsReport* r = AddCertificateReports(&(certificate->ssl_certificate())); | 698 StatsReport* r = AddCertificateReports(&(certificate->ssl_certificate())); |
701 if (r) | 699 if (r) |
702 local_cert_report_id = r->id(); | 700 local_cert_report_id = r->id(); |
703 } | 701 } |
704 | 702 |
705 rtc::scoped_ptr<rtc::SSLCertificate> cert = | 703 std::unique_ptr<rtc::SSLCertificate> cert = |
706 pc_->session()->GetRemoteSSLCertificate( | 704 pc_->session()->GetRemoteSSLCertificate( |
707 transport_iter.second.transport_name); | 705 transport_iter.second.transport_name); |
708 if (cert) { | 706 if (cert) { |
709 StatsReport* r = AddCertificateReports(cert.get()); | 707 StatsReport* r = AddCertificateReports(cert.get()); |
710 if (r) | 708 if (r) |
711 remote_cert_report_id = r->id(); | 709 remote_cert_report_id = r->id(); |
712 } | 710 } |
713 | 711 |
714 for (const auto& channel_iter : transport_iter.second.channel_stats) { | 712 for (const auto& channel_iter : transport_iter.second.channel_stats) { |
715 StatsReport::Id id(StatsReport::NewComponentId( | 713 StatsReport::Id id(StatsReport::NewComponentId( |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 StatsReport* report = entry.second; | 972 StatsReport* report = entry.second; |
975 report->set_timestamp(stats_gathering_started_); | 973 report->set_timestamp(stats_gathering_started_); |
976 } | 974 } |
977 } | 975 } |
978 | 976 |
979 void StatsCollector::ClearUpdateStatsCacheForTest() { | 977 void StatsCollector::ClearUpdateStatsCacheForTest() { |
980 stats_gathering_started_ = 0; | 978 stats_gathering_started_ = 0; |
981 } | 979 } |
982 | 980 |
983 } // namespace webrtc | 981 } // namespace webrtc |
OLD | NEW |