Disable block & ignore filter during recording

This commit is contained in:
relikd
2020-08-29 18:36:41 +02:00
parent 8fcb5ad874
commit 7dbf21d564
5 changed files with 36 additions and 5 deletions

View File

@@ -23,6 +23,11 @@ enum PrefsShared {
get { Int("AutoDeleteLogsDays") }
set { Int("AutoDeleteLogsDays", newValue) }
}
static var CurrentlyRecording: Bool {
get { Bool("CurrentlyRecording") }
set { Bool("CurrentlyRecording", newValue) }
}
}

View File

@@ -46,7 +46,14 @@ class SimulatorVPN {
@objc static func insertRandom() {
//QLog.Debug("Inserting 1 periodic log entry")
let domain = "\(arc4random() % 5).count.test.com"
let rand = arc4random() % 8
let domain: String
switch rand {
case 6: domain = "tmp.b.test.com"
case 7: domain = "tmp.i.test.com"
case 8: domain = "tmp.bi.test.com"
default: domain = "\(rand).count.test.com"
}
let kill = hook.processDNSRequest(domain)
if kill { QLog.Info("Blocked: \(domain)") }
}

View File

@@ -157,4 +157,8 @@ struct VPNAppMessage {
static func notificationSettingsChanged() -> Self {
.init("notify-prefs-change:1")
}
/// Triggered whenever user taps on the start/stop recording button
static func isRecording(_ state: Bool) -> Self {
.init("recording-now:\(state ? 1 : 0)")
}
}

View File

@@ -8,6 +8,7 @@ class GlassVPNHook {
private var filterOptions: [(block: Bool, ignore: Bool, customA: Bool, customB: Bool)]!
private var autoDeleteTimer: Timer? = nil
private var cachedNotify: CachedConnectionAlert!
private var currentlyRecording: Bool = false
init() { reset() }
@@ -16,6 +17,7 @@ class GlassVPNHook {
reloadDomainFilter()
setAutoDelete(PrefsShared.AutoDeleteLogsDays)
cachedNotify = CachedConnectionAlert()
currentlyRecording = PrefsShared.CurrentlyRecording
}
/// Invalidate auto-delete timer and release stored properties. You should nullify this instance afterwards.
@@ -25,6 +27,7 @@ class GlassVPNHook {
autoDeleteTimer?.fire() // one last time before we quit
autoDeleteTimer?.invalidate()
cachedNotify = nil
currentlyRecording = false
}
/// Call this method from `PacketTunnelProvider.handleAppMessage(_:completionHandler:)`
@@ -43,6 +46,9 @@ class GlassVPNHook {
case "notify-prefs-change":
cachedNotify = CachedConnectionAlert()
return
case "recording-now":
currentlyRecording = value == "1"
return
default: break
}
}
@@ -57,18 +63,19 @@ class GlassVPNHook {
/// - Returns: `true` if the request shoud be blocked.
func processDNSRequest(_ domain: String) -> Bool {
let i = filterIndex(for: domain)
// TODO: disable ignore & block during recordings
let (block, ignore, cA, cB) = (i<0) ? (false, false, false, false) : filterOptions[i]
if ignore {
if ignore, !currentlyRecording {
return block
}
let blockActive = block && !currentlyRecording
queue.async {
do { try AppDB?.logWrite(domain, blocked: block) }
do { try AppDB?.logWrite(domain, blocked: blockActive) }
catch { NSLog("[VPN.WARN] Couldn't write: \(error)") }
}
// TODO: disable notifications during recording?
cachedNotify.postOrIgnore(domain, blck: block, custA: cA, custB: cB)
// TODO: wait for notify response to block or allow connection
return block
return blockActive
}
/// Build binary tree for reverse DNS lookup

View File

@@ -64,8 +64,11 @@ class VCRecordings: UIViewController, UINavigationControllerDelegate {
return
}
currentRecording = RecordingsDB.startNew()
QLog.Debug("start recording #\(currentRecording!.id)")
startTimer(animate: true)
notifyVPN(setRecording: true)
} else {
notifyVPN(setRecording: false)
stopTimer(animate: true)
RecordingsDB.stop(&currentRecording!)
let editVC = (children.first as! TVCPreviousRecords)
@@ -74,6 +77,11 @@ class VCRecordings: UIViewController, UINavigationControllerDelegate {
}
}
private func notifyVPN(setRecording state: Bool) {
PrefsShared.CurrentlyRecording = state
GlassVPN.send(.isRecording(state))
}
private func startTimer(animate: Bool) {
guard let r = currentRecording, r.stop == nil else {
return