Changeset f11a543
- Timestamp:
- Feb 11, 2011 11:59:10 PM (10 years ago)
- Branches:
- master
- Children:
- f4ca3976
- Parents:
- 3f3385f
- Files:
-
- 1 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketEepGet.java
r3f3385f rf11a543 60 60 super(ctx, false, null, -1, numRetries, minSize, maxSize, outputFile, outputStream, url, true, null, null); 61 61 _socketManager = mgr; 62 _log = ctx.logManager().getLog(I2PSocketEepGet.class);63 62 } 64 63 -
apps/routerconsole/java/src/net/i2p/router/web/NewsFetcher.java
r3f3385f rf11a543 4 4 import java.io.FileInputStream; 5 5 import java.io.IOException; 6 import java.text.ParseException;7 6 import java.text.SimpleDateFormat; 8 7 import java.util.Date; 9 8 import java.util.List; 10 import java.util.Locale;11 9 12 10 import net.i2p.I2PAppContext; … … 16 14 import net.i2p.router.RouterContext; 17 15 import net.i2p.router.RouterVersion; 16 import net.i2p.router.util.RFC822Date; 18 17 import net.i2p.util.EepGet; 19 18 import net.i2p.util.EepHead; … … 74 73 _lastFetch = _lastUpdated; 75 74 if (_lastModified == null) 76 _lastModified = to822Date(_lastFetch);75 _lastModified = RFC822Date.to822Date(_lastFetch); 77 76 } else { 78 77 _lastUpdated = 0; … … 213 212 if (lastmod != null) { 214 213 if (!(_context.isRouterContext())) return; 215 long modtime = parse822Date(lastmod);214 long modtime = RFC822Date.parse822Date(lastmod); 216 215 if (modtime <= 0) return; 217 216 String lastUpdate = _context.getProperty(UpdateHandler.PROP_LAST_UPDATE_TIME); … … 250 249 _unsignedUpdateVersion); 251 250 handler.update(); 252 }253 254 /**255 * http://jimyjoshi.com/blog/2007/08/rfc822dateparsinginjava.html256 * Apparently public domain257 * Probably don't need all of these...258 */259 private static final SimpleDateFormat rfc822DateFormats[] = new SimpleDateFormat[] {260 new SimpleDateFormat("EEE, d MMM yy HH:mm:ss z", Locale.US),261 new SimpleDateFormat("EEE, d MMM yy HH:mm z", Locale.US),262 new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z", Locale.US),263 new SimpleDateFormat("EEE, d MMM yyyy HH:mm z", Locale.US),264 new SimpleDateFormat("d MMM yy HH:mm z", Locale.US),265 new SimpleDateFormat("d MMM yy HH:mm:ss z", Locale.US),266 new SimpleDateFormat("d MMM yyyy HH:mm z", Locale.US),267 new SimpleDateFormat("d MMM yyyy HH:mm:ss z", Locale.US)268 };269 270 /**271 * new Date(String foo) is deprecated, so let's do this the hard way272 *273 * @param s non-null274 * @return -1 on failure275 */276 public static long parse822Date(String s) {277 for (int i = 0; i < rfc822DateFormats.length; i++) {278 try {279 Date date = rfc822DateFormats[i].parse(s);280 if (date != null)281 return date.getTime();282 } catch (ParseException pe) {}283 }284 return -1;285 }286 287 /** @since 0.8.2 */288 private static String to822Date(long t) {289 return (new SimpleDateFormat("d MMM yyyy HH:mm:ss z", Locale.US)).format(new Date(t));290 251 } 291 252 -
apps/routerconsole/java/src/net/i2p/router/web/UnsignedUpdateHandler.java
r3f3385f rf11a543 5 5 import net.i2p.router.Router; 6 6 import net.i2p.router.RouterContext; 7 import net.i2p.router.util.RFC822Date; 7 8 import net.i2p.util.EepGet; 8 9 import net.i2p.util.FileUtil; … … 102 103 long modtime = 0; 103 104 if (lastmod != null) 104 modtime = NewsFetcher.parse822Date(lastmod);105 modtime = RFC822Date.parse822Date(lastmod); 105 106 if (modtime <= 0) 106 107 modtime = _context.clock().now(); -
apps/routerconsole/java/src/net/i2p/router/web/UpdateHandler.java
r3f3385f rf11a543 16 16 import net.i2p.router.RouterContext; 17 17 import net.i2p.router.RouterVersion; 18 import net.i2p.router.util.RFC822Date; 18 19 import net.i2p.util.EepGet; 19 20 import net.i2p.util.I2PAppThread; … … 272 273 long modtime = 0; 273 274 if (lastmod != null) 274 modtime = NewsFetcher.parse822Date(lastmod);275 modtime = RFC822Date.parse822Date(lastmod); 275 276 if (modtime <= 0) 276 277 modtime = _context.clock().now(); -
core/java/src/net/i2p/time/Timestamper.java
r3f3385f rf11a543 5 5 import java.util.Locale; 6 6 import java.util.StringTokenizer; 7 import java.util.concurrent.CopyOnWriteArrayList; 7 8 8 9 import net.i2p.I2PAppContext; … … 57 58 // moved here to prevent problems with synchronized statements. 58 59 _servers = new ArrayList(3); 59 _listeners = new ArrayList(1);60 _listeners = new CopyOnWriteArrayList(); 60 61 // Don't bother starting a thread if we are disabled. 61 62 // This means we no longer check every 5 minutes to see if we got enabled, … … 93 94 94 95 public void addListener(UpdateListener lsnr) { 95 synchronized (_listeners) {96 96 _listeners.add(lsnr); 97 }98 97 } 99 98 public void removeListener(UpdateListener lsnr) { 100 synchronized (_listeners) {101 99 _listeners.remove(lsnr); 102 }103 100 } 104 101 public int getListenerCount() { 105 synchronized (_listeners) {106 102 return _listeners.size(); 107 }108 103 } 109 104 public UpdateListener getListener(int index) { 110 synchronized (_listeners) {111 105 return _listeners.get(index); 112 }113 106 } 114 107 … … 258 251 private void stampTime(long now, int stratum) { 259 252 long before = _context.clock().now(); 260 synchronized (_listeners) { 261 for (int i = 0; i < _listeners.size(); i++) { 262 UpdateListener lsnr = _listeners.get(i); 263 lsnr.setNow(now, stratum); 264 } 253 for (UpdateListener lsnr : _listeners) { 254 lsnr.setNow(now, stratum); 265 255 } 266 256 if (_log.shouldLog(Log.DEBUG)) -
core/java/src/net/i2p/util/Clock.java
r3f3385f rf11a543 50 50 public final static long MIN_OFFSET_CHANGE = 5 * 1000; 51 51 52 /** 53 * Specify how far away from the "correct" time the computer is - a positive 54 * value means that the system time is slow, while a negative value means the system time is fast. 55 * 56 * @param offsetMs the delta from System.currentTimeMillis() (NOT the delta from now()) 57 */ 52 58 public void setOffset(long offsetMs) { 53 59 setOffset(offsetMs, false); … … 56 62 /** 57 63 * Specify how far away from the "correct" time the computer is - a positive 58 * value means that we are slow, while a negative value means we arefast.64 * value means that the system time is slow, while a negative value means the system time is fast. 59 65 * Warning - overridden in RouterClock 66 * 67 * @param offsetMs the delta from System.currentTimeMillis() (NOT the delta from now()) 60 68 */ 61 69 public void setOffset(long offsetMs, boolean force) { … … 102 110 } 103 111 112 /* 113 * @return the current delta from System.currentTimeMillis() in milliseconds 114 */ 104 115 public long getOffset() { 105 116 return _offset; -
core/java/src/net/i2p/util/EepGet.java
r3f3385f rf11a543 29 29 */ 30 30 public class EepGet { 31 protected I2PAppContext _context;32 protected Log _log;33 protected boolean _shouldProxy;34 private String _proxyHost;35 private int _proxyPort;36 protected int _numRetries;37 private long _minSize; // minimum and maximum acceptable response size, -1 signifies unlimited,38 private long _maxSize; // applied both against whole responses and chunks39 protected String _outputFile;40 protected OutputStream _outputStream;31 protected final I2PAppContext _context; 32 protected final Log _log; 33 protected final boolean _shouldProxy; 34 private final String _proxyHost; 35 private final int _proxyPort; 36 protected final int _numRetries; 37 private final long _minSize; // minimum and maximum acceptable response size, -1 signifies unlimited, 38 private final long _maxSize; // applied both against whole responses and chunks 39 protected final String _outputFile; 40 protected final OutputStream _outputStream; 41 41 /** url we were asked to fetch */ 42 protected String _url;42 protected final String _url; 43 43 /** the URL we actually fetch from (may differ from the _url in case of redirect) */ 44 44 protected String _actualURL; 45 private String _postData;45 private final String _postData; 46 46 private boolean _allowCaching; 47 47 protected final List<StatusListener> _listeners; … … 107 107 String etag, String lastModified, String postData) { 108 108 _context = ctx; 109 _log = ctx.logManager().getLog( EepGet.class);109 _log = ctx.logManager().getLog(getClass()); 110 110 _shouldProxy = (proxyHost != null) && (proxyHost.length() > 0) && (proxyPort > 0) && shouldProxy; 111 111 _proxyHost = proxyHost; … … 119 119 _actualURL = url; 120 120 _postData = postData; 121 _alreadyTransferred = 0;122 _bytesTransferred = 0;123 121 _bytesRemaining = -1; 124 _currentAttempt = 0;125 _transferFailed = false;126 _headersRead = false;127 _aborted = false;128 122 _fetchHeaderTimeout = CONNECT_TIMEOUT; 129 123 _listeners = new ArrayList(1); … … 256 250 } 257 251 protected class CLIStatusListener implements StatusListener { 258 private int _markSize;259 private int _lineSize;260 private long _startedOn;252 private final int _markSize; 253 private final int _lineSize; 254 private final long _startedOn; 261 255 private long _written; 262 256 private long _previousWritten; … … 272 266 _markSize = markSize; 273 267 _lineSize = lineSize; 274 _written = 0;275 _previousWritten = 0;276 _discarded = 0;277 268 _lastComplete = _context.clock().now(); 278 269 _startedOn = _lastComplete; -
router/java/src/net/i2p/router/RouterClock.java
r3f3385f rf11a543 25 25 */ 26 26 private static final long MAX_SLEW = 50; 27 p rivatestatic final int DEFAULT_STRATUM = 8;27 public static final int DEFAULT_STRATUM = 8; 28 28 private static final int WORST_STRATUM = 16; 29 29 /** the max NTP Timestamper delay is 30m right now, make this longer than that */ … … 45 45 /** 46 46 * Specify how far away from the "correct" time the computer is - a positive 47 * value means that we are slow, while a negative value means we arefast.47 * value means that the system time is slow, while a negative value means the system time is fast. 48 48 * 49 * @param offsetMs the delta from System.currentTimeMillis() (NOT the delta from now()) 49 50 */ 50 51 @Override … … 53 54 } 54 55 55 /** @since 0.7.12 */ 56 /** 57 * @since 0.7.12 58 * @param offsetMs the delta from System.currentTimeMillis() (NOT the delta from now()) 59 */ 56 60 private void setOffset(long offsetMs, int stratum) { 57 61 setOffset(offsetMs, false, stratum); 58 62 } 59 63 60 /** @since 0.7.12 */ 64 /** 65 * @since 0.7.12 66 * @param offsetMs the delta from System.currentTimeMillis() (NOT the delta from now()) 67 */ 61 68 private void setOffset(long offsetMs, boolean force, int stratum) { 62 69 long delta = offsetMs - _offset; … … 92 99 93 100 // If so configured, check sanity of proposed clock offset 94 if ( Boolean.valueOf(_contextRC.getProperty("router.clockOffsetSanityCheck","true")).booleanValue() &&101 if (_contextRC.getBooleanPropertyDefaultTrue("router.clockOffsetSanityCheck") && 95 102 _alreadyChanged) { 96 103 … … 193 200 * How far we still have to slew, for diagnostics 194 201 * @since 0.7.12 202 * @deprecated for debugging only 195 203 */ 196 204 public long getDeltaOffset() { -
router/java/src/net/i2p/router/networkdb/reseed/Reseeder.java
r3f3385f rf11a543 15 15 16 16 import net.i2p.I2PAppContext; 17 import net.i2p.data.DataHelper; 18 import net.i2p.router.RouterClock; 17 19 import net.i2p.router.RouterContext; 20 import net.i2p.router.util.RFC822Date; 18 21 import net.i2p.util.EepGet; 19 22 import net.i2p.util.I2PAppThread; … … 35 38 */ 36 39 public class Reseeder { 40 /** FIXME don't keep a static reference, store _isRunning some other way */ 37 41 private static ReseedRunner _reseedRunner; 38 42 private final RouterContext _context; … … 47 51 * NOTE - URLs in both the standard and SSL groups should use the same hostname and path, 48 52 * so the reseed process will not download from both. 53 * 54 * NOTE - Each seedURL must be a directory, it must end with a '/', 55 * it can't end with 'index.html', for example. Both because of how individual file 56 * URLs are constructed, and because SSLEepGet doesn't follow redirects. 49 57 */ 50 58 public static final String DEFAULT_SEED_URL = … … 99 107 private int _proxyPort; 100 108 private SSLEepGet.SSLState _sslState; 109 private int _gotDate; 110 private long _attemptStarted; 111 private static final int MAX_DATE_SETS = 2; 101 112 102 113 public ReseedRunner() { 103 _isRunning = false; 104 System.clearProperty(PROP_ERROR); 105 System.setProperty(PROP_STATUS, _("Reseeding")); 106 System.setProperty(PROP_INPROGRESS, "true"); 107 } 114 } 115 108 116 public boolean isRunning() { return _isRunning; } 109 117 … … 114 122 public void run() { 115 123 _isRunning = true; 124 System.clearProperty(PROP_ERROR); 125 System.setProperty(PROP_STATUS, _("Reseeding")); 126 System.setProperty(PROP_INPROGRESS, "true"); 127 _attemptStarted = 0; 128 _gotDate = 0; 116 129 _sslState = null; // start fresh 117 130 if (_context.getBooleanProperty(PROP_PROXY_ENABLE)) { … … 153 166 public void transferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining, String url, String outputFile, boolean notModified) {} 154 167 public void transferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt) {} 155 public void headerReceived(String url, int attemptNum, String key, String val) {} 156 public void attempting(String url) {} 168 169 /** 170 * Use the Date header as a backup time source 171 */ 172 public void headerReceived(String url, int attemptNum, String key, String val) { 173 // We do this more than once, because 174 // the first SSL handshake may take a while, and it may take the server 175 // a while to render the index page. 176 if (_gotDate < MAX_DATE_SETS && "date".equalsIgnoreCase(key) && _attemptStarted > 0) { 177 long timeRcvd = System.currentTimeMillis(); 178 long serverTime = RFC822Date.parse822Date(val); 179 if (serverTime > 0) { 180 // add 500ms since it's 1-sec resolution, and add half the RTT 181 long now = serverTime + 500 + ((timeRcvd - _attemptStarted) / 2); 182 long offset = now - _context.clock().now(); 183 if (_context.clock().getUpdatedSuccessfully()) { 184 // 2nd time better than the first 185 if (_gotDate > 0) 186 _context.clock().setNow(now, RouterClock.DEFAULT_STRATUM - 2); 187 else 188 _context.clock().setNow(now, RouterClock.DEFAULT_STRATUM - 1); 189 if (_log.shouldLog(Log.WARN)) 190 _log.warn("Reseed adjusting clock by " + 191 DataHelper.formatDuration(Math.abs(offset))); 192 } else { 193 // No peers or NTP yet, this is probably better than the peer average will be for a while 194 // default stratum - 1, so the peer average is a worse stratum 195 _context.clock().setNow(now, RouterClock.DEFAULT_STRATUM - 1); 196 _log.logAlways(Log.WARN, "NTP failure, Reseed adjusting clock by " + 197 DataHelper.formatDuration(Math.abs(offset))); 198 } 199 _gotDate++; 200 } 201 } 202 } 203 204 /** save the start time */ 205 public void attempting(String url) { 206 if (_gotDate < MAX_DATE_SETS) 207 _attemptStarted = System.currentTimeMillis(); 208 } 209 157 210 // End of EepGet status listeners 158 211 … … 236 289 private int reseedOne(String seedURL, boolean echoStatus) { 237 290 try { 238 final long timeLimit = _context.clock().now() + MAX_TIME_PER_HOST; 291 // Don't use context clock as we may be adjusting the time 292 final long timeLimit = System.currentTimeMillis() + MAX_TIME_PER_HOST; 239 293 System.setProperty(PROP_STATUS, _("Reseeding: fetching seed URL.")); 240 294 System.err.println("Reseeding from " + seedURL); … … 276 330 // 200 max from one URL 277 331 for (Iterator<String> iter = urlList.iterator(); 278 iter.hasNext() && fetched < 200 && _context.clock().now() < timeLimit; ) {332 iter.hasNext() && fetched < 200 && System.currentTimeMillis() < timeLimit; ) { 279 333 try { 280 334 System.setProperty(PROP_STATUS, -
router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java
r3f3385f rf11a543 510 510 boolean found = _context.netDb().lookupRouterInfoLocally(peer) != null; 511 511 if (found) 512 buf.append("<a title=\"").append(_("NetDb entry")).append("\" href=\"netdb .jsp?r=").append(h).append("\">");512 buf.append("<a title=\"").append(_("NetDb entry")).append("\" href=\"netdb?r=").append(h).append("\">"); 513 513 buf.append(h); 514 514 if (found) -
router/java/src/net/i2p/router/transport/ntcp/EstablishState.java
r3f3385f rf11a543 400 400 _tsA = _tsB; 401 401 if (diff != 0) 402 _log. error("NTP failure, NTCP adjusting clock by " + DataHelper.formatDuration(diff));402 _log.logAlways(Log.WARN, "NTP failure, NTCP adjusting clock by " + DataHelper.formatDuration(diff)); 403 403 } else if (diff >= Router.CLOCK_FUDGE_FACTOR) { 404 404 _context.statManager().addRateData("ntcp.invalidOutboundSkew", diff, 0); … … 618 618 tsA = _tsB; 619 619 if (diff != 0) 620 _log. error("NTP failure, NTCP adjusting clock by " + DataHelper.formatDuration(diff));620 _log.logAlways(Log.WARN, "NTP failure, NTCP adjusting clock by " + DataHelper.formatDuration(diff)); 621 621 } else if (diff >= Router.CLOCK_FUDGE_FACTOR) { 622 622 _context.statManager().addRateData("ntcp.invalidInboundSkew", diff, 0); -
router/java/src/net/i2p/router/transport/udp/PacketHandler.java
r3f3385f rf11a543 474 474 _context.clock().setOffset(0 - skew, true); 475 475 if (skew != 0) 476 _log. error("NTP failure, UDP adjusting clock by " + DataHelper.formatDuration(Math.abs(skew)));476 _log.logAlways(Log.WARN, "NTP failure, UDP adjusting clock by " + DataHelper.formatDuration(Math.abs(skew))); 477 477 } 478 478
Note: See TracChangeset
for help on using the changeset viewer.