hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 11 | #import "RTCConfiguration+Private.h" |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 12 | |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 13 | #include <memory> |
| 14 | |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame] | 15 | #import "RTCCertificate.h" |
Zeke Chin | ef1140e | 2017-10-27 15:42:08 -0700 | [diff] [blame] | 16 | #import "RTCConfiguration+Native.h" |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 17 | #import "RTCIceServer+Private.h" |
Steve Anton | d295e40 | 2017-07-14 16:06:41 -0700 | [diff] [blame] | 18 | #import "RTCIntervalRange+Private.h" |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame] | 19 | #import "base/RTCLogging.h" |
tkchin | ab8f82f | 2016-01-27 17:50:11 -0800 | [diff] [blame] | 20 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "rtc_base/rtccertificategenerator.h" |
| 22 | #include "rtc_base/sslidentity.h" |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 23 | |
| 24 | @implementation RTCConfiguration |
| 25 | |
| 26 | @synthesize iceServers = _iceServers; |
Michael Iedema | ccee56b | 2018-07-05 15:28:24 +0200 | [diff] [blame] | 27 | @synthesize certificate = _certificate; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 28 | @synthesize iceTransportPolicy = _iceTransportPolicy; |
| 29 | @synthesize bundlePolicy = _bundlePolicy; |
| 30 | @synthesize rtcpMuxPolicy = _rtcpMuxPolicy; |
| 31 | @synthesize tcpCandidatePolicy = _tcpCandidatePolicy; |
Honghai Zhang | 46007ae | 2016-06-03 16:31:32 -0700 | [diff] [blame] | 32 | @synthesize candidateNetworkPolicy = _candidateNetworkPolicy; |
Honghai Zhang | 3108fc9 | 2016-05-11 10:10:39 -0700 | [diff] [blame] | 33 | @synthesize continualGatheringPolicy = _continualGatheringPolicy; |
deadbeef | 2059bb3 | 2017-07-26 18:25:43 -0700 | [diff] [blame] | 34 | @synthesize maxIPv6Networks = _maxIPv6Networks; |
Daniel Lazarenko | 2870b0a | 2018-01-25 10:30:22 +0100 | [diff] [blame] | 35 | @synthesize disableLinkLocalNetworks = _disableLinkLocalNetworks; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 36 | @synthesize audioJitterBufferMaxPackets = _audioJitterBufferMaxPackets; |
haysc | c9f9500 | 2016-12-05 14:24:32 -0800 | [diff] [blame] | 37 | @synthesize audioJitterBufferFastAccelerate = _audioJitterBufferFastAccelerate; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 38 | @synthesize iceConnectionReceivingTimeout = _iceConnectionReceivingTimeout; |
| 39 | @synthesize iceBackupCandidatePairPingInterval = |
| 40 | _iceBackupCandidatePairPingInterval; |
tkchin | ab8f82f | 2016-01-27 17:50:11 -0800 | [diff] [blame] | 41 | @synthesize keyType = _keyType; |
deadbeef | be0c96f | 2016-05-18 16:20:14 -0700 | [diff] [blame] | 42 | @synthesize iceCandidatePoolSize = _iceCandidatePoolSize; |
honghaiz | af6b6e0 | 2016-07-11 15:09:26 -0700 | [diff] [blame] | 43 | @synthesize shouldPruneTurnPorts = _shouldPruneTurnPorts; |
| 44 | @synthesize shouldPresumeWritableWhenFullyRelayed = |
| 45 | _shouldPresumeWritableWhenFullyRelayed; |
skvlad | a5d94ff | 2017-02-02 13:02:30 -0800 | [diff] [blame] | 46 | @synthesize iceCheckMinInterval = _iceCheckMinInterval; |
Steve Anton | d295e40 | 2017-07-14 16:06:41 -0700 | [diff] [blame] | 47 | @synthesize iceRegatherIntervalRange = _iceRegatherIntervalRange; |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 48 | @synthesize sdpSemantics = _sdpSemantics; |
Zeke Chin | ef1140e | 2017-10-27 15:42:08 -0700 | [diff] [blame] | 49 | @synthesize turnCustomizer = _turnCustomizer; |
Zhi Huang | b57e169 | 2018-06-12 11:41:11 -0700 | [diff] [blame] | 50 | @synthesize activeResetSrtpParams = _activeResetSrtpParams; |
Piotr (Peter) Slatala | e0c2e97 | 2018-10-08 09:43:21 -0700 | [diff] [blame] | 51 | @synthesize useMediaTransport = _useMediaTransport; |
Benjamin Wright | 8c27cca | 2018-10-25 10:16:44 -0700 | [diff] [blame] | 52 | @synthesize cryptoOptions = _cryptoOptions; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 53 | |
| 54 | - (instancetype)init { |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 55 | // Copy defaults. |
Yuriy Pavlyshak | 8cec4fb | 2018-09-07 16:43:31 +0200 | [diff] [blame] | 56 | webrtc::PeerConnectionInterface::RTCConfiguration config; |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 57 | return [self initWithNativeConfiguration:config]; |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | - (instancetype)initWithNativeConfiguration: |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 61 | (const webrtc::PeerConnectionInterface::RTCConfiguration &)config { |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 62 | if (self = [super init]) { |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 63 | NSMutableArray *iceServers = [NSMutableArray array]; |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 64 | for (const webrtc::PeerConnectionInterface::IceServer& server : config.servers) { |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 65 | RTCIceServer *iceServer = [[RTCIceServer alloc] initWithNativeServer:server]; |
| 66 | [iceServers addObject:iceServer]; |
| 67 | } |
| 68 | _iceServers = iceServers; |
Michael Iedema | ccee56b | 2018-07-05 15:28:24 +0200 | [diff] [blame] | 69 | if (!config.certificates.empty()) { |
| 70 | rtc::scoped_refptr<rtc::RTCCertificate> native_cert; |
| 71 | native_cert = config.certificates[0]; |
| 72 | rtc::RTCCertificatePEM native_pem = native_cert->ToPEM(); |
| 73 | _certificate = |
| 74 | [[RTCCertificate alloc] initWithPrivateKey:@(native_pem.private_key().c_str()) |
| 75 | certificate:@(native_pem.certificate().c_str())]; |
| 76 | } |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 77 | _iceTransportPolicy = |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 78 | [[self class] transportPolicyForTransportsType:config.type]; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 79 | _bundlePolicy = |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 80 | [[self class] bundlePolicyForNativePolicy:config.bundle_policy]; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 81 | _rtcpMuxPolicy = |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 82 | [[self class] rtcpMuxPolicyForNativePolicy:config.rtcp_mux_policy]; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 83 | _tcpCandidatePolicy = [[self class] tcpCandidatePolicyForNativePolicy: |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 84 | config.tcp_candidate_policy]; |
Honghai Zhang | 46007ae | 2016-06-03 16:31:32 -0700 | [diff] [blame] | 85 | _candidateNetworkPolicy = [[self class] |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 86 | candidateNetworkPolicyForNativePolicy:config.candidate_network_policy]; |
Honghai Zhang | 3108fc9 | 2016-05-11 10:10:39 -0700 | [diff] [blame] | 87 | webrtc::PeerConnectionInterface::ContinualGatheringPolicy nativePolicy = |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 88 | config.continual_gathering_policy; |
Honghai Zhang | 3108fc9 | 2016-05-11 10:10:39 -0700 | [diff] [blame] | 89 | _continualGatheringPolicy = |
| 90 | [[self class] continualGatheringPolicyForNativePolicy:nativePolicy]; |
deadbeef | 2059bb3 | 2017-07-26 18:25:43 -0700 | [diff] [blame] | 91 | _maxIPv6Networks = config.max_ipv6_networks; |
Daniel Lazarenko | 2870b0a | 2018-01-25 10:30:22 +0100 | [diff] [blame] | 92 | _disableLinkLocalNetworks = config.disable_link_local_networks; |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 93 | _audioJitterBufferMaxPackets = config.audio_jitter_buffer_max_packets; |
| 94 | _audioJitterBufferFastAccelerate = config.audio_jitter_buffer_fast_accelerate; |
| 95 | _iceConnectionReceivingTimeout = config.ice_connection_receiving_timeout; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 96 | _iceBackupCandidatePairPingInterval = |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 97 | config.ice_backup_candidate_pair_ping_interval; |
tkchin | ab8f82f | 2016-01-27 17:50:11 -0800 | [diff] [blame] | 98 | _keyType = RTCEncryptionKeyTypeECDSA; |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 99 | _iceCandidatePoolSize = config.ice_candidate_pool_size; |
| 100 | _shouldPruneTurnPorts = config.prune_turn_ports; |
honghaiz | af6b6e0 | 2016-07-11 15:09:26 -0700 | [diff] [blame] | 101 | _shouldPresumeWritableWhenFullyRelayed = |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 102 | config.presume_writable_when_fully_relayed; |
| 103 | if (config.ice_check_min_interval) { |
skvlad | a5d94ff | 2017-02-02 13:02:30 -0800 | [diff] [blame] | 104 | _iceCheckMinInterval = |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 105 | [NSNumber numberWithInt:*config.ice_check_min_interval]; |
skvlad | a5d94ff | 2017-02-02 13:02:30 -0800 | [diff] [blame] | 106 | } |
Steve Anton | d295e40 | 2017-07-14 16:06:41 -0700 | [diff] [blame] | 107 | if (config.ice_regather_interval_range) { |
| 108 | const rtc::IntervalRange &nativeIntervalRange = config.ice_regather_interval_range.value(); |
| 109 | _iceRegatherIntervalRange = |
| 110 | [[RTCIntervalRange alloc] initWithNativeIntervalRange:nativeIntervalRange]; |
| 111 | } |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 112 | _sdpSemantics = [[self class] sdpSemanticsForNativeSdpSemantics:config.sdp_semantics]; |
Zeke Chin | ef1140e | 2017-10-27 15:42:08 -0700 | [diff] [blame] | 113 | _turnCustomizer = config.turn_customizer; |
Zhi Huang | b57e169 | 2018-06-12 11:41:11 -0700 | [diff] [blame] | 114 | _activeResetSrtpParams = config.active_reset_srtp_params; |
Benjamin Wright | 8c27cca | 2018-10-25 10:16:44 -0700 | [diff] [blame] | 115 | if (config.crypto_options) { |
| 116 | _cryptoOptions = [[RTCCryptoOptions alloc] |
| 117 | initWithSrtpEnableGcmCryptoSuites:config.crypto_options->srtp |
| 118 | .enable_gcm_crypto_suites |
| 119 | srtpEnableAes128Sha1_32CryptoCipher:config.crypto_options->srtp |
| 120 | .enable_aes128_sha1_32_crypto_cipher |
| 121 | srtpEnableEncryptedRtpHeaderExtensions:config.crypto_options->srtp |
| 122 | .enable_encrypted_rtp_header_extensions |
| 123 | sframeRequireFrameEncryption:config.crypto_options->sframe |
| 124 | .require_frame_encryption]; |
| 125 | } |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 126 | } |
| 127 | return self; |
| 128 | } |
| 129 | |
| 130 | - (NSString *)description { |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 131 | static NSString *formatString = |
| 132 | @"RTCConfiguration: " |
Piotr (Peter) Slatala | e0c2e97 | 2018-10-08 09:43:21 -0700 | [diff] [blame] | 133 | @"{\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%@\n%@\n%d\n%d\n%d\n%@\n}\n"; |
Daniel Lazarenko | 2870b0a | 2018-01-25 10:30:22 +0100 | [diff] [blame] | 134 | |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 135 | return [NSString |
| 136 | stringWithFormat:formatString, |
| 137 | _iceServers, |
| 138 | [[self class] stringForTransportPolicy:_iceTransportPolicy], |
| 139 | [[self class] stringForBundlePolicy:_bundlePolicy], |
| 140 | [[self class] stringForRtcpMuxPolicy:_rtcpMuxPolicy], |
| 141 | [[self class] stringForTcpCandidatePolicy:_tcpCandidatePolicy], |
| 142 | [[self class] stringForCandidateNetworkPolicy:_candidateNetworkPolicy], |
| 143 | [[self class] stringForContinualGatheringPolicy:_continualGatheringPolicy], |
| 144 | [[self class] stringForSdpSemantics:_sdpSemantics], |
| 145 | _audioJitterBufferMaxPackets, |
| 146 | _audioJitterBufferFastAccelerate, |
| 147 | _iceConnectionReceivingTimeout, |
| 148 | _iceBackupCandidatePairPingInterval, |
| 149 | _iceCandidatePoolSize, |
| 150 | _shouldPruneTurnPorts, |
| 151 | _shouldPresumeWritableWhenFullyRelayed, |
| 152 | _iceCheckMinInterval, |
| 153 | _iceRegatherIntervalRange, |
| 154 | _disableLinkLocalNetworks, |
Zhi Huang | b57e169 | 2018-06-12 11:41:11 -0700 | [diff] [blame] | 155 | _maxIPv6Networks, |
Piotr (Peter) Slatala | e0c2e97 | 2018-10-08 09:43:21 -0700 | [diff] [blame] | 156 | _activeResetSrtpParams, |
| 157 | _useMediaTransport]; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | #pragma mark - Private |
| 161 | |
hbos | a73ca56 | 2016-05-17 03:28:58 -0700 | [diff] [blame] | 162 | - (webrtc::PeerConnectionInterface::RTCConfiguration *) |
| 163 | createNativeConfiguration { |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 164 | std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> |
Honghai Zhang | f7ddc06 | 2016-09-01 15:34:01 -0700 | [diff] [blame] | 165 | nativeConfig(new webrtc::PeerConnectionInterface::RTCConfiguration( |
| 166 | webrtc::PeerConnectionInterface::RTCConfigurationType::kAggressive)); |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 167 | |
| 168 | for (RTCIceServer *iceServer in _iceServers) { |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 169 | nativeConfig->servers.push_back(iceServer.nativeServer); |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 170 | } |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 171 | nativeConfig->type = |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 172 | [[self class] nativeTransportsTypeForTransportPolicy:_iceTransportPolicy]; |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 173 | nativeConfig->bundle_policy = |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 174 | [[self class] nativeBundlePolicyForPolicy:_bundlePolicy]; |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 175 | nativeConfig->rtcp_mux_policy = |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 176 | [[self class] nativeRtcpMuxPolicyForPolicy:_rtcpMuxPolicy]; |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 177 | nativeConfig->tcp_candidate_policy = |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 178 | [[self class] nativeTcpCandidatePolicyForPolicy:_tcpCandidatePolicy]; |
Honghai Zhang | 46007ae | 2016-06-03 16:31:32 -0700 | [diff] [blame] | 179 | nativeConfig->candidate_network_policy = [[self class] |
| 180 | nativeCandidateNetworkPolicyForPolicy:_candidateNetworkPolicy]; |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 181 | nativeConfig->continual_gathering_policy = [[self class] |
Honghai Zhang | 3108fc9 | 2016-05-11 10:10:39 -0700 | [diff] [blame] | 182 | nativeContinualGatheringPolicyForPolicy:_continualGatheringPolicy]; |
deadbeef | 2059bb3 | 2017-07-26 18:25:43 -0700 | [diff] [blame] | 183 | nativeConfig->max_ipv6_networks = _maxIPv6Networks; |
Daniel Lazarenko | 2870b0a | 2018-01-25 10:30:22 +0100 | [diff] [blame] | 184 | nativeConfig->disable_link_local_networks = _disableLinkLocalNetworks; |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 185 | nativeConfig->audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets; |
haysc | c9f9500 | 2016-12-05 14:24:32 -0800 | [diff] [blame] | 186 | nativeConfig->audio_jitter_buffer_fast_accelerate = |
| 187 | _audioJitterBufferFastAccelerate ? true : false; |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 188 | nativeConfig->ice_connection_receiving_timeout = |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 189 | _iceConnectionReceivingTimeout; |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 190 | nativeConfig->ice_backup_candidate_pair_ping_interval = |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 191 | _iceBackupCandidatePairPingInterval; |
Piotr (Peter) Slatala | 88d8d7d | 2018-10-26 15:06:17 -0700 | [diff] [blame] | 192 | nativeConfig->use_media_transport = _useMediaTransport; |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 193 | rtc::KeyType keyType = |
| 194 | [[self class] nativeEncryptionKeyTypeForKeyType:_keyType]; |
Michael Iedema | ccee56b | 2018-07-05 15:28:24 +0200 | [diff] [blame] | 195 | if (_certificate != nullptr) { |
| 196 | // if offered a pemcert use it... |
| 197 | RTC_LOG(LS_INFO) << "Have configured cert - using it."; |
| 198 | std::string pem_private_key = [[_certificate private_key] UTF8String]; |
| 199 | std::string pem_certificate = [[_certificate certificate] UTF8String]; |
| 200 | rtc::RTCCertificatePEM pem = rtc::RTCCertificatePEM(pem_private_key, pem_certificate); |
| 201 | rtc::scoped_refptr<rtc::RTCCertificate> certificate = rtc::RTCCertificate::FromPEM(pem); |
| 202 | RTC_LOG(LS_INFO) << "Created cert from PEM strings."; |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 203 | if (!certificate) { |
Michael Iedema | ccee56b | 2018-07-05 15:28:24 +0200 | [diff] [blame] | 204 | RTC_LOG(LS_ERROR) << "Failed to generate certificate from PEM."; |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 205 | return nullptr; |
tkchin | ab8f82f | 2016-01-27 17:50:11 -0800 | [diff] [blame] | 206 | } |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 207 | nativeConfig->certificates.push_back(certificate); |
Michael Iedema | ccee56b | 2018-07-05 15:28:24 +0200 | [diff] [blame] | 208 | } else { |
| 209 | RTC_LOG(LS_INFO) << "Don't have configured cert."; |
| 210 | // Generate non-default certificate. |
| 211 | if (keyType != rtc::KT_DEFAULT) { |
| 212 | rtc::scoped_refptr<rtc::RTCCertificate> certificate = |
| 213 | rtc::RTCCertificateGenerator::GenerateCertificate(rtc::KeyParams(keyType), |
| 214 | absl::optional<uint64_t>()); |
| 215 | if (!certificate) { |
| 216 | RTCLogError(@"Failed to generate certificate."); |
| 217 | return nullptr; |
| 218 | } |
| 219 | nativeConfig->certificates.push_back(certificate); |
| 220 | } |
tkchin | ab8f82f | 2016-01-27 17:50:11 -0800 | [diff] [blame] | 221 | } |
deadbeef | be0c96f | 2016-05-18 16:20:14 -0700 | [diff] [blame] | 222 | nativeConfig->ice_candidate_pool_size = _iceCandidatePoolSize; |
honghaiz | af6b6e0 | 2016-07-11 15:09:26 -0700 | [diff] [blame] | 223 | nativeConfig->prune_turn_ports = _shouldPruneTurnPorts ? true : false; |
Taylor Brandstetter | e985111 | 2016-07-01 11:11:13 -0700 | [diff] [blame] | 224 | nativeConfig->presume_writable_when_fully_relayed = |
honghaiz | af6b6e0 | 2016-07-11 15:09:26 -0700 | [diff] [blame] | 225 | _shouldPresumeWritableWhenFullyRelayed ? true : false; |
skvlad | a5d94ff | 2017-02-02 13:02:30 -0800 | [diff] [blame] | 226 | if (_iceCheckMinInterval != nil) { |
Danil Chapovalov | 196100e | 2018-06-21 10:17:24 +0200 | [diff] [blame] | 227 | nativeConfig->ice_check_min_interval = absl::optional<int>(_iceCheckMinInterval.intValue); |
skvlad | a5d94ff | 2017-02-02 13:02:30 -0800 | [diff] [blame] | 228 | } |
Steve Anton | d295e40 | 2017-07-14 16:06:41 -0700 | [diff] [blame] | 229 | if (_iceRegatherIntervalRange != nil) { |
| 230 | std::unique_ptr<rtc::IntervalRange> nativeIntervalRange( |
| 231 | _iceRegatherIntervalRange.nativeIntervalRange); |
| 232 | nativeConfig->ice_regather_interval_range = |
Danil Chapovalov | 196100e | 2018-06-21 10:17:24 +0200 | [diff] [blame] | 233 | absl::optional<rtc::IntervalRange>(*nativeIntervalRange); |
Steve Anton | d295e40 | 2017-07-14 16:06:41 -0700 | [diff] [blame] | 234 | } |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 235 | nativeConfig->sdp_semantics = [[self class] nativeSdpSemanticsForSdpSemantics:_sdpSemantics]; |
Zeke Chin | ef1140e | 2017-10-27 15:42:08 -0700 | [diff] [blame] | 236 | if (_turnCustomizer) { |
| 237 | nativeConfig->turn_customizer = _turnCustomizer; |
| 238 | } |
Zhi Huang | b57e169 | 2018-06-12 11:41:11 -0700 | [diff] [blame] | 239 | nativeConfig->active_reset_srtp_params = _activeResetSrtpParams ? true : false; |
Benjamin Wright | 8c27cca | 2018-10-25 10:16:44 -0700 | [diff] [blame] | 240 | if (_cryptoOptions) { |
| 241 | webrtc::CryptoOptions nativeCryptoOptions; |
| 242 | nativeCryptoOptions.srtp.enable_gcm_crypto_suites = |
| 243 | _cryptoOptions.srtpEnableGcmCryptoSuites ? true : false; |
| 244 | nativeCryptoOptions.srtp.enable_aes128_sha1_32_crypto_cipher = |
| 245 | _cryptoOptions.srtpEnableAes128Sha1_32CryptoCipher ? true : false; |
| 246 | nativeCryptoOptions.srtp.enable_encrypted_rtp_header_extensions = |
| 247 | _cryptoOptions.srtpEnableEncryptedRtpHeaderExtensions ? true : false; |
| 248 | nativeCryptoOptions.sframe.require_frame_encryption = |
| 249 | _cryptoOptions.sframeRequireFrameEncryption ? true : false; |
| 250 | nativeConfig->crypto_options = absl::optional<webrtc::CryptoOptions>(nativeCryptoOptions); |
| 251 | } |
| 252 | |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 253 | return nativeConfig.release(); |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 254 | } |
| 255 | |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 256 | + (webrtc::PeerConnectionInterface::IceTransportsType) |
| 257 | nativeTransportsTypeForTransportPolicy:(RTCIceTransportPolicy)policy { |
| 258 | switch (policy) { |
| 259 | case RTCIceTransportPolicyNone: |
| 260 | return webrtc::PeerConnectionInterface::kNone; |
| 261 | case RTCIceTransportPolicyRelay: |
| 262 | return webrtc::PeerConnectionInterface::kRelay; |
| 263 | case RTCIceTransportPolicyNoHost: |
| 264 | return webrtc::PeerConnectionInterface::kNoHost; |
| 265 | case RTCIceTransportPolicyAll: |
| 266 | return webrtc::PeerConnectionInterface::kAll; |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | + (RTCIceTransportPolicy)transportPolicyForTransportsType: |
| 271 | (webrtc::PeerConnectionInterface::IceTransportsType)nativeType { |
| 272 | switch (nativeType) { |
| 273 | case webrtc::PeerConnectionInterface::kNone: |
| 274 | return RTCIceTransportPolicyNone; |
| 275 | case webrtc::PeerConnectionInterface::kRelay: |
| 276 | return RTCIceTransportPolicyRelay; |
| 277 | case webrtc::PeerConnectionInterface::kNoHost: |
| 278 | return RTCIceTransportPolicyNoHost; |
| 279 | case webrtc::PeerConnectionInterface::kAll: |
| 280 | return RTCIceTransportPolicyAll; |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | + (NSString *)stringForTransportPolicy:(RTCIceTransportPolicy)policy { |
| 285 | switch (policy) { |
| 286 | case RTCIceTransportPolicyNone: |
| 287 | return @"NONE"; |
| 288 | case RTCIceTransportPolicyRelay: |
| 289 | return @"RELAY"; |
| 290 | case RTCIceTransportPolicyNoHost: |
| 291 | return @"NO_HOST"; |
| 292 | case RTCIceTransportPolicyAll: |
| 293 | return @"ALL"; |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | + (webrtc::PeerConnectionInterface::BundlePolicy)nativeBundlePolicyForPolicy: |
| 298 | (RTCBundlePolicy)policy { |
| 299 | switch (policy) { |
| 300 | case RTCBundlePolicyBalanced: |
| 301 | return webrtc::PeerConnectionInterface::kBundlePolicyBalanced; |
| 302 | case RTCBundlePolicyMaxCompat: |
| 303 | return webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat; |
| 304 | case RTCBundlePolicyMaxBundle: |
| 305 | return webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | + (RTCBundlePolicy)bundlePolicyForNativePolicy: |
| 310 | (webrtc::PeerConnectionInterface::BundlePolicy)nativePolicy { |
| 311 | switch (nativePolicy) { |
| 312 | case webrtc::PeerConnectionInterface::kBundlePolicyBalanced: |
| 313 | return RTCBundlePolicyBalanced; |
| 314 | case webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat: |
| 315 | return RTCBundlePolicyMaxCompat; |
| 316 | case webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle: |
| 317 | return RTCBundlePolicyMaxBundle; |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | + (NSString *)stringForBundlePolicy:(RTCBundlePolicy)policy { |
| 322 | switch (policy) { |
| 323 | case RTCBundlePolicyBalanced: |
| 324 | return @"BALANCED"; |
| 325 | case RTCBundlePolicyMaxCompat: |
| 326 | return @"MAX_COMPAT"; |
| 327 | case RTCBundlePolicyMaxBundle: |
| 328 | return @"MAX_BUNDLE"; |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | + (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativeRtcpMuxPolicyForPolicy: |
| 333 | (RTCRtcpMuxPolicy)policy { |
| 334 | switch (policy) { |
| 335 | case RTCRtcpMuxPolicyNegotiate: |
| 336 | return webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate; |
| 337 | case RTCRtcpMuxPolicyRequire: |
| 338 | return webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | + (RTCRtcpMuxPolicy)rtcpMuxPolicyForNativePolicy: |
| 343 | (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativePolicy { |
| 344 | switch (nativePolicy) { |
| 345 | case webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate: |
| 346 | return RTCRtcpMuxPolicyNegotiate; |
| 347 | case webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire: |
| 348 | return RTCRtcpMuxPolicyRequire; |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | + (NSString *)stringForRtcpMuxPolicy:(RTCRtcpMuxPolicy)policy { |
| 353 | switch (policy) { |
| 354 | case RTCRtcpMuxPolicyNegotiate: |
| 355 | return @"NEGOTIATE"; |
| 356 | case RTCRtcpMuxPolicyRequire: |
| 357 | return @"REQUIRE"; |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | + (webrtc::PeerConnectionInterface::TcpCandidatePolicy) |
| 362 | nativeTcpCandidatePolicyForPolicy:(RTCTcpCandidatePolicy)policy { |
| 363 | switch (policy) { |
| 364 | case RTCTcpCandidatePolicyEnabled: |
| 365 | return webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled; |
| 366 | case RTCTcpCandidatePolicyDisabled: |
| 367 | return webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled; |
| 368 | } |
| 369 | } |
| 370 | |
Honghai Zhang | 46007ae | 2016-06-03 16:31:32 -0700 | [diff] [blame] | 371 | + (webrtc::PeerConnectionInterface::CandidateNetworkPolicy) |
| 372 | nativeCandidateNetworkPolicyForPolicy:(RTCCandidateNetworkPolicy)policy { |
| 373 | switch (policy) { |
| 374 | case RTCCandidateNetworkPolicyAll: |
| 375 | return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll; |
| 376 | case RTCCandidateNetworkPolicyLowCost: |
| 377 | return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost; |
| 378 | } |
| 379 | } |
| 380 | |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 381 | + (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy: |
| 382 | (webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy { |
| 383 | switch (nativePolicy) { |
| 384 | case webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled: |
| 385 | return RTCTcpCandidatePolicyEnabled; |
| 386 | case webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled: |
| 387 | return RTCTcpCandidatePolicyDisabled; |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | + (NSString *)stringForTcpCandidatePolicy:(RTCTcpCandidatePolicy)policy { |
| 392 | switch (policy) { |
| 393 | case RTCTcpCandidatePolicyEnabled: |
| 394 | return @"TCP_ENABLED"; |
| 395 | case RTCTcpCandidatePolicyDisabled: |
| 396 | return @"TCP_DISABLED"; |
| 397 | } |
| 398 | } |
| 399 | |
Honghai Zhang | 46007ae | 2016-06-03 16:31:32 -0700 | [diff] [blame] | 400 | + (RTCCandidateNetworkPolicy)candidateNetworkPolicyForNativePolicy: |
| 401 | (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)nativePolicy { |
| 402 | switch (nativePolicy) { |
| 403 | case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll: |
| 404 | return RTCCandidateNetworkPolicyAll; |
| 405 | case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost: |
| 406 | return RTCCandidateNetworkPolicyLowCost; |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | + (NSString *)stringForCandidateNetworkPolicy: |
| 411 | (RTCCandidateNetworkPolicy)policy { |
| 412 | switch (policy) { |
| 413 | case RTCCandidateNetworkPolicyAll: |
| 414 | return @"CANDIDATE_ALL_NETWORKS"; |
| 415 | case RTCCandidateNetworkPolicyLowCost: |
| 416 | return @"CANDIDATE_LOW_COST_NETWORKS"; |
| 417 | } |
| 418 | } |
| 419 | |
Honghai Zhang | 3108fc9 | 2016-05-11 10:10:39 -0700 | [diff] [blame] | 420 | + (webrtc::PeerConnectionInterface::ContinualGatheringPolicy) |
| 421 | nativeContinualGatheringPolicyForPolicy: |
| 422 | (RTCContinualGatheringPolicy)policy { |
| 423 | switch (policy) { |
| 424 | case RTCContinualGatheringPolicyGatherOnce: |
| 425 | return webrtc::PeerConnectionInterface::GATHER_ONCE; |
| 426 | case RTCContinualGatheringPolicyGatherContinually: |
| 427 | return webrtc::PeerConnectionInterface::GATHER_CONTINUALLY; |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | + (RTCContinualGatheringPolicy)continualGatheringPolicyForNativePolicy: |
| 432 | (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)nativePolicy { |
| 433 | switch (nativePolicy) { |
| 434 | case webrtc::PeerConnectionInterface::GATHER_ONCE: |
| 435 | return RTCContinualGatheringPolicyGatherOnce; |
| 436 | case webrtc::PeerConnectionInterface::GATHER_CONTINUALLY: |
| 437 | return RTCContinualGatheringPolicyGatherContinually; |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | + (NSString *)stringForContinualGatheringPolicy: |
| 442 | (RTCContinualGatheringPolicy)policy { |
| 443 | switch (policy) { |
| 444 | case RTCContinualGatheringPolicyGatherOnce: |
| 445 | return @"GATHER_ONCE"; |
| 446 | case RTCContinualGatheringPolicyGatherContinually: |
| 447 | return @"GATHER_CONTINUALLY"; |
| 448 | } |
| 449 | } |
| 450 | |
hbos | f9da44d | 2016-06-09 03:18:28 -0700 | [diff] [blame] | 451 | + (rtc::KeyType)nativeEncryptionKeyTypeForKeyType: |
| 452 | (RTCEncryptionKeyType)keyType { |
| 453 | switch (keyType) { |
| 454 | case RTCEncryptionKeyTypeRSA: |
| 455 | return rtc::KT_RSA; |
| 456 | case RTCEncryptionKeyTypeECDSA: |
| 457 | return rtc::KT_ECDSA; |
| 458 | } |
| 459 | } |
| 460 | |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 461 | + (webrtc::SdpSemantics)nativeSdpSemanticsForSdpSemantics:(RTCSdpSemantics)sdpSemantics { |
| 462 | switch (sdpSemantics) { |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 463 | case RTCSdpSemanticsPlanB: |
| 464 | return webrtc::SdpSemantics::kPlanB; |
| 465 | case RTCSdpSemanticsUnifiedPlan: |
| 466 | return webrtc::SdpSemantics::kUnifiedPlan; |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | + (RTCSdpSemantics)sdpSemanticsForNativeSdpSemantics:(webrtc::SdpSemantics)sdpSemantics { |
| 471 | switch (sdpSemantics) { |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 472 | case webrtc::SdpSemantics::kPlanB: |
| 473 | return RTCSdpSemanticsPlanB; |
| 474 | case webrtc::SdpSemantics::kUnifiedPlan: |
| 475 | return RTCSdpSemanticsUnifiedPlan; |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | + (NSString *)stringForSdpSemantics:(RTCSdpSemantics)sdpSemantics { |
| 480 | switch (sdpSemantics) { |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 481 | case RTCSdpSemanticsPlanB: |
| 482 | return @"PLAN_B"; |
| 483 | case RTCSdpSemanticsUnifiedPlan: |
| 484 | return @"UNIFIED_PLAN"; |
| 485 | } |
| 486 | } |
| 487 | |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 488 | @end |