summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2025-04-22 08:37:34 +0200
committerSanto Cariotti <santo@dcariotti.me>2025-04-22 08:37:34 +0200
commit6e72dd92a358fcf4ba72f667a9b96d48123fc09f (patch)
treebedc752ef4f467494c4d2ad478001b8cf5f119b5
parentbea3c27a1069b6934cfa84794563918f60578cd2 (diff)
Return a port only in the ephemeral ports range
-rw-r--r--pkg/p2p/ip.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/pkg/p2p/ip.go b/pkg/p2p/ip.go
index c82b861..d42eabd 100644
--- a/pkg/p2p/ip.go
+++ b/pkg/p2p/ip.go
@@ -22,10 +22,10 @@ func GetOutboundIP() net.IP {
return localAddr.IP
}
-// Returns a random available port on the node
+// Returns a random available port on the node in the range of ephemeral ports
func GetRandomAvailablePort() (int, error) {
for i := 0; i < 100; i += 1 {
- port := rand.Intn(65535-1024) + 1024
+ port := rand.Intn(65535-49152) + 1024
addr := fmt.Sprintf(":%d", port)
ln, err := net.Listen("tcp", addr)
if err == nil {