From 768a8b7df7bc2a412f028bbd32e62d04a56d2484 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 5 Dec 2021 14:06:45 +0100 Subject: [PATCH] Improve unused port search to find ports more quickly --- network/ports.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/network/ports.go b/network/ports.go index ebf290e6..a0982461 100644 --- a/network/ports.go +++ b/network/ports.go @@ -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: