RTCPeerConnectionInterface.mm createNativeConfiguration and other clean-up.

This CL turns nativeConfiguration into createNativeConfiguration returning a
pointer or nil on failure. This method's certificate generation is updated to
use the new API and reports failure (nil) if unsuccessful instead of relying on
the default certificate. We also remove the implicit assumption (now incorrect)
that RSA is the default. This is the same type of changes as was done in
https://codereview.webrtc.org/1965313002 but this file
(RTCPeerConnectionInterface.mm) was forgotten.

With no more usages of kIdentityName it and dtlsidentitystore.cc is removed.
Also removes unnecessary #include in peerconnectioninterface.h that was still
remnant due to an indirect include of kIdentityName.

RTCConfiguration+Private.h now lists method nativeEncryptionKeyTypeForKeyType
which was added in the above mentioned prior CL.

BUG=webrtc:5707, webrtc:5708

Review-Url: https://codereview.webrtc.org/2035473004
Cr-Commit-Position: refs/heads/master@{#13089}
This commit is contained in:
hbos
2016-06-09 03:18:28 -07:00
committed by Commit bot
parent d4070c63d9
commit f9da44dbcf
11 changed files with 68 additions and 61 deletions

View File

@ -211,8 +211,12 @@ class RTCStatsObserver : public StatsObserver {
} }
- (BOOL)setConfiguration:(RTCConfiguration *)configuration { - (BOOL)setConfiguration:(RTCConfiguration *)configuration {
return self.peerConnection->SetConfiguration( std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> config(
configuration.nativeConfiguration); [configuration createNativeConfiguration]);
if (!config) {
return NO;
}
return self.peerConnection->SetConfiguration(*config);
} }
- (RTCSessionDescription*)localDescription { - (RTCSessionDescription*)localDescription {

View File

@ -99,8 +99,13 @@
- (RTCPeerConnection *)peerConnectionWithConfiguration:(RTCConfiguration *)configuration - (RTCPeerConnection *)peerConnectionWithConfiguration:(RTCConfiguration *)configuration
constraints:(RTCMediaConstraints *)constraints constraints:(RTCMediaConstraints *)constraints
delegate:(id<RTCPeerConnectionDelegate>)delegate { delegate:(id<RTCPeerConnectionDelegate>)delegate {
std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> config(
[configuration createNativeConfiguration]);
if (!config) {
return nil;
}
return [[RTCPeerConnection alloc] initWithFactory:self.nativeFactory.get() return [[RTCPeerConnection alloc] initWithFactory:self.nativeFactory.get()
config:configuration.nativeConfiguration config:*config
constraints:constraints.constraints constraints:constraints.constraints
delegate:delegate]; delegate:delegate];
} }

View File

@ -31,7 +31,9 @@
@interface RTCConfiguration () @interface RTCConfiguration ()
@property(nonatomic, readonly) + (rtc::KeyType)nativeEncryptionKeyTypeForKeyType:(RTCEncryptionKeyType)keyType;
webrtc::PeerConnectionInterface::RTCConfiguration nativeConfiguration;
- (webrtc::PeerConnectionInterface::RTCConfiguration *)
createNativeConfiguration;
@end @end

View File

@ -33,6 +33,8 @@
#include <memory> #include <memory>
#include "webrtc/base/rtccertificategenerator.h"
@implementation RTCConfiguration @implementation RTCConfiguration
@synthesize iceTransportsType = _iceTransportsType; @synthesize iceTransportsType = _iceTransportsType;
@ -83,30 +85,49 @@
#pragma mark - Private #pragma mark - Private
- (webrtc::PeerConnectionInterface::RTCConfiguration)nativeConfiguration { - (webrtc::PeerConnectionInterface::RTCConfiguration *)
webrtc::PeerConnectionInterface::RTCConfiguration nativeConfig; createNativeConfiguration {
nativeConfig.type = [RTCEnumConverter nativeEnumForIceTransportsType:_iceTransportsType]; std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration>
nativeConfig(new webrtc::PeerConnectionInterface::RTCConfiguration());
nativeConfig->type =
[RTCEnumConverter nativeEnumForIceTransportsType:_iceTransportsType];
for (RTCICEServer *iceServer : _iceServers) { for (RTCICEServer *iceServer : _iceServers) {
nativeConfig.servers.push_back(iceServer.iceServer); nativeConfig->servers.push_back(iceServer.iceServer);
} }
nativeConfig.bundle_policy = [RTCEnumConverter nativeEnumForBundlePolicy:_bundlePolicy]; nativeConfig->bundle_policy =
nativeConfig.rtcp_mux_policy = [RTCEnumConverter nativeEnumForRtcpMuxPolicy:_rtcpMuxPolicy]; [RTCEnumConverter nativeEnumForBundlePolicy:_bundlePolicy];
nativeConfig.tcp_candidate_policy = nativeConfig->rtcp_mux_policy =
[RTCEnumConverter nativeEnumForRtcpMuxPolicy:_rtcpMuxPolicy];
nativeConfig->tcp_candidate_policy =
[RTCEnumConverter nativeEnumForTcpCandidatePolicy:_tcpCandidatePolicy]; [RTCEnumConverter nativeEnumForTcpCandidatePolicy:_tcpCandidatePolicy];
nativeConfig.audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets; nativeConfig->audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets;
nativeConfig.ice_connection_receiving_timeout = _iceConnectionReceivingTimeout; nativeConfig->ice_connection_receiving_timeout =
nativeConfig.ice_backup_candidate_pair_ping_interval = _iceBackupCandidatePairPingInterval; _iceConnectionReceivingTimeout;
if (_keyType == kRTCEncryptionKeyTypeECDSA) { nativeConfig->ice_backup_candidate_pair_ping_interval =
std::unique_ptr<rtc::SSLIdentity> identity( _iceBackupCandidatePairPingInterval;
rtc::SSLIdentity::Generate(webrtc::kIdentityName, rtc::KT_ECDSA)); rtc::KeyType keyType =
if (identity) { [[self class] nativeEncryptionKeyTypeForKeyType:_keyType];
nativeConfig.certificates.push_back( if (keyType != rtc::KT_DEFAULT) {
rtc::RTCCertificate::Create(std::move(identity))); rtc::scoped_refptr<rtc::RTCCertificate> certificate =
} else { rtc::RTCCertificateGenerator::GenerateCertificate(
RTCLogWarning(@"Failed to generate ECDSA identity. RSA will be used."); rtc::KeyParams(keyType), rtc::Optional<uint64_t>());
if (!certificate) {
RTCLogError(@"Failed to generate certificate.");
return nullptr;
} }
nativeConfig->certificates.push_back(certificate);
}
return nativeConfig.release();
}
+ (rtc::KeyType)nativeEncryptionKeyTypeForKeyType:
(RTCEncryptionKeyType)keyType {
switch (keyType) {
case kRTCEncryptionKeyTypeRSA:
return rtc::KT_RSA;
case kRTCEncryptionKeyTypeECDSA:
return rtc::KT_ECDSA;
} }
return nativeConfig;
} }
@end @end

View File

@ -34,7 +34,6 @@ source_set("libjingle_peerconnection") {
"datachannel.cc", "datachannel.cc",
"datachannel.h", "datachannel.h",
"datachannelinterface.h", "datachannelinterface.h",
"dtlsidentitystore.cc",
"dtlsidentitystore.h", "dtlsidentitystore.h",
"dtmfsender.cc", "dtmfsender.cc",
"dtmfsender.h", "dtmfsender.h",

View File

@ -135,7 +135,6 @@
'datachannel.cc', 'datachannel.cc',
'datachannel.h', 'datachannel.h',
'datachannelinterface.h', 'datachannelinterface.h',
'dtlsidentitystore.cc',
'dtlsidentitystore.h', 'dtlsidentitystore.h',
'dtmfsender.cc', 'dtmfsender.cc',
'dtmfsender.h', 'dtmfsender.h',

View File

@ -1,19 +0,0 @@
/*
* Copyright 2015 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.
*/
#include "webrtc/api/dtlsidentitystore.h"
namespace webrtc {
// Passed to SSLIdentity::Generate, "WebRTC". Used for the certificates'
// subject and issuer name.
const char kIdentityName[] = "WebRTC";
} // namespace webrtc

View File

@ -27,11 +27,6 @@
namespace webrtc { namespace webrtc {
// TODO(hbos): Remove this constant (and dtlsidentitystore.cc) after
// RTCPeerConnectionInterface.mm stops using it.
// bugs.webrtc.org/5707, bugs.webrtc.org/5708
extern const char kIdentityName[];
class SSLIdentity; class SSLIdentity;
class Thread; class Thread;

View File

@ -57,7 +57,6 @@
#include <vector> #include <vector>
#include "webrtc/api/datachannelinterface.h" #include "webrtc/api/datachannelinterface.h"
#include "webrtc/api/dtlsidentitystore.h"
#include "webrtc/api/dtmfsenderinterface.h" #include "webrtc/api/dtmfsenderinterface.h"
#include "webrtc/api/jsep.h" #include "webrtc/api/jsep.h"
#include "webrtc/api/mediastreaminterface.h" #include "webrtc/api/mediastreaminterface.h"

View File

@ -56,6 +56,8 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSString *)stringForCandidateNetworkPolicy:(RTCCandidateNetworkPolicy)policy; + (NSString *)stringForCandidateNetworkPolicy:(RTCCandidateNetworkPolicy)policy;
+ (rtc::KeyType)nativeEncryptionKeyTypeForKeyType:(RTCEncryptionKeyType)keyType;
/** /**
* RTCConfiguration struct representation of this RTCConfiguration. This is * RTCConfiguration struct representation of this RTCConfiguration. This is
* needed to pass to the underlying C++ APIs. * needed to pass to the underlying C++ APIs.

View File

@ -250,16 +250,6 @@
} }
} }
+ (rtc::KeyType)nativeEncryptionKeyTypeForKeyType:
(RTCEncryptionKeyType)keyType {
switch (keyType) {
case RTCEncryptionKeyTypeRSA:
return rtc::KT_RSA;
case RTCEncryptionKeyTypeECDSA:
return rtc::KT_ECDSA;
}
}
+ (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy: + (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy:
(webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy { (webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy {
switch (nativePolicy) { switch (nativePolicy) {
@ -330,4 +320,14 @@
} }
} }
+ (rtc::KeyType)nativeEncryptionKeyTypeForKeyType:
(RTCEncryptionKeyType)keyType {
switch (keyType) {
case RTCEncryptionKeyTypeRSA:
return rtc::KT_RSA;
case RTCEncryptionKeyTypeECDSA:
return rtc::KT_ECDSA;
}
}
@end @end