Skip to content

Commit

Permalink
Merges back the changes from release/7.111.0
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoreymendez committed Mar 7, 2024
2 parents 21a594f + 066711a commit ea5d541
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 11 deletions.
15 changes: 14 additions & 1 deletion Core/Pixel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,27 @@ extension Pixel {
}
}

/// NSError supports this through `NSUnderlyingError`, but there's no support for this for Swift's `Error`. This protocol does that.
///
/// The reason why this protocol returns a code and a domain instead of just an `Error` or `NSError` is so that the error implementing
/// this protocol has full control over these values, and is able to override them as it best sees fit.
///
protocol ErrorWithUnderlyingError: Error {
var underlyingErrorCode: Int { get }
var underlyingErrorDomain: String { get }
}

extension Dictionary where Key == String, Value == String {
mutating func appendErrorPixelParams(error: Error) {
let nsError = error as NSError

self[PixelParameters.errorCode] = "\(nsError.code)"
self[PixelParameters.errorDomain] = nsError.domain

if let underlyingError = nsError.userInfo["NSUnderlyingError"] as? NSError {
if let underlyingError = error as? ErrorWithUnderlyingError {
self[PixelParameters.underlyingErrorCode] = "\(underlyingError.underlyingErrorCode)"
self[PixelParameters.underlyingErrorDomain] = underlyingError.underlyingErrorDomain
} else if let underlyingError = nsError.userInfo["NSUnderlyingError"] as? NSError {
self[PixelParameters.underlyingErrorCode] = "\(underlyingError.code)"
self[PixelParameters.underlyingErrorDomain] = underlyingError.domain
} else if let sqlErrorCode = nsError.userInfo["NSSQLiteErrorDomain"] as? NSNumber {
Expand Down
25 changes: 25 additions & 0 deletions Core/PixelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,18 @@ extension Pixel {
case networkProtectionActiveUser
case networkProtectionNewUser

case networkProtectionControllerStartAttempt
case networkProtectionControllerStartSuccess
case networkProtectionControllerStartFailure

case networkProtectionTunnelStartAttempt
case networkProtectionTunnelStartSuccess
case networkProtectionTunnelStartFailure

case networkProtectionTunnelUpdateAttempt
case networkProtectionTunnelUpdateSuccess
case networkProtectionTunnelUpdateFailure

case networkProtectionEnableAttemptConnecting
case networkProtectionEnableAttemptSuccess
case networkProtectionEnableAttemptFailure
Expand All @@ -280,6 +292,8 @@ extension Pixel {

case networkProtectionBreakageReport

case networkProtectionRekeyAttempt
case networkProtectionRekeyFailure
case networkProtectionRekeyCompleted

case networkProtectionTunnelConfigurationNoServerRegistrationInfo
Expand Down Expand Up @@ -786,14 +800,25 @@ extension Pixel.Event {

case .networkProtectionActiveUser: return "m_netp_daily_active_d"
case .networkProtectionNewUser: return "m_netp_daily_active_u"
case .networkProtectionControllerStartAttempt: return "m_netp_controller_start_attempt"
case .networkProtectionControllerStartSuccess: return "m_netp_controller_start_success"
case .networkProtectionControllerStartFailure: return "m_netp_controller_start_failure"
case .networkProtectionTunnelStartAttempt: return "m_netp_tunnel_start_attempt"
case .networkProtectionTunnelStartSuccess: return "m_netp_tunnel_start_success"
case .networkProtectionTunnelStartFailure: return "m_netp_tunnel_start_failure"
case .networkProtectionTunnelUpdateAttempt: return "m_netp_tunnel_update_attempt"
case .networkProtectionTunnelUpdateSuccess: return "m_netp_tunnel_update_success"
case .networkProtectionTunnelUpdateFailure: return "m_netp_tunnel_update_failure"
case .networkProtectionEnableAttemptConnecting: return "m_netp_ev_enable_attempt"
case .networkProtectionEnableAttemptSuccess: return "m_netp_ev_enable_attempt_success"
case .networkProtectionEnableAttemptFailure: return "m_netp_ev_enable_attempt_failure"
case .networkProtectionTunnelFailureDetected: return "m_netp_ev_tunnel_failure"
case .networkProtectionTunnelFailureRecovered: return "m_netp_ev_tunnel_failure_recovered"
case .networkProtectionLatency(let quality): return "m_netp_ev_\(quality.rawValue)_latency"
case .networkProtectionLatencyError: return "m_netp_ev_latency_error_d"
case .networkProtectionRekeyAttempt: return "m_mac_netp_rekey_attempt"
case .networkProtectionRekeyCompleted: return "m_netp_rekey_completed"
case .networkProtectionRekeyFailure: return "m_netp_rekey_failure"
case .networkProtectionEnabledOnSearch: return "m_netp_ev_enabled_on_search"
case .networkProtectionBreakageReport: return "m_vpn_breakage_report"
case .networkProtectionTunnelConfigurationNoServerRegistrationInfo: return "m_netp_tunnel_config_error_no_server_registration_info"
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10045,7 +10045,7 @@
repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 118.0.0;
version = 119.0.1;
};
};
B6F997C22B8F374300476735 /* XCRemoteSwiftPackageReference "apple-toolbox" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/DuckDuckGo/BrowserServicesKit",
"state" : {
"revision" : "2181cdcd27be961f10d988fbb202431a6ec6d56d",
"version" : "118.0.0"
"revision" : "a32ff4084e910354bdd948812793de6b04804a1b",
"version" : "119.0.1"
}
},
{
Expand All @@ -41,8 +41,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/content-scope-scripts",
"state" : {
"revision" : "59752eb7973d3e3b0c23255ff51359f48b343f15",
"version" : "5.2.0"
"revision" : "f6241631fc14cc2d0f47950bfdc4d6c30bf90130",
"version" : "5.4.0"
}
},
{
Expand Down
12 changes: 9 additions & 3 deletions DuckDuckGo/AppDelegate+Waitlists.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Core
import BackgroundTasks
import NetworkProtection
import Waitlist
import BrowserServicesKit

extension AppDelegate {

Expand Down Expand Up @@ -51,12 +52,17 @@ extension AppDelegate {

VPNWaitlist.shared.fetchInviteCodeIfAvailable { [weak self] error in
guard error == nil else {
#if !DEBUG

if error == .alreadyHasInviteCode, UIApplication.shared.applicationState == .active {
// If the user already has an invite code but their auth token has gone missing, attempt to redeem it again.
let tokenStore = NetworkProtectionKeychainTokenStore()
let waitlistStorage = VPNWaitlist.shared.waitlistStorage
if let inviteCode = waitlistStorage.getWaitlistInviteCode(), !tokenStore.isFeatureActivated {
let configManager = ContentBlocking.shared.privacyConfigurationManager
let waitlistBetaActive = configManager.privacyConfig.isSubfeatureEnabled(NetworkProtectionSubfeature.waitlistBetaActive)

if let inviteCode = waitlistStorage.getWaitlistInviteCode(),
!tokenStore.isFeatureActivated,
waitlistBetaActive {
let pixel: Pixel.Event = .networkProtectionWaitlistRetriedInviteCodeRedemption

do {
Expand All @@ -72,7 +78,7 @@ extension AppDelegate {
self?.fetchVPNWaitlistAuthToken(inviteCode: inviteCode)
}
}
#endif

return

}
Expand Down
5 changes: 5 additions & 0 deletions DuckDuckGo/NetworkProtectionTunnelController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,14 @@ final class NetworkProtectionTunnelController: TunnelController {
/// Starts the VPN connection used for Network Protection
///
func start() async {
Pixel.fire(pixel: .networkProtectionControllerStartAttempt)

do {
try await startWithError()
Pixel.fire(pixel: .networkProtectionControllerStartSuccess)
} catch {
Pixel.fire(pixel: .networkProtectionControllerStartFailure, error: error)

#if DEBUG
errorStore.lastErrorMessage = error.localizedDescription
#endif
Expand Down
1 change: 1 addition & 0 deletions DuckDuckGo/TabViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2605,6 +2605,7 @@ extension WKWebView {

extension UserContentController {

@MainActor
public convenience init(privacyConfigurationManager: PrivacyConfigurationManaging = ContentBlocking.shared.privacyConfigurationManager) {
self.init(assetsPublisher: ContentBlocking.shared.contentBlockingUpdating.userContentBlockingAssets,
privacyConfigurationManager: privacyConfigurationManager)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import NetworkExtension
import NetworkProtection
import Subscription

// swiftlint:disable type_body_length

// Initial implementation for initial Network Protection tests. Will be fleshed out with https://app.asana.com/0/1203137811378537/1204630829332227/f
final class NetworkProtectionPacketTunnelProvider: PacketTunnelProvider {

Expand Down Expand Up @@ -68,8 +70,33 @@ final class NetworkProtectionPacketTunnelProvider: PacketTunnelProvider {
guard quality != .unknown else { return }
DailyPixel.fireDailyAndCount(pixel: .networkProtectionLatency(quality: quality))
}
case .rekeyCompleted:
Pixel.fire(pixel: .networkProtectionRekeyCompleted)
case .rekeyAttempt(let step):
switch step {
case .begin:
DailyPixel.fireDailyAndCount(pixel: .networkProtectionRekeyAttempt)
case .failure(let error):
DailyPixel.fireDailyAndCount(pixel: .networkProtectionRekeyFailure, error: error)
case .success:
DailyPixel.fireDailyAndCount(pixel: .networkProtectionRekeyCompleted)
}
case .tunnelStartAttempt(let step):
switch step {
case .begin:
DailyPixel.fireDailyAndCount(pixel: .networkProtectionTunnelStartAttempt)
case .failure(let error):
DailyPixel.fireDailyAndCount(pixel: .networkProtectionTunnelStartFailure, error: error)
case .success:
DailyPixel.fireDailyAndCount(pixel: .networkProtectionTunnelStartSuccess)
}
case .tunnelUpdateAttempt(let step):
switch step {
case .begin:
DailyPixel.fireDailyAndCount(pixel: .networkProtectionTunnelUpdateAttempt)
case .failure(let error):
DailyPixel.fireDailyAndCount(pixel: .networkProtectionTunnelUpdateFailure, error: error)
case .success:
DailyPixel.fireDailyAndCount(pixel: .networkProtectionTunnelUpdateSuccess)
}
}
}

Expand Down Expand Up @@ -293,4 +320,6 @@ final class NetworkProtectionPacketTunnelProvider: PacketTunnelProvider {
}
}

// swiftlint:enable type_body_length

#endif

0 comments on commit ea5d541

Please sign in to comment.