@@ -228,15 +228,19 @@ proc sendRegister*(
228228
229229proc ticketRetryDelay * (ticket: Ticket , now: Moment ): Duration {.raises : [].} =
230230 # # Time to sleep before presenting ``ticket`` so the registrar sees it inside
231- # # the eligibility window ``[tMod + tWaitFor, tMod + tWaitFor + Δ]``.
232- # #
233- # # Uses absolute ticket timestamps (not a relative wait from response receipt,
234- # # and not capped by advert expiry) so retries under load are not rejected as
235- # # "ticket outside valid time window".
236- let eligibility = ticket.tMod.get () + ticket.tWaitFor.get ()
231+ # # the eligibility window ``[tMod + tWaitFor, tMod + tWaitFor + delta]``.
232+ let tMod = ticket.tMod.valueOr:
233+ return ZeroDuration
234+
235+ let tWaitFor = ticket.tWaitFor.valueOr:
236+ return ZeroDuration
237+
238+ let eligibility = tMod + tWaitFor
239+
237240 if now >= eligibility:
238241 return ZeroDuration
239- eligibility - now
242+
243+ return eligibility - now
240244
241245proc advertiseToRegistrar * (
242246 disco: ServiceDiscovery ,
@@ -295,9 +299,8 @@ proc advertiseToRegistrar*(
295299
296300 let waitSecs = ticketRetryDelay (newTicket, Moment .now ())
297301
298- debug " waiting for registrar" , serviceId, registrar, wait = $ waitSecs
299-
300302 if waitSecs > ZeroDuration :
303+ debug " waiting for registrar" , serviceId, registrar, wait = $ waitSecs
301304 await sleepAsync (waitSecs)
302305 of kademlia_protobuf.RegistrationStatus .Rejected :
303306 debug " registrar rejection, aborting" , serviceId, registrar
0 commit comments