diff --git a/ntp_core.c b/ntp_core.c index 7911844..4e17d26 100644 --- a/ntp_core.c +++ b/ntp_core.c @@ -437,6 +437,77 @@ get_poll_adj(NCR_Instance inst, double error_in_estimate, double peer_distance) /* ================================================== */ +static double +get_transmit_delay(NCR_Instance inst) +{ + int poll_to_use; + double delay_time; + + /* If we're in burst mode, queue for immediate dispatch. + + If we're operating in client/server mode, queue the timeout for + the poll interval hence. The fact that a timeout has been queued + in the transmit handler is immaterial - that is only done so that + we at least send something, if no reply is heard. + + If we're in symmetric mode, we have to take account of the peer's + wishes, otherwise his sampling regime will fall to pieces. If + we're in client/server mode, we don't care what poll interval the + server responded with last time. */ + + switch (inst->opmode) { + case MD_OFFLINE: + assert(0); + break; + case MD_ONLINE: + /* Normal processing, depending on whether we're in + client/server or symmetric mode */ + + switch(inst->mode) { + case MODE_CLIENT: + /* Client/server association - aim at some randomised time + approx the poll interval away */ + poll_to_use = inst->local_poll; + + delay_time = (double) (1UL<local_poll; + if (poll_to_use > inst->remote_poll) + poll_to_use = inst->remote_poll; + if (poll_to_use < inst->minpoll) + poll_to_use = inst->minpoll; + + delay_time = (double) (1UL<remote_addr.ip_addr), inst->minpoll); } + + requeue_transmit = 1; } if (valid_header && valid_data) { @@ -1093,76 +1165,19 @@ receive_packet(NTP_Packet *message, struct timeval *now, double now_err, NCR_Ins /* Slowly increase the polling interval if we can't get good_data */ adjust_poll(inst, 0.1); } + + requeue_transmit = 1; } - /* And now, requeue the timer. + /* And now, requeue the timer. */ + if (requeue_transmit && inst->opmode != MD_OFFLINE) { + delay_time = get_transmit_delay(inst); - If we're in burst mode, queue for immediate dispatch. + if (kod_rate) { + /* Back off for a while */ + delay_time += (double) (4 * (1UL << inst->minpoll)); + } - If we're operating in client/server mode, queue the timeout for - the poll interval hence. The fact that a timeout has been queued - in the transmit handler is immaterial - that is only done so that - we at least send something, if no reply is heard. - - If we're in symmetric mode, we have to take account of the peer's - wishes, otherwise his sampling regime will fall to pieces. If - we're in client/server mode, we don't care what poll interval the - server responded with last time. */ - - switch (inst->opmode) { - case MD_OFFLINE: - break; - case MD_ONLINE: - /* Normal processing, depending on whether we're in - client/server or symmetric mode */ - - requeue_transmit = 1; - - switch(inst->mode) { - case MODE_CLIENT: - /* Client/server association - aim at some randomised time - approx the poll interval away */ - poll_to_use = inst->local_poll; - - delay_time = (double) (1UL<local_poll < inst->remote_poll) ? inst->local_poll : inst->remote_poll; - - /* Limit by min and max poll */ - if (poll_to_use < inst->minpoll) poll_to_use = inst->minpoll; - if (poll_to_use > inst->maxpoll) poll_to_use = inst->maxpoll; - - delay_time = (double) (1UL<minpoll)); - } - - if (requeue_transmit) { /* Get rid of old timeout and start a new one */ assert(inst->timer_running); SCH_RemoveTimeout(inst->timeout_id);