<commit_before>package net.i2p.time;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import net.i2p.util.I2PThread;
import net.i2p.util.Log;

/**
 * Periodically query a series of NTP servers and post the offset 
 * to a given URL.  It tries the NTP servers in order, contacting them
 * using UDP port 123, and sends the current date to the URL specified
 * (specifically, URL+"&now=" + yyyyMMdd_HH:mm:ss.SSS in the UK locale).
 * It does this every 5 minutes, forever.
 *
 * Usage: <pre>
 *  Timestamper URL ntpServer1[ ntpServer2]*
 * </pre>
 */
public class Timestamper implements Runnable {
    private static Log _log = new Log(Timestamper.class);
    private String _targetURL;
    private String _serverList[];
    
    private int DELAY_MS = 5*60*1000;
    
    public Timestamper(String url, String serverNames[]) {
        if (_log.shouldLog(Log.INFO))
            _log.info("Creating new timestamper pointing at " + url);
        _targetURL = url;
        _serverList = serverNames;
    }
    
    public void startTimestamper() {
        if (_log.shouldLog(Log.INFO))
            _log.info("Starting timestamper pointing at " + _targetURL);
        I2PThread t = new I2PThread(this, "Timestamper");
        t.setPriority(I2PThread.MIN_PRIORITY);
        t.start();
    }
    
    public void run() {
        if (_log.shouldLog(Log.INFO))
            _log.info("Starting up timestamper");
        try {
            while (true) {
                if (_log.shouldLog(Log.DEBUG))
                    _log.debug("Querying servers " + _serverList);
                long now = NtpClient.currentTime(_serverList);
                if (now < 0) {
                    _log.error("Unable to contact any of the NTP servers - network disconnect?");
                } else {
                    if (_log.shouldLog(Log.DEBUG))
                        _log.debug("Stamp time");
                    stampTime(now);
                }
                try { Thread.sleep(DELAY_MS); } catch (InterruptedException ie) {}
            }
        } catch (Throwable t) {
            _log.log(Log.CRIT, "Timestamper died!", t);<commit_msg>correctly handle no reachable NTP servers<commit_after>package net.i2p.time;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import net.i2p.util.I2PThread;
import net.i2p.util.Log;

/**
 * Periodically query a series of NTP servers and post the offset 
 * to a given URL.  It tries the NTP servers in order, contacting them
 * using UDP port 123, and sends the current date to the URL specified
 * (specifically, URL+"&now=" + yyyyMMdd_HH:mm:ss.SSS in the UK locale).
 * It does this every 5 minutes, forever.
 *
 * Usage: <pre>
 *  Timestamper URL ntpServer1[ ntpServer2]*
 * </pre>
 */
public class Timestamper implements Runnable {
    private static Log _log = new Log(Timestamper.class);
    private String _targetURL;
    private String _serverList[];
    
    private int DELAY_MS = 5*60*1000;
    
    public Timestamper(String url, String serverNames[]) {
        if (_log.shouldLog(Log.INFO))
            _log.info("Creating new timestamper pointing at " + url);
        _targetURL = url;
        _serverList = serverNames;
    }
    
    public void startTimestamper() {
        if (_log.shouldLog(Log.INFO))
            _log.info("Starting timestamper pointing at " + _targetURL);
        I2PThread t = new I2PThread(this, "Timestamper");
        t.setPriority(I2PThread.MIN_PRIORITY);
        t.start();
    }
    
    public void run() {
        if (_log.shouldLog(Log.INFO))
            _log.info("Starting up timestamper");
        try {
            while (true) {
                if (_log.shouldLog(Log.DEBUG))
                    _log.debug("Querying servers " + _serverList);
                try {
                    long now = NtpClient.currentTime(_serverList);
                    if (_log.shouldLog(Log.DEBUG))
                        _log.debug("Stamp time");
                    stampTime(now);
                } catch (IllegalArgumentException iae) {
                    _log.log(Log.CRIT, "Unable to reach any of the NTP servers - network disconnected?");
                }
                try { Thread.sleep(DELAY_MS); } catch (InterruptedException ie) {}
            }
        } catch (Throwable t) {
            _log.log(Log.CRIT, "Timestamper died!", t);
{'fraction_non_alphanumeric': 0.10375082254880456, 'fraction_numerical': 0.008993200263215618, 'mean_word_length': 2.2317505315379162, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '927432', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1364, 'n_words': 367}