Skip to content

Commit 8fb5d68

Browse files
Revert "KM-16549: remove Reachability library (#366)"
This reverts commit e528d19.
1 parent 7d0c583 commit 8fb5d68

7 files changed

Lines changed: 39 additions & 65 deletions

File tree

LocalPackages/PIALibrary/Package.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@ let package = Package(
2626
.package(url: "git@github.com:pia-foss/mobile-ios-openvpn.git", exact: "2.2.6"),
2727
.package(url: "git@github.com:pia-foss/mobile-ios-wireguard.git", exact: "1.0.6"),
2828
.package(url: "https://github.com/apple/swift-algorithms", exact: "1.2.1"),
29-
.package(url: "https://github.com/apple/swift-log", exact: "1.13.1")
29+
.package(url: "https://github.com/apple/swift-log", exact: "1.13.1"),
30+
.package(url: "https://github.com/ashleymills/Reachability.swift.git", exact: "5.2.4")
3031
],
3132
targets: [
3233
.target(
3334
name: "PIALibrary",
3435
dependencies: [
3536
.product(name: "Algorithms", package: "swift-algorithms"),
3637
.product(name: "Logging", package: "swift-log"),
38+
.product(name: "Reachability", package: "Reachability.swift"),
3739
.product(name: "PIAKPI", package: "PIAKPI"),
3840
.product(name: "PIACSI", package: "PIACSI"),
3941
.product(name: "PIARegions", package: "PIARegions"),

LocalPackages/PIALibrary/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ This project is licensed under the [MIT (Expat) license](https://choosealicense.
302302

303303
## Acknowledgements
304304

305+
- ReachabilitySwift - © 2016 Ashley Mills
305306
- TunnelKit - © 2018 - Present Davide de Rosa (https://github.com/passepartoutvpn/tunnelkit) - TunnelKit is not MIT software and remains under the terms of the GPL license (https://github.com/passepartoutvpn/tunnelkit/blob/master/LICENSE)
306307

307308
[pia-image]: https://www.privateinternetaccess.com/assets/PIALogo2x-0d1e1094ac909ea4c93df06e2da3db4ee8a73d8b2770f0f7d768a8603c62a82f.png

LocalPackages/PIALibrary/Sources/PIALibrary/Daemons/ConnectivityDaemon.swift

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
//
2222

2323
import Foundation
24+
import Reachability
2425

2526
private let log = PIALogger.logger(for: ConnectivityDaemon.self)
2627

@@ -38,7 +39,7 @@ final class ConnectivityDaemon: Daemon, ConfigurationAccess, DatabaseAccess, Pre
3839

3940
private(set) var hasEnabledUpdates: Bool = false
4041

41-
private let networkObserver = NetworkObserver()
42+
private let reachability = try! Reachability(hostname: "8.8.8.8")
4243

4344
private lazy var checker = ConnectivityChecker(webServices: accessedWebServices)
4445

@@ -57,7 +58,7 @@ final class ConnectivityDaemon: Daemon, ConfigurationAccess, DatabaseAccess, Pre
5758

5859
let nc = NotificationCenter.default
5960
nc.addObserver(self, selector: #selector(vpnStatusDidChange(notification:)), name: .PIADaemonsDidUpdateVPNStatus, object: nil)
60-
startNetworkObserver()
61+
startReachability()
6162
}
6263

6364
func enableUpdates() {
@@ -69,13 +70,12 @@ final class ConnectivityDaemon: Daemon, ConfigurationAccess, DatabaseAccess, Pre
6970
checkConnectivityOrRetry()
7071
}
7172

72-
private func startNetworkObserver() {
73-
log.debug("Configuring for network observer...")
74-
accessedDatabase.transient.isNetworkReachable = networkObserver.isReachable
73+
private func startReachability() {
74+
log.debug("Configuring for reachability...")
75+
accessedDatabase.transient.isNetworkReachable = (reachability.connection != .unavailable)
7576
log.debug("Initial network state is \(accessedDatabase.transient.isNetworkReachable ? "REACHABLE" : "NOT REACHABLE")")
7677

77-
networkObserver.whenReachable = { [weak self] in
78-
guard let self else { return }
78+
reachability.whenReachable = { (reach) in
7979
DispatchQueue.main.async {
8080
guard !self.accessedDatabase.transient.isNetworkReachable else {
8181
if (self.accessedDatabase.transient.vpnStatus != .connected) {
@@ -88,8 +88,7 @@ final class ConnectivityDaemon: Daemon, ConfigurationAccess, DatabaseAccess, Pre
8888
Macros.postNotification(.ConnectivityDaemonDidGetReachable)
8989
}
9090
}
91-
networkObserver.whenUnreachable = { [weak self] in
92-
guard let self else { return }
91+
reachability.whenUnreachable = { (reach) in
9392
DispatchQueue.main.async {
9493
guard self.accessedDatabase.transient.vpnStatus != .connecting else {
9594
// while connecting we are unreachable, but expected, skip reporting
@@ -103,9 +102,9 @@ final class ConnectivityDaemon: Daemon, ConfigurationAccess, DatabaseAccess, Pre
103102
Macros.postNotification(.ConnectivityDaemonDidGetUnreachable)
104103
}
105104
}
105+
try? reachability.startNotifier()
106106

107-
networkObserver.start()
108-
log.debug("Network observer started")
107+
log.debug("Reachability notifier started")
109108
}
110109

111110
private func checkConnectivityOrRetry() {

LocalPackages/PIALibrary/Sources/PIALibrary/Daemons/NetworkObserver.swift

Lines changed: 0 additions & 53 deletions
This file was deleted.

PIA VPN-tvOS/Resources/Licences.plist

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
<dict>
55
<key>Licenses</key>
66
<array>
7+
<dict>
8+
<key>Name</key>
9+
<string>ReachabilitySwift</string>
10+
<key>Copyright</key>
11+
<string>Copyright (c) 2016 Ashley Mills</string>
12+
<key>LicenseURL</key>
13+
<string>https://raw.githubusercontent.com/ashleymills/Reachability.swift/master/LICENSE</string>
14+
</dict>
715
<dict>
816
<key>Name</key>
917
<string>TunnelKit</string>

PIA VPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PIA VPN/Resources/Components.plist

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@
3939
<key>LicenseURL</key>
4040
<string>https://www.openssl.org/source/license.txt</string>
4141
</dict>
42+
<dict>
43+
<key>Name</key>
44+
<string>ReachabilitySwift</string>
45+
<key>Copyright</key>
46+
<string>Copyright (c) 2016 Ashley Mills</string>
47+
<key>LicenseURL</key>
48+
<string>https://raw.githubusercontent.com/ashleymills/Reachability.swift/master/LICENSE</string>
49+
</dict>
4250
<dict>
4351
<key>Name</key>
4452
<string>GradientProgressBar</string>

0 commit comments

Comments
 (0)