Improve lookup tries for network state
This commit is contained in:
@@ -2,7 +2,6 @@ package state
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/safing/portmaster/network/netutils"
|
||||
"github.com/safing/portmaster/network/packet"
|
||||
@@ -30,9 +29,8 @@ var (
|
||||
)
|
||||
|
||||
var (
|
||||
baseWaitTime = 3 * time.Millisecond
|
||||
lookupRetries = 7 * 2 // Every retry takes two full passes.
|
||||
fastLookupRetries = 2 * 2
|
||||
lookupTries = 15 // With a max wait of 5ms, this amounts to up to 75ms.
|
||||
fastLookupTries = 2
|
||||
)
|
||||
|
||||
// Lookup looks for the given connection in the system state tables and returns the PID of the associated process and whether the connection is inbound.
|
||||
@@ -81,7 +79,7 @@ func (table *tcpTable) lookup(pktInfo *packet.Info, fast bool) (
|
||||
)
|
||||
|
||||
// Search for the socket until found.
|
||||
for i := 1; i <= lookupRetries; i++ {
|
||||
for i := 1; i <= lookupTries; i++ {
|
||||
// Get or update tables.
|
||||
if i == 1 {
|
||||
connections, listeners, updateIter = table.getCurrentTables()
|
||||
@@ -120,7 +118,7 @@ func (table *tcpTable) lookup(pktInfo *packet.Info, fast bool) (
|
||||
}
|
||||
|
||||
// Search less if we want to be fast.
|
||||
if fast && i < fastLookupRetries {
|
||||
if fast && i >= fastLookupTries {
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -184,7 +182,7 @@ func (table *udpTable) lookup(pktInfo *packet.Info, fast bool) (
|
||||
)
|
||||
|
||||
// Search for the socket until found.
|
||||
for i := 1; i <= lookupRetries; i++ {
|
||||
for i := 1; i <= lookupTries; i++ {
|
||||
// Get or update tables.
|
||||
if i == 1 {
|
||||
binds, updateIter = table.getCurrentTables()
|
||||
@@ -245,7 +243,7 @@ func (table *udpTable) lookup(pktInfo *packet.Info, fast bool) (
|
||||
}
|
||||
|
||||
// Search less if we want to be fast.
|
||||
if fast && i < fastLookupRetries {
|
||||
if fast && i >= fastLookupTries {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,10 @@ var (
|
||||
getUDP6Table = proc.GetUDP6Table
|
||||
)
|
||||
|
||||
var baseWaitTime = 3 * time.Millisecond
|
||||
|
||||
func checkPID(socketInfo socket.Info, connInbound bool) (pid int, inbound bool, err error) {
|
||||
for i := 0; i <= lookupRetries; i++ {
|
||||
for i := 1; i <= lookupTries; i++ {
|
||||
// look for PID
|
||||
pid = proc.GetPID(socketInfo)
|
||||
if pid != socket.UndefinedProcessID {
|
||||
@@ -24,7 +26,7 @@ func checkPID(socketInfo socket.Info, connInbound bool) (pid int, inbound bool,
|
||||
}
|
||||
|
||||
// every time, except for the last iteration
|
||||
if i < lookupRetries {
|
||||
if i < lookupTries {
|
||||
// we found no PID, we could have been too fast, give the kernel some time to think
|
||||
// back off timer: with 3ms baseWaitTime: 3, 6, 9, 12, 15, 18, 21ms - 84ms in total
|
||||
time.Sleep(time.Duration(i+1) * baseWaitTime)
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
package state
|
||||
Reference in New Issue
Block a user