/* High-level description of the algorithm:
*
* We start running with very small poll_exp, BURSTPOLL,
- * in order to quickly accumulate INITIAL_SAMLPES datapoints
+ * in order to quickly accumulate INITIAL_SAMPLES datapoints
* for each peer. Then, time is stepped if the offset is larger
* than STEP_THRESHOLD, otherwise it isn't; anyway, we enlarge
* poll_exp to MINPOLL and enter frequency measurement step:
#define RETRY_INTERVAL 5 /* on error, retry in N secs */
#define RESPONSE_INTERVAL 15 /* wait for reply up to N secs */
-#define INITIAL_SAMLPES 4 /* how many samples do we want for init */
+#define INITIAL_SAMPLES 4 /* how many samples do we want for init */
/* Clock discipline parameters and constants */
//UNUSED: #define PANIC_THRESHOLD 1000 /* panic threshold (sec) */
#define FREQ_TOLERANCE 0.000015 /* frequency tolerance (15 PPM) */
-#define BURSTPOLL 0 /* initial poll */
+#define BURSTPOLL 0 /* initial poll */
#define MINPOLL 5 /* minimum poll interval. std ntpd uses 6 (6: 64 sec) */
#define BIGPOLL 10 /* drop to lower poll at any trouble (10: 17 min) */
#define MAXPOLL 12 /* maximum poll interval (12: 1.1h, 17: 36.4h). std ntpd uses 17 */
VERB3 bb_error_msg("peer %s unfit for selection: unreachable", p->p_dotted);
return 0;
}
-#if 0 /* we filter out such packets earlier */
+#if 0 /* we filter out such packets earlier */
if ((p->lastpkt_status & LI_ALARM) == LI_ALARM
|| p->lastpkt_stratum >= MAXSTRAT
) {
/* this time was obtained between poll() and recv() */
msg.m_rectime = d_to_lfp(G.cur_time);
msg.m_xmttime = d_to_lfp(gettime1900d()); /* this instant */
+ if (G.peer_cnt == 0) {
+ /* we have no peers: "stratum 1 server" mode. reftime = our own time */
+ G.reftime = G.cur_time;
+ }
msg.m_reftime = d_to_lfp(G.reftime);
msg.m_orgtime = query_xmttime;
msg.m_rootdelay = d_to_sfp(G.rootdelay);
bb_show_usage();
// if (opts & OPT_x) /* disable stepping, only slew is allowed */
// G.time_was_stepped = 1;
- while (peers)
- add_peers(llist_pop(&peers));
+ if (peers) {
+ while (peers)
+ add_peers(llist_pop(&peers));
+ } else {
+ /* -l but no peers: "stratum 1 server" mode */
+ G.stratum = 1;
+ }
if (!(opts & OPT_n)) {
bb_daemonize_or_rexec(DAEMON_DEVNULL_STDIO, argv);
logmode = LOGMODE_NONE;
idx2peer = xzalloc(sizeof(idx2peer[0]) * cnt);
pfd = xzalloc(sizeof(pfd[0]) * cnt);
- /* Countdown: we never sync before we sent INITIAL_SAMLPES+1
+ /* Countdown: we never sync before we sent INITIAL_SAMPLES+1
* packets to each peer.
* NB: if some peer is not responding, we may end up sending
* fewer packets to it and more to other peers.
- * NB2: sync usually happens using INITIAL_SAMLPES packets,
+ * NB2: sync usually happens using INITIAL_SAMPLES packets,
* since last reply does not come back instantaneously.
*/
- cnt = G.peer_cnt * (INITIAL_SAMLPES + 1);
+ cnt = G.peer_cnt * (INITIAL_SAMPLES + 1);
while (!bb_got_signal) {
llist_t *item;
}
static void
-set_freq(double freq) /* frequency update */
+set_freq(double freq) /* frequency update */
{
char tbuf[80];