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