mirror of
https://github.com/safing/portmaster
synced 2025-09-02 10:39:22 +00:00
Merge branch 'feature/online-check-special-ip' into feature/sleep-mode-support
This commit is contained in:
commit
7667fc26e8
6 changed files with 34 additions and 9 deletions
|
@ -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.Read():
|
||||
// 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.Read():
|
||||
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()
|
||||
|
|
Loading…
Add table
Reference in a new issue