Merge pull request #1182 from safing/feature/sleep-mode-support
Reduce running of background tasks on sleep mode
This commit is contained in:
2
go.mod
2
go.mod
@@ -17,7 +17,7 @@ require (
|
||||
github.com/miekg/dns v1.1.53
|
||||
github.com/oschwald/maxminddb-golang v1.10.0
|
||||
github.com/safing/jess v0.3.1
|
||||
github.com/safing/portbase v0.16.5
|
||||
github.com/safing/portbase v0.16.6
|
||||
github.com/safing/portmaster-android/go v0.0.0-20230329101752-28296331340b
|
||||
github.com/safing/spn v0.6.7
|
||||
github.com/shirou/gopsutil v3.21.11+incompatible
|
||||
|
||||
8
go.sum
8
go.sum
@@ -201,8 +201,8 @@ github.com/safing/jess v0.3.1 h1:cMZVhi2whW/YdD98MPLeLIWJndQ7o2QVt2HefQ/ByFA=
|
||||
github.com/safing/jess v0.3.1/go.mod h1:aj73Eot1zm2ETkJuw9hJlIO8bRom52uBbsCHemvlZmA=
|
||||
github.com/safing/portbase v0.15.2/go.mod h1:5bHi99fz7Hh/wOsZUOI631WF9ePSHk57c4fdlOMS91Y=
|
||||
github.com/safing/portbase v0.16.2/go.mod h1:mzNCWqPbO7vIYbbK5PElGbudwd2vx4YPNawymL8Aro8=
|
||||
github.com/safing/portbase v0.16.5 h1:vn6jGQW+ACnPVV57XtlNX+A/LESFh8/YmKn9rwAdy90=
|
||||
github.com/safing/portbase v0.16.5/go.mod h1:CJSY+0pgbgh00UcM9myS/l+Bcgqgc6afLJX2BqzD+Ek=
|
||||
github.com/safing/portbase v0.16.6 h1:6MbK8VGusSKswmbZ031Dher1yijYGxUQ36nNuEIP9P8=
|
||||
github.com/safing/portbase v0.16.6/go.mod h1:CJSY+0pgbgh00UcM9myS/l+Bcgqgc6afLJX2BqzD+Ek=
|
||||
github.com/safing/portmaster-android/go v0.0.0-20230329101752-28296331340b h1:b+GCsl+dTnR22JY3N2aRDVnac2ocjFqqUhn8rPxywGM=
|
||||
github.com/safing/portmaster-android/go v0.0.0-20230329101752-28296331340b/go.mod h1:E3MFiTwsHxsPfzI+CGhpE8BOGQYS/V7tkXttMTFeyuc=
|
||||
github.com/safing/spn v0.6.7 h1:WNxzf6eEI/FyRtEjUwXK0GTwHD9VPxrKhlupLqQlz+E=
|
||||
@@ -423,10 +423,6 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gvisor.dev/gvisor v0.0.0-20220817001344-846276b3dbc5 h1:cv/zaNV0nr1mJzaeo4S5mHIm5va1W0/9J3/5prlsuRM=
|
||||
gvisor.dev/gvisor v0.0.0-20220817001344-846276b3dbc5/go.mod h1:TIvkJD0sxe8pIob3p6T8IzxXunlp6yfgktvTNp+DGNM=
|
||||
gvisor.dev/gvisor v0.0.0-20221203005347-703fd9b7fbc0 h1:Wobr37noukisGxpKo5jAsLREcpj61RxrWYzD8uwveOY=
|
||||
gvisor.dev/gvisor v0.0.0-20221203005347-703fd9b7fbc0/go.mod h1:Dn5idtptoW1dIos9U6A2rpebLs/MtTwFacjKb8jLdQA=
|
||||
gvisor.dev/gvisor v0.0.0-20230323070900-fa7aa5b4e2e5 h1:chb75CHSg+jG0/6sLIzG4qkYg/LQBw3m3SOx487J0rg=
|
||||
gvisor.dev/gvisor v0.0.0-20230323070900-fa7aa5b4e2e5/go.mod h1:pzr6sy8gDLfVmDAg8OYrlKvGEHw5C3PGTiBXBTCx76Q=
|
||||
honnef.co/go/tools v0.2.1/go.mod h1:lPVVZ2BS5TfnjLyizF7o7hv7j9/L+8cZY2hLyjP9cGY=
|
||||
honnef.co/go/tools v0.2.2/go.mod h1:lPVVZ2BS5TfnjLyizF7o7hv7j9/L+8cZY2hLyjP9cGY=
|
||||
modernc.org/libc v1.22.3 h1:D/g6O5ftAfavceqlLOFwaZuA5KYafKwmr30A6iSqoyY=
|
||||
|
||||
@@ -41,10 +41,13 @@ serviceLoop:
|
||||
for {
|
||||
trigger := false
|
||||
|
||||
timeout := 15 * time.Second
|
||||
if !Online() {
|
||||
timeout = time.Second
|
||||
var ticker *time.Ticker
|
||||
if Online() {
|
||||
ticker = monitorNetworkChangeOnlineTicker
|
||||
} else {
|
||||
ticker = monitorNetworkChangeOfflineTicker
|
||||
}
|
||||
|
||||
// wait for trigger
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
@@ -54,7 +57,7 @@ serviceLoop:
|
||||
// triggers the networkChangeCheck this way. If we would set
|
||||
// trigger == true we would trigger the online check again
|
||||
// resulting in a loop of pointless checks.
|
||||
case <-time.After(timeout):
|
||||
case <-ticker.C:
|
||||
trigger = true
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,20 @@ package netenv
|
||||
import (
|
||||
"github.com/safing/portmaster-android/go/app_interface"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
monitorNetworkChangeOnlineTicker = time.NewTicker(time.Second)
|
||||
monitorNetworkChangeOfflineTicker = time.NewTicker(time.Second)
|
||||
)
|
||||
|
||||
func init() {
|
||||
// Network change event is monitored by the android system.
|
||||
monitorNetworkChangeOnlineTicker.Stop()
|
||||
monitorNetworkChangeOfflineTicker.Stop()
|
||||
}
|
||||
|
||||
func osGetInterfaceAddrs() ([]net.Addr, error) {
|
||||
list, err := app_interface.GetNetworkAddresses()
|
||||
if err != nil {
|
||||
|
||||
@@ -4,6 +4,12 @@ package netenv
|
||||
|
||||
import (
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
monitorNetworkChangeOnlineTicker = time.NewTicker(15 * time.Second)
|
||||
monitorNetworkChangeOfflineTicker = time.NewTicker(time.Second)
|
||||
)
|
||||
|
||||
func osGetInterfaceAddrs() ([]net.Addr, error) {
|
||||
|
||||
@@ -19,14 +19,14 @@ const (
|
||||
)
|
||||
|
||||
func connectionCleaner(ctx context.Context) error {
|
||||
ticker := time.NewTicker(cleanerTickDuration)
|
||||
ticker := module.NewSleepyTicker(cleanerTickDuration, 0)
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
ticker.Stop()
|
||||
return nil
|
||||
case <-ticker.C:
|
||||
case <-ticker.Wait():
|
||||
// clean connections and processes
|
||||
activePIDs := cleanConnections()
|
||||
process.CleanProcessStorage(activePIDs)
|
||||
|
||||
@@ -84,14 +84,14 @@ func SaveOpenDNSRequest(q *resolver.Query, rrCache *resolver.RRCache, conn *Conn
|
||||
}
|
||||
|
||||
func openDNSRequestWriter(ctx context.Context) error {
|
||||
ticker := time.NewTicker(writeOpenDNSRequestsTickDuration)
|
||||
ticker := module.NewSleepyTicker(writeOpenDNSRequestsTickDuration, 0)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil
|
||||
case <-ticker.C:
|
||||
case <-ticker.Wait():
|
||||
writeOpenDNSRequestsToDB()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,9 +53,13 @@ func (p *Process) Save() {
|
||||
|
||||
p.UpdateMeta()
|
||||
|
||||
if p.processKey == "" {
|
||||
p.processKey = getProcessKey(int32(p.Pid), p.CreatedAt)
|
||||
}
|
||||
|
||||
if !p.KeyIsSet() {
|
||||
// set key
|
||||
p.SetKey(fmt.Sprintf("%s/%s", processDatabaseNamespace, getProcessKey(int32(p.Pid), p.CreatedAt)))
|
||||
p.SetKey(fmt.Sprintf("%s/%s", processDatabaseNamespace, p.processKey))
|
||||
|
||||
// save
|
||||
processesLock.Lock()
|
||||
|
||||
Reference in New Issue
Block a user