Changeset 352396b


Ignore:
Timestamp:
Aug 13, 2004 9:15:22 PM (17 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
3b65107
Parents:
3c9b027
git-author:
jrandom <jrandom> (08/13/04 21:15:22)
git-committer:
zzz <zzz@…> (08/13/04 21:15:22)
Message:

Date: Fri, 13 Aug 2004 15:58:30 +1200 (NZST)
Message-ID: <1776.202.37.75.101.1092369510.squirrel@202.37.75.101>
From: adam@…
To: jrandom@…

[…]

I hereby authorize my NtpClient?.java and NtpMessage?.java code to be
redistributed under the BSD license for the purpose of integration with
the I2P project, providing that I am credited as the original author of
the code.

[…]

w00t! adam++
code migrated into core/java/src/net/i2p/time, integrated with Clock,
dropping that whole ugly pass-the-time-through-URL, and hence dropped
support for :7655/setTime.
New router.config properties to control the timestamper:

time.sntpServerList=pool.ntp.org,pool.ntp.org,pool.ntp.org
time.queryFrequencyMs=300000
time.disabled=false

So, to disable, add time.disabled=true to your router.config. It is
enabled by default.
Default router.config and startup scripts updated accordingly (since
timestamper.jar is now gone)

Files:
1 added
2 deleted
12 edited
2 moved

Legend:

Unmodified
Added
Removed
  • apps/routerconsole/java/src/net/i2p/router/web/ConfigNetHandler.java

    r3c9b027 r352396b  
    1818
    1919import net.i2p.util.Log;
     20import net.i2p.time.Timestamper;
    2021
    2122import net.i2p.router.RouterContext;
     
    222223       
    223224        if (_timeSyncEnabled) {
    224             System.setProperty("timestamper.enabled", "true");
     225            _context.router().setConfigSetting(Timestamper.PROP_DISABLED, "false");
    225226        } else {
    226             System.setProperty("timestamper.enabled", "false");
     227            _context.router().setConfigSetting(Timestamper.PROP_DISABLED, "false");
    227228        }
    228229       
  • apps/routerconsole/java/src/net/i2p/router/web/ConfigNetHelper.java

    r3c9b027 r352396b  
    77import java.util.TreeMap;
    88
     9import net.i2p.time.Timestamper;
    910import net.i2p.util.Log;
    1011
     
    5152   
    5253    public String getEnableTimeSyncChecked() {
    53         String enabled = System.getProperty("timestamper.enabled");
    54         if ( (enabled == null) || (!"true".equals(enabled)) )
     54        String enabled = _context.getProperty(Timestamper.PROP_DISABLED, "true");
     55        if ( (enabled == null) || (!"true".equalsIgnoreCase(enabled)) )
    5556            return "";
    5657        else
  • apps/routerconsole/jsp/config.jsp

    r3c9b027 r352396b  
    3535 <hr />
    3636 <b>Enable internal time synchronization?</b> <input type="checkbox" <jsp:getProperty name="nethelper" property="enableTimeSyncChecked" /> name="enabletimesync" /><br />
    37  <i>If disabled, your machine <b>must</b> be NTP synchronized.  This option only
    38     takes effect for the current run - if your machine is always synchronized within
    39     (a few seconds), you can update your configuration so that it doesn't start the
    40     "Timestamper" app (which would make this option irrelevent)</i>
     37 <i>If disabled, your machine <b>must</b> be NTP synchronized - your clock must always
     38    be within a few seconds of "correct".</i>
    4139 <hr />
    4240 <b>Bandwidth limiter</b><br />
  • build.xml

    r3c9b027 r352396b  
    2828        <ant dir="apps/heartbeat/java/" target="jar" />
    2929        <ant dir="apps/netmonitor/java/" target="jar" />
    30         <ant dir="apps/time/java/" target="jar" />
    3130        <ant dir="apps/routerconsole/java/" target="jar" />
    3231        <ant dir="installer/java/" target="jar" />
     
    4443        <copy file="apps/heartbeat/java/build/heartbeat.jar" todir="build/" />
    4544        <copy file="apps/netmonitor/java/build/netmonitor.jar" todir="build/" />
    46         <copy file="apps/time/java/build/timestamper.jar" todir="build/" />
    4745        <copy file="installer/java/build/install.jar" todir="build/" />
    4846        <copy file="installer/java/build/guiinstall.jar" todir="build/" />
     
    7573        <ant dir="apps/netmonitor/java/" target="distclean" />
    7674        <ant dir="apps/routerconsole/java/" target="distclean" />
    77         <ant dir="apps/time/java/" target="distclean" />
    7875        <ant dir="installer/java/" target="distclean" />
    7976        <delete>
  • core/java/src/net/i2p/time/NtpClient.java

    r3c9b027 r352396b  
    11package net.i2p.time;
    2 
     2/*
     3 * Copyright (c) 2004, Adam Buckley
     4 * All rights reserved.
     5 *
     6 * Redistribution and use in source and binary forms, with or without
     7 * modification, are permitted provided that the following conditions are met:
     8 *
     9 * - Redistributions of source code must retain the above copyright notice,
     10 *   this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright notice,
     12 *   this list of conditions and the following disclaimer in the documentation
     13 *   and/or other materials provided with the distribution.
     14 * - Neither the name of Adam Buckley nor the names of its contributors may be
     15 *   used to endorse or promote products derived from this software without
     16 *   specific prior written permission.
     17 *
     18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
     22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     28 * POSSIBILITY OF SUCH DAMAGE.
     29 *
     30 */
    331import java.io.IOException;
    432import java.io.InterruptedIOException;
     
    1745 * Note that on windows platforms, the curent time-of-day timestamp is limited
    1846 * to an resolution of 10ms and adversely affects the accuracy of the results.
    19  *
    20  *
    21  * This code is copyright (c) Adam Buckley 2004
    22  *
    23  * This program is free software; you can redistribute it and/or modify it
    24  * under the terms of the GNU General Public License as published by the Free
    25  * Software Foundation; either version 2 of the License, or (at your option)
    26  * any later version.  A HTML version of the GNU General Public License can be
    27  * seen at http://www.gnu.org/licenses/gpl.html
    28  *
    29  * This program is distributed in the hope that it will be useful, but WITHOUT
    30  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    31  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
    32  * more details.
    3347 *
    3448 * @author Adam Buckley
  • core/java/src/net/i2p/time/NtpMessage.java

    r3c9b027 r352396b  
    11package net.i2p.time;
     2/*
     3 * Copyright (c) 2004, Adam Buckley
     4 * All rights reserved.
     5 *
     6 * Redistribution and use in source and binary forms, with or without
     7 * modification, are permitted provided that the following conditions are met:
     8 *
     9 * - Redistributions of source code must retain the above copyright notice,
     10 *   this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright notice,
     12 *   this list of conditions and the following disclaimer in the documentation
     13 *   and/or other materials provided with the distribution.
     14 * - Neither the name of Adam Buckley nor the names of its contributors may be
     15 *   used to endorse or promote products derived from this software without
     16 *   specific prior written permission.
     17 *
     18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
     22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     28 * POSSIBILITY OF SUCH DAMAGE.
     29 *
     30 */
    231
    332import java.text.DecimalFormat;
     
    3463 * socket.receive(packet);
    3564 * System.out.println(msg.toString());
    36  *
    37  *
    38  * This code is copyright (c) Adam Buckley 2004
    39  *
    40  * This program is free software; you can redistribute it and/or modify it
    41  * under the terms of the GNU General Public License as published by the Free
    42  * Software Foundation; either version 2 of the License, or (at your option)
    43  * any later version.  A HTML version of the GNU General Public License can be
    44  * seen at http://www.gnu.org/licenses/gpl.html
    45  *
    46  * This program is distributed in the hope that it will be useful, but WITHOUT
    47  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    48  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
    49  * more details.
    50  *
    5165 *
    5266 * Comments for member variables are taken from RFC2030 by David Mills,
  • core/java/src/net/i2p/util/Clock.java

    r3c9b027 r352396b  
    66
    77import net.i2p.I2PAppContext;
     8import net.i2p.time.Timestamper;
    89
    910/**
     
    1415 *
    1516 */
    16 public class Clock {
     17public class Clock implements Timestamper.UpdateListener {
    1718    private I2PAppContext _context;
     19    private Timestamper _timestamper;
     20   
    1821    public Clock(I2PAppContext context) {
    1922        _context = context;
     
    2124        _alreadyChanged = false;
    2225        _listeners = new HashSet(64);
     26        _timestamper = new Timestamper(context, this);
    2327    }
    2428    public static Clock getInstance() {
    2529        return I2PAppContext.getGlobalContext().clock();
    2630    }
     31   
     32    public Timestamper getTimestamper() { return _timestamper; }
    2733   
    2834    /** we fetch it on demand to avoid circular dependencies (logging uses the clock) */
  • installer/java/build.xml

    r3c9b027 r352396b  
    1111        <ant dir="../../apps/netmonitor/java/" target="build" />
    1212        <ant dir="../../apps/heartbeat/java/" target="build" />
    13         <ant dir="../../apps/time/java/" target="build" />
    1413    </target>
    1514    <target name="compile">
     
    4140            <fileset file="../../apps/heartbeat/java/build/heartbeat.jar" />
    4241            <fileset file="../../apps/netmonitor/java/build/netmonitor.jar" />
    43             <fileset file="../../apps/time/java/build/timestamper.jar" />
    4442            <fileset file="../doc/COPYING" />
    4543            <fileset file="../../readme.txt" />
     
    6563            <fileset file="../../apps/heartbeat/java/build/heartbeat.jar" />
    6664            <fileset file="../../apps/netmonitor/java/build/netmonitor.jar" />
    67             <fileset file="../../apps/time/java/build/timestamper.jar" />
    6865            <fileset file="../doc/COPYING" />
    6966            <fileset file="../../readme.txt" />
     
    8784        <ant dir="../../apps/heartbeat/java" target="cleandep" />
    8885        <ant dir="../../apps/netmonitor/java" target="cleandep" />
    89         <ant dir="../../apps/time/java" target="cleandep" />
    9086    </target>
    9187    <target name="distclean" depends="clean">
     
    9793        <ant dir="../../apps/heartbeat/java" target="distclean" />
    9894        <ant dir="../../apps/netmonitor/java" target="distclean" />
    99         <ant dir="../../apps/time/java" target="distclean" />
    10095    </target>
    10196</project>
  • installer/java/src/Install.java

    r3c9b027 r352396b  
    326326        _inBPS = ((Integer)_answers.get("inBPS")).intValue();
    327327        _outBPS = ((Integer)_answers.get("outBPS")).intValue();
    328         long num = new java.util.Random().nextLong();
    329         if (num < 0)
    330             num = 0 - num;
    331         _answers.put("timestamperPassword", new Long(num));
    332328    }
    333329
  • installer/java/src/install.config

    r3c9b027 r352396b  
    116116libs.0013.name=heartbeat.config
    117117    libs.0013.islib=false
    118 libs.0014.name=timestamper.jar
    119     libs.0014.islib=true
  • installer/java/src/router.config.template

    r3c9b027 r352396b  
    110110#router.shutdownPassword=thisIsASecret
    111111
    112 #
    113 # the remaining lines describe how you can get your router to fire up client
    114 # applications it is up and running, all within the router's JVM.  Uncomment the
    115 # ones you want (revising the numbers and ports accordingly)
    116 
    117 # Keep the router's clock in sync by querying one of the specified NTP servers once
    118 # a minute (uses UDP port 123)
     112# Comma delimited list of SNTP servers to query.  pool.ntp.org is a DNS trick to
    119113# This defaults to the DNS round-robin ntp pool - see http://www.pool.ntp.org/
    120114# Please change the NTP server specified to include ones closer to you - see
     
    127121#  BE: ntp2.belbone.be
    128122#  AU: ntp.saard.net
    129 clientApp.0.main=net.i2p.time.Timestamper
    130 clientApp.0.name=Timestamper
    131 clientApp.0.onBoot=true
    132 clientApp.0.args=http://localhost:7655/setTime?##timestamperPassword## pool.ntp.org pool.ntp.org pool.ntp.org
     123time.sntpServerList=pool.ntp.org,pool.ntp.org,pool.ntp.org
    133124
    134 # The admin time passphrase, used to prevent unauthorized people from updating your
    135 # routers time.  The value should be included in the timestamper's args above,
    136 # otherwise it wont honor timestamp updates.  You shouldnt include any spaces or funky
    137 # characters - just pick some random numbers.
    138 adminTimePassphrase=##timestamperPassword##
     125# Query an SNTP server every 5 minutes
     126# time.queryFrequencyMs=300000
     127
     128# If you really really know that your computer's clock is ALWAYS correct, set this property
     129# time.disabled=true
     130
     131#
     132# the remaining lines describe how you can get your router to fire up client
     133# applications it is up and running, all within the router's JVM.  Uncomment the
     134# ones you want (revising the numbers and ports accordingly)
    139135
    140136# SAM bridge (a simplified socket based protocol for using I2P - listens on port 7656.  see
    141137# the specs at http://www.i2p.net/node/view/144 for more info)
    142 clientApp.1.main=net.i2p.sam.SAMBridge
    143 clientApp.1.name=SAMBridge
    144 clientApp.1.args=sam.keys 0.0.0.0 7656 i2cp.tcp.host=localhost i2cp.tcp.port=##_router_i2cp_port##
     138clientApp.0.main=net.i2p.sam.SAMBridge
     139clientApp.0.name=SAMBridge
     140clientApp.0.args=sam.keys 0.0.0.0 7656 i2cp.tcp.host=localhost i2cp.tcp.port=##_router_i2cp_port##
    145141
    146142# The eepProxy (HTTP proxy that lets you browse both eepsites and the normal web via squid.i2p) and
    147143# the ircProxy (which connects to the anonymously hosted ircd at irc.duck.i2p)
    148 clientApp.2.main=net.i2p.i2ptunnel.I2PTunnel
    149 clientApp.2.name=Tunnels
    150 clientApp.2.args=-nocli -e "config localhost ##_router_i2cp_port##" -e "httpclient 4444" -e "client 6668 irc.duck.i2p"
     144clientApp.1.main=net.i2p.i2ptunnel.I2PTunnel
     145clientApp.1.name=Tunnels
     146clientApp.1.args=-nocli -e "config localhost ##_router_i2cp_port##" -e "httpclient 4444" -e "client 6668 irc.duck.i2p"
    151147# note: if you want the proxies to be reachable from other machines, add:
    152148#       -e "listen_on 0.0.0.0"   
     
    158154# script
    159155# (don't bother trying to figure this out prior to the 0.4 release)
    160 #clientApp.3.main=net.i2p.router.web.RouterConsoleRunner
    161 #clientApp.3.name=webConsole
    162 #clientApp.3.args=7657 127.0.0.1 ./webapps/
    163 #clientApp.3.onBoot=true
     156#clientApp.2.main=net.i2p.router.web.RouterConsoleRunner
     157#clientApp.2.name=webConsole
     158#clientApp.2.args=7657 127.0.0.1 ./webapps/
     159#clientApp.2.onBoot=true
    164160
    165161# To require simple HTTP authentication for accessing any of the pages underneath the web console
     
    170166#
    171167#consolePassword=fooBarBaz
    172 
    173 # Network monitor (harvests data from the network database and stores it under
    174 # monitorData/, and with the netviewer GUI you can browse through its results)
    175 #clientApp.4.main=net.i2p.netmonitor.NetMonitor
    176 #clientApp.4.name=NetMonitor
    177 #clientApp.4.args=
    178 
    179 # Heartbeat engine (ueber-simple ping/pong system, configured in heartbeat.config.  By itself
    180 # it just writes out stat data where its told to, but there's a seperate HeartbeatMonitor
    181 # GUI to let you visualize things)
    182 #clientApp.5.main=net.i2p.heartbeat.Heartbeat
    183 #clientApp.5.name=Heartbeat
    184 #clientApp.5.args=heartbeat.config
  • installer/java/src/startRouter.bat.template

    r3c9b027 r352396b  
    55REM the -XX args are workarounds for bugs in java 1.4.2's garbage collector
    66
    7 java -cp lib\i2p.jar;lib\router.jar;lib\mstreaming.jar;lib\heartbeat.jar;lib\i2ptunnel.jar;lib\netmonitor.jar;lib\sam.jar;lib\timestamper.jar -Djava.library.path=. -DloggerFilenameOverride=logs\log-router-#.txt -XX:NewSize=4M -XX:MaxNewSize=8M -XX:PermSize=8M -XX:MaxPermSize=32M net.i2p.router.Router
     7java -cp lib\i2p.jar;lib\router.jar;lib\mstreaming.jar;lib\heartbeat.jar;lib\i2ptunnel.jar;lib\netmonitor.jar;lib\sam.jar -Djava.library.path=. -DloggerFilenameOverride=logs\log-router-#.txt -XX:NewSize=4M -XX:MaxNewSize=8M -XX:PermSize=8M -XX:MaxPermSize=32M net.i2p.router.Router
  • installer/java/src/startRouter.sh.template

    r3c9b027 r352396b  
    33export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
    44# the -XX args are workarounds for bugs in java 1.4.2's garbage collector
    5 nohup nice java -cp lib/i2p.jar:lib/router.jar:lib/mstreaming.jar:lib/heartbeat.jar:lib/i2ptunnel.jar:lib/netmonitor.jar:lib/sam.jar:lib/timestamper.jar -Djava.library.path=. -DloggerFilenameOverride=logs/log-router-#.txt -XX:NewSize=4M -XX:MaxNewSize=8M -XX:PermSize=8M -XX:MaxPermSize=32M net.i2p.router.Router --quiet > /dev/null &
     5nohup nice java -cp lib/i2p.jar:lib/router.jar:lib/mstreaming.jar:lib/heartbeat.jar:lib/i2ptunnel.jar:lib/netmonitor.jar:lib/sam.jar -Djava.library.path=. -DloggerFilenameOverride=logs/log-router-#.txt -XX:NewSize=4M -XX:MaxNewSize=8M -XX:PermSize=8M -XX:MaxPermSize=32M net.i2p.router.Router --quiet > /dev/null &
    66# Save the pid just in case we ever want to stop the router
    77echo $! > router.pid
  • router/java/src/net/i2p/router/admin/AdminRunner.java

    r3c9b027 r352396b  
    77import java.io.OutputStream;
    88import java.net.Socket;
    9 import java.text.ParseException;
    10 import java.text.SimpleDateFormat;
    119import java.util.Iterator;
    12 import java.util.Locale;
    1310import java.util.Set;
    1411
     
    5956        } else if (command.indexOf("/profile/") >= 0) {
    6057            replyText(out, getProfile(command));
    61         } else if (command.indexOf("setTime") >= 0) {
    62             if (allowTimeUpdate(command)) {
    63                 setTime(command);
    64                 reply(out, "<html><body>Time updated</body></html>");
    65             } else {
    66                 reply(out, "<html><body>Time not updated</body></html>");
    67             }
    6858        } else if (command.indexOf("/shutdown") >= 0) {
    6959            reply(out, shutdown(command));
     
    7868                throw ioe;
    7969            }
    80         }
    81     }
    82    
    83     private boolean allowTimeUpdate(String command) {
    84         String pass = _context.getProperty("adminTimePassphrase");
    85         if ( (pass == null) || (pass.trim().length() <= 0) ) {
    86             if (_log.shouldLog(Log.ERROR))
    87                 _log.error("No passphrase for update time from " + _socket.getInetAddress()
    88                           + ":" + _socket.getPort());
    89             return false;
    90         }
    91        
    92         if (command.indexOf(pass) != -1) {
    93             return true;
    94         } else {
    95             if (_log.shouldLog(Log.ERROR))
    96                 _log.error("Invalid passphrase for update time from " + _socket.getInetAddress()
    97                           + ":" + _socket.getPort());
    98             return false;
    9970        }
    10071    }
     
    153124    }
    154125   
    155    
    156     private static final String FORMAT_STRING = "yyyyMMdd_HH:mm:ss.SSS";
    157     private SimpleDateFormat _fmt = new SimpleDateFormat(FORMAT_STRING, Locale.UK);
    158    
    159     private long getTime(String now) throws ParseException {
    160         synchronized (_fmt) {
    161             return _fmt.parse(now).getTime();
    162         }
    163     }
    164     private void setTime(String cmd) {
    165         int start = cmd.indexOf("now=");
    166         String str = cmd.substring(start + 4, start+4+FORMAT_STRING.length());
    167         try {
    168             long now = getTime(str);
    169             if (_log.shouldLog(Log.INFO))
    170                 _log.log(Log.INFO, "Admin time set to " + str);
    171             setTime(now);
    172         } catch (ParseException pe) {
    173             _log.error("Invalid time specified [" + str + "]", pe);
    174         }
    175     }
    176    
    177     private void setTime(long now) {
    178         _context.clock().setNow(now);
    179     }
    180    
    181    
    182126    private static final String SHUTDOWN_PASSWORD_PROP = "router.shutdownPassword";
    183127    private String shutdown(String cmd) {
Note: See TracChangeset for help on using the changeset viewer.