mirror of
https://github.com/safing/portmaster
synced 2025-09-02 02:29:12 +00:00
Improve unused port search to find ports more quickly
This commit is contained in:
parent
0a02b89e60
commit
768a8b7df7
1 changed files with 1 additions and 3 deletions
|
@ -9,9 +9,7 @@ import (
|
|||
// currently unused and is unlikely to be used within the next seconds.
|
||||
func GetUnusedLocalPort(protocol uint8) (port uint16, ok bool) {
|
||||
allConns := conns.clone()
|
||||
|
||||
tries := 1000
|
||||
hundredth := tries / 100
|
||||
|
||||
// Try up to 1000 times to find an unused port.
|
||||
nextPort:
|
||||
|
@ -25,7 +23,7 @@ nextPort:
|
|||
port := uint16(rN + 10000)
|
||||
|
||||
// Shrink range when we chew through the tries.
|
||||
portRangeStart := port - uint16(100-(i/hundredth))
|
||||
portRangeStart := port - 10
|
||||
|
||||
// Check if the generated port is unused.
|
||||
nextConnection:
|
||||
|
|
Loading…
Add table
Reference in a new issue