- for (jitter = 0, i = 0; i < ELEMENTSOF(sntp->samples); i++)
- jitter += square(sntp->samples[i].offset - sntp->samples[idx_min].offset);
- sntp->samples_jitter = sqrt(jitter / (ELEMENTSOF(sntp->samples) - 1));
+ j = 0;
+ for (i = 0; i < ELEMENTSOF(sntp->samples); i++)
+ j += square(sntp->samples[i].offset - sntp->samples[idx_min].offset);
+ sntp->samples_jitter = sqrt(j / (ELEMENTSOF(sntp->samples) - 1));
+
+ /* ignore samples when resyncing */
+ if (sntp->poll_resync)
+ return false;
+
+ /* always accept offset if we are farther off than the round-trip delay */
+ if (fabs(offset) > delay)
+ return false;
+
+ /* we need a few samples before looking at them */
+ if (sntp->packet_count < 4)
+ return false;