From 6307ffc418a96a12a29774356896eada8f124585 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Wed, 17 Jun 2026 02:43:52 +0400 Subject: [PATCH] Activate SO_REUSEPORT for hole punching --- storage/storage.nim | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/storage/storage.nim b/storage/storage.nim index 9c5690b0..4088dcb8 100644 --- a/storage/storage.nim +++ b/storage/storage.nim @@ -88,6 +88,13 @@ proc start*(s: StorageServer) {.async.} = await s.storageNode.switch.start() + # Activate SO_REUSEPORT for hole punching in tcptransport.nim. + # Without that, hole punching would use an ephemeral port assigned by the OS. + # NotReachable has nothing to do with AutoNAT Reachability + if s.holePunchHandler.isSome: + for t in s.storageNode.switch.transports: + t.networkReachability = NetworkReachability.NotReachable + # When listenPort is 0 the OS assigns a random port. For UDP, the port # doesn't change so there is no need to update it. if s.natMapper.isSome and s.config.listenPort == Port(0):