@@ -35,37 +35,44 @@ type Server struct {
3535 ringMutex sync.Mutex
3636 notEmpty * sync.Cond
3737
38- lastSeen map [string ]time.Time
39- lastSeenMu sync.Mutex
40- keepAliveCheckInterval time.Duration
41- keepAliveTimeout time.Duration
42- OnDisconnect func (ip string )
38+ // Disabled: state for the UDP keep-alive, which checked that every source
39+ // IP kept sending packets and reported disconnections - Javier Ribal del Río (2026-07-15)
40+ // lastSeen map[string]time.Time
41+ // lastSeenMu sync.Mutex
42+ // keepAliveCheckInterval time.Duration
43+ // keepAliveTimeout time.Duration
44+ // OnDisconnect func(ip string)
4345}
4446
45- const (
46- defaultKeepAliveCheckInterval = 5 * time .Millisecond
47- defaultKeepAliveTimeout = 100 * time .Millisecond
48- )
49-
50- func NewServer (address string , port uint16 , logger * zerolog.Logger , ringBufferSize int , packetChanSize int , keepAliveCheckInterval time.Duration , keepAliveTimeout time.Duration , onDisconnect func (ip string )) * Server {
51- if keepAliveCheckInterval <= 0 {
52- keepAliveCheckInterval = defaultKeepAliveCheckInterval
53- }
54- if keepAliveTimeout <= 0 {
55- keepAliveTimeout = defaultKeepAliveTimeout
56- }
47+ // Disabled: default intervals for the UDP keep-alive - Javier Ribal del Río (2026-07-15)
48+ // const (
49+ // defaultKeepAliveCheckInterval = 5 * time.Millisecond
50+ // defaultKeepAliveTimeout = 100 * time.Millisecond
51+ // )
52+
53+ func NewServer (address string , port uint16 , logger * zerolog.Logger , ringBufferSize int , packetChanSize int ) * Server {
54+ // Disabled: UDP keep-alive parameters and their defaulting; the previous
55+ // signature also took keepAliveCheckInterval, keepAliveTimeout and an
56+ // onDisconnect callback - Javier Ribal del Río (2026-07-15)
57+ // if keepAliveCheckInterval <= 0 {
58+ // keepAliveCheckInterval = defaultKeepAliveCheckInterval
59+ // }
60+ // if keepAliveTimeout <= 0 {
61+ // keepAliveTimeout = defaultKeepAliveTimeout
62+ // }
5763
5864 s := & Server {
59- address : address ,
60- port : port ,
61- logger : logger ,
62- packetsCh : make (chan Packet , packetChanSize ),
63- errorsCh : make (chan error , 100 ),
64- stopCh : make (chan struct {}),
65- lastSeen : make (map [string ]time.Time ),
66- keepAliveCheckInterval : keepAliveCheckInterval ,
67- keepAliveTimeout : keepAliveTimeout ,
68- OnDisconnect : onDisconnect ,
65+ address : address ,
66+ port : port ,
67+ logger : logger ,
68+ packetsCh : make (chan Packet , packetChanSize ),
69+ errorsCh : make (chan error , 100 ),
70+ stopCh : make (chan struct {}),
71+ // Disabled: UDP keep-alive state initialization - Javier Ribal del Río (2026-07-15)
72+ // lastSeen: make(map[string]time.Time),
73+ // keepAliveCheckInterval: keepAliveCheckInterval,
74+ // keepAliveTimeout: keepAliveTimeout,
75+ // OnDisconnect: onDisconnect,
6976 }
7077
7178 s .ring = make ([]Packet , ringBufferSize )
@@ -93,9 +100,10 @@ func (s *Server) Start() error {
93100 Uint16 ("port" , s .port ).
94101 Msg ("UDP server started" )
95102
96- go s .readLoop () // Read incoming UDP packets
97- go s .dispatchLoop () // Dispatch packets from ring buffer to channel
98- go s .keepAliveLoop () // Monitor keep-alive timeouts
103+ go s .readLoop () // Read incoming UDP packets
104+ go s .dispatchLoop () // Dispatch packets from ring buffer to channel
105+ // Disabled: goroutine that monitored UDP keep-alive timeouts - Javier Ribal del Río (2026-07-15)
106+ // go s.keepAliveLoop()
99107 return nil
100108}
101109
@@ -144,53 +152,56 @@ func (s *Server) readLoop() {
144152 Int ("size" , len (payload )).
145153 Msg ("received UDP packet" )
146154
147- // Update keep-alive tracking for this source IP
148- s .lastSeenMu .Lock ()
149- s .lastSeen [addr .IP .String ()] = packet .Timestamp
150- s .lastSeenMu .Unlock ()
155+ // Disabled: recorded when each source IP was last seen, feeding
156+ // the UDP keep-alive check - Javier Ribal del Río (2026-07-15)
157+ // s.lastSeenMu.Lock()
158+ // s.lastSeen[addr.IP.String()] = packet.Timestamp
159+ // s.lastSeenMu.Unlock()
151160
152161 // Push packet to ring buffer
153162 s .push (packet )
154163 }
155164 }
156165}
157166
158- // keepAliveLoop checks for clients that have not sent any packets within the keepAliveTimeout duration.
159- func (s * Server ) keepAliveLoop () {
160- ticker := time .NewTicker (s .keepAliveCheckInterval )
161- defer ticker .Stop ()
162-
163- for {
164- select {
165- case <- s .stopCh :
166- return
167- case now := <- ticker .C :
168- var timedOut []string
169-
170- s .lastSeenMu .Lock ()
171- for ip , last := range s .lastSeen {
172- if now .Sub (last ) > s .keepAliveTimeout {
173- timedOut = append (timedOut , ip )
174- delete (s .lastSeen , ip )
175- }
176- }
177- s .lastSeenMu .Unlock ()
178-
179- for _ , ip := range timedOut {
180- s .logger .Error ().
181- Str ("ip" , ip ).
182- Dur ("timeout" , s .keepAliveTimeout ).
183- Msg ("keep-alive timeout: no UDP packets received" )
184- if s .OnDisconnect != nil {
185- // Run the callback on its own goroutine so a slow
186- // handler (e.g. blocking TCP writes) cannot stall
187- // timeout detection for the remaining IPs
188- go s .OnDisconnect (ip )
189- }
190- }
191- }
192- }
193- }
167+ // Disabled: UDP keep-alive loop — checked every keepAliveCheckInterval whether
168+ // any source IP had gone more than keepAliveTimeout without sending a packet,
169+ // and fired OnDisconnect for it - Javier Ribal del Río (2026-07-15)
170+ // func (s *Server) keepAliveLoop() {
171+ // ticker := time.NewTicker(s.keepAliveCheckInterval)
172+ // defer ticker.Stop()
173+ //
174+ // for {
175+ // select {
176+ // case <-s.stopCh:
177+ // return
178+ // case now := <-ticker.C:
179+ // var timedOut []string
180+ //
181+ // s.lastSeenMu.Lock()
182+ // for ip, last := range s.lastSeen {
183+ // if now.Sub(last) > s.keepAliveTimeout {
184+ // timedOut = append(timedOut, ip)
185+ // delete(s.lastSeen, ip)
186+ // }
187+ // }
188+ // s.lastSeenMu.Unlock()
189+ //
190+ // for _, ip := range timedOut {
191+ // s.logger.Error().
192+ // Str("ip", ip).
193+ // Dur("timeout", s.keepAliveTimeout).
194+ // Msg("keep-alive timeout: no UDP packets received")
195+ // if s.OnDisconnect != nil {
196+ // // Run the callback on its own goroutine so a slow
197+ // // handler (e.g. blocking TCP writes) cannot stall
198+ // // timeout detection for the remaining IPs
199+ // go s.OnDisconnect(ip)
200+ // }
201+ // }
202+ // }
203+ // }
204+ // }
194205
195206func (s * Server ) GetPackets () <- chan Packet {
196207 return s .packetsCh
0 commit comments