feat(WIP): add pause and resume functionality for Portmaster/SPN

https://github.com/safing/portmaster/issues/2050
This commit is contained in:
Alexandr Stelnykovych
2025-10-24 18:15:27 +03:00
parent 287c498bf1
commit c063bda700
9 changed files with 404 additions and 10 deletions

View File

@@ -12,9 +12,7 @@ import (
var (
packetMetricsDestination string
metrics = &packetMetrics{
done: make(chan struct{}),
}
metrics = &packetMetrics{}
)
func init() {
@@ -40,6 +38,10 @@ func (pm *packetMetrics) record(tp *tracedPacket, verdict string) {
pm.l.Lock()
defer pm.l.Unlock()
if pm.done == nil {
return
}
pm.records = append(pm.records, &performanceRecord{
start: start,
duration: duration,
@@ -48,6 +50,18 @@ func (pm *packetMetrics) record(tp *tracedPacket, verdict string) {
}(tp.start.UnixNano(), time.Since(tp.start))
}
func (pm *packetMetrics) stop() {
pm.l.Lock()
defer pm.l.Unlock()
if pm.done == nil {
return
}
close(pm.done)
pm.done = nil
}
func (pm *packetMetrics) writeMetrics() {
if packetMetricsDestination == "" {
return
@@ -62,9 +76,14 @@ func (pm *packetMetrics) writeMetrics() {
_ = f.Close()
}()
pm.l.Lock()
pm.done = make(chan struct{})
done := pm.done
pm.l.Unlock()
for {
select {
case <-pm.done:
case <-done:
return
case <-time.After(time.Second * 5):
}