Skip to content

Commit

Permalink
refactor(openvpn): update getOpenVPNLog method
Browse files Browse the repository at this point in the history
in VPNManager.swift
  • Loading branch information
jurajhilje committed Jan 9, 2024
1 parent 94c27f7 commit 17d10a2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
25 changes: 4 additions & 21 deletions IVPNClient/Managers/VPNManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -399,32 +399,15 @@ class VPNManager {
}

func getOpenVPNLog(completion: @escaping (String?) -> Void) {
guard let session = openvpnManager?.connection as? NETunnelProviderSession else {
completion(nil)
return
}
let maxBytes = UInt64(Config.maxBytes)

do {
try session.sendProviderMessage(OpenVPNProvider.Message.requestLog.data) { data in
guard let data = data, !data.isEmpty else {
completion(nil)
return
}

guard let newestLog = String(data: data, encoding: .utf8), !newestLog.isEmpty else {
completion(nil)
return
}

completion(newestLog)
return
}
} catch {
guard let url = FileManager.openvpnLogTextFileURL else {
completion(nil)
return
}

completion(nil)
let lines = url.trailingLines(bytes: maxBytes)
completion(lines.joined(separator: "\n"))
}

func getWireGuardLog(completion: @escaping (String?) -> Void) {
Expand Down
5 changes: 5 additions & 0 deletions IVPNClient/Utilities/Extensions/FileManager+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,15 @@ extension FileManager {
return sharedFolderURL?.appendingPathComponent("WireGuard.log")
}

static var openvpnLogTextFileURL: URL? {
return sharedFolderURL?.appendingPathComponent("Tunnel.log")
}

static func deleteFile(at url: URL) -> Bool {
do {
try FileManager.default.removeItem(at: url)
} catch {
log(.error, message: error.localizedDescription)
return false
}
return true
Expand Down

0 comments on commit 17d10a2

Please sign in to comment.