Use instance variables

This commit is contained in:
Ian VanSchooten 2024-10-16 13:57:04 -04:00
parent 1590b8772c
commit 7b1b2a4732
3 changed files with 13 additions and 13 deletions

View File

@ -7,7 +7,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
private var networkMonitor: NWPathMonitor? private var networkMonitor: NWPathMonitor?
private var site: Site? private var site: Site?
static let log = Logger(subsystem: "net.defined.mobileNebula", category: "PacketTunnelProvider") private let log = Logger(subsystem: "net.defined.mobileNebula", category: "PacketTunnelProvider")
private var nebula: MobileNebulaNebula? private var nebula: MobileNebulaNebula?
private var dnUpdater = DNUpdater() private var dnUpdater = DNUpdater()
private var didSleep = false private var didSleep = false
@ -37,7 +37,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
config = try site!.getConfig() config = try site!.getConfig()
} catch { } catch {
//TODO: need a way to notify the app //TODO: need a way to notify the app
Self.log.error("Failed to render config from vpn object") log.error("Failed to render config from vpn object")
return completionHandler(error) return completionHandler(error)
} }
@ -89,7 +89,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
self.startNetworkMonitor() self.startNetworkMonitor()
if err != nil { if err != nil {
Self.log.error("We had an error starting up: \(err, privacy: .public)") self.log.error("We had an error starting up: \(err, privacy: .public)")
return completionHandler(err!) return completionHandler(err!)
} }
@ -106,7 +106,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
try self.nebula?.reload(String(data: newSite.getConfig(), encoding: .utf8), key: newSite.getKey()) try self.nebula?.reload(String(data: newSite.getConfig(), encoding: .utf8), key: newSite.getKey())
} catch { } catch {
Self.log.error("Got an error while updating nebula \(error.localizedDescription, privacy: .public)") log.error("Got an error while updating nebula \(error.localizedDescription, privacy: .public)")
} }
} }
@ -162,7 +162,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
override func handleAppMessage(_ data: Data, completionHandler: ((Data?) -> Void)? = nil) { override func handleAppMessage(_ data: Data, completionHandler: ((Data?) -> Void)? = nil) {
guard let call = try? JSONDecoder().decode(IPCRequest.self, from: data) else { guard let call = try? JSONDecoder().decode(IPCRequest.self, from: data) else {
Self.log.error("Failed to decode IPCRequest from network extension") log.error("Failed to decode IPCRequest from network extension")
return return
} }
@ -190,7 +190,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
if nebula == nil { if nebula == nil {
// Respond with an empty success message in the event a command comes in before we've truly started // Respond with an empty success message in the event a command comes in before we've truly started
Self.log.warning("Received command but do not have a nebula instance") log.warning("Received command but do not have a nebula instance")
return completionHandler!(try? JSONEncoder().encode(IPCResponse.init(type: .success, message: nil))) return completionHandler!(try? JSONEncoder().encode(IPCResponse.init(type: .success, message: nil)))
} }

View File

@ -3,7 +3,7 @@ import MobileNebula
import SwiftyJSON import SwiftyJSON
import os.log import os.log
var log = Logger(subsystem: "net.defined.mobileNebula", category: "Site") let log = Logger(subsystem: "net.defined.mobileNebula", category: "Site")
extension String: Error {} extension String: Error {}

View File

@ -3,8 +3,8 @@ import os.log
class DNUpdater { class DNUpdater {
private let apiClient = APIClient() private let apiClient = APIClient()
private let timer = RepeatingTimer(timeInterval: 15 * 60) // 15 * 60 is 15 minutes private let timer = RepeatingTimer(timeInterval: 30) // 15 * 60 is 15 minutes
static let log = Logger(subsystem: "net.defined.mobileNebula", category: "DNUpdater") private let log = Logger(subsystem: "net.defined.mobileNebula", category: "DNUpdater")
func updateAll(onUpdate: @escaping (Site) -> ()) { func updateAll(onUpdate: @escaping (Site) -> ()) {
_ = SiteList{ (sites, _) -> () in _ = SiteList{ (sites, _) -> () in
@ -57,7 +57,7 @@ class DNUpdater {
} catch (APIClientError.invalidCredentials) { } catch (APIClientError.invalidCredentials) {
if (!credentials.invalid) { if (!credentials.invalid) {
try site.invalidateDNCredentials() try site.invalidateDNCredentials()
Self.log.notice("Invalidated credentials in site: \(site.name, privacy: .public)") log.notice("Invalidated credentials in site: \(site.name, privacy: .public)")
} }
return return
@ -65,7 +65,7 @@ class DNUpdater {
newSite?.save(manager: nil) { error in newSite?.save(manager: nil) { error in
if (error != nil) { if (error != nil) {
Self.log.error("failed to save update: \(error!.localizedDescription, privacy: .public)") self.log.error("failed to save update: \(error!.localizedDescription, privacy: .public)")
} else { } else {
onUpdate(Site(incoming: newSite!)) onUpdate(Site(incoming: newSite!))
} }
@ -73,11 +73,11 @@ class DNUpdater {
if (credentials.invalid) { if (credentials.invalid) {
try site.validateDNCredentials() try site.validateDNCredentials()
Self.log.notice("Revalidated credentials in site \(site.name, privacy: .public)") log.notice("Revalidated credentials in site \(site.name, privacy: .public)")
} }
} catch { } catch {
Self.log.error("Error while updating \(site.name, privacy: .public): \(error.localizedDescription, privacy: .public)") log.error("Error while updating \(site.name, privacy: .public): \(error.localizedDescription, privacy: .public)")
} }
} }
} }