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