mirror of
https://github.com/safing/portmaster
synced 2025-09-02 02:29:12 +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 {
|
for {
|
||||||
trigger := false
|
trigger := false
|
||||||
|
|
||||||
timeout := 15 * time.Second
|
var ticker *time.Ticker
|
||||||
if !Online() {
|
if Online() {
|
||||||
timeout = time.Second
|
ticker = monitorNetworkChangeOnlineTicker
|
||||||
|
} else {
|
||||||
|
ticker = monitorNetworkChangeOfflineTicker
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait for trigger
|
// wait for trigger
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
@ -54,7 +57,7 @@ serviceLoop:
|
||||||
// triggers the networkChangeCheck this way. If we would set
|
// triggers the networkChangeCheck this way. If we would set
|
||||||
// trigger == true we would trigger the online check again
|
// trigger == true we would trigger the online check again
|
||||||
// resulting in a loop of pointless checks.
|
// resulting in a loop of pointless checks.
|
||||||
case <-time.After(timeout):
|
case <-ticker.C:
|
||||||
trigger = true
|
trigger = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,20 @@ package netenv
|
||||||
import (
|
import (
|
||||||
"github.com/safing/portmaster-android/go/app_interface"
|
"github.com/safing/portmaster-android/go/app_interface"
|
||||||
"net"
|
"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) {
|
func osGetInterfaceAddrs() ([]net.Addr, error) {
|
||||||
list, err := app_interface.GetNetworkAddresses()
|
list, err := app_interface.GetNetworkAddresses()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -4,6 +4,12 @@ package netenv
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
monitorNetworkChangeOnlineTicker = time.NewTicker(15 * time.Second)
|
||||||
|
monitorNetworkChangeOfflineTicker = time.NewTicker(time.Second)
|
||||||
)
|
)
|
||||||
|
|
||||||
func osGetInterfaceAddrs() ([]net.Addr, error) {
|
func osGetInterfaceAddrs() ([]net.Addr, error) {
|
||||||
|
|
|
@ -19,14 +19,14 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func connectionCleaner(ctx context.Context) error {
|
func connectionCleaner(ctx context.Context) error {
|
||||||
ticker := time.NewTicker(cleanerTickDuration)
|
ticker := module.NewSleepyTicker(cleanerTickDuration, 0)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
ticker.Stop()
|
ticker.Stop()
|
||||||
return nil
|
return nil
|
||||||
case <-ticker.C:
|
case <-ticker.Read():
|
||||||
// clean connections and processes
|
// clean connections and processes
|
||||||
activePIDs := cleanConnections()
|
activePIDs := cleanConnections()
|
||||||
process.CleanProcessStorage(activePIDs)
|
process.CleanProcessStorage(activePIDs)
|
||||||
|
|
|
@ -84,14 +84,14 @@ func SaveOpenDNSRequest(q *resolver.Query, rrCache *resolver.RRCache, conn *Conn
|
||||||
}
|
}
|
||||||
|
|
||||||
func openDNSRequestWriter(ctx context.Context) error {
|
func openDNSRequestWriter(ctx context.Context) error {
|
||||||
ticker := time.NewTicker(writeOpenDNSRequestsTickDuration)
|
ticker := module.NewSleepyTicker(writeOpenDNSRequestsTickDuration, 0)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return nil
|
return nil
|
||||||
case <-ticker.C:
|
case <-ticker.Read():
|
||||||
writeOpenDNSRequestsToDB()
|
writeOpenDNSRequestsToDB()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,9 +53,13 @@ func (p *Process) Save() {
|
||||||
|
|
||||||
p.UpdateMeta()
|
p.UpdateMeta()
|
||||||
|
|
||||||
|
if p.processKey == "" {
|
||||||
|
p.processKey = getProcessKey(int32(p.Pid), p.CreatedAt)
|
||||||
|
}
|
||||||
|
|
||||||
if !p.KeyIsSet() {
|
if !p.KeyIsSet() {
|
||||||
// set key
|
// 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
|
// save
|
||||||
processesLock.Lock()
|
processesLock.Lock()
|
||||||
|
|
Loading…
Add table
Reference in a new issue