2005-03-24 01:19:52 +00:00
|
|
|
package net.i2p.router.web;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.IOException;
|
2009-08-09 14:28:20 +00:00
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.Date;
|
2005-03-24 01:19:52 +00:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.i2p.I2PAppContext;
|
2005-04-08 12:39:20 +00:00
|
|
|
import net.i2p.crypto.TrustedUpdate;
|
2005-03-24 01:19:52 +00:00
|
|
|
import net.i2p.data.DataHelper;
|
2008-05-10 14:31:18 +00:00
|
|
|
import net.i2p.router.Router;
|
2005-03-24 01:19:52 +00:00
|
|
|
import net.i2p.router.RouterContext;
|
|
|
|
import net.i2p.router.RouterVersion;
|
2011-02-11 23:59:10 +00:00
|
|
|
import net.i2p.router.util.RFC822Date;
|
2005-03-24 01:19:52 +00:00
|
|
|
import net.i2p.util.EepGet;
|
2009-08-09 14:28:20 +00:00
|
|
|
import net.i2p.util.EepHead;
|
2005-03-30 00:07:36 +00:00
|
|
|
import net.i2p.util.FileUtil;
|
2005-03-24 01:19:52 +00:00
|
|
|
import net.i2p.util.Log;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Task to periodically look for updates to the news.xml, and to keep
|
|
|
|
* track of whether that has an announcement for a new version.
|
|
|
|
*/
|
|
|
|
public class NewsFetcher implements Runnable, EepGet.StatusListener {
|
|
|
|
private I2PAppContext _context;
|
|
|
|
private Log _log;
|
|
|
|
private boolean _updateAvailable;
|
2009-08-09 14:28:20 +00:00
|
|
|
private boolean _unsignedUpdateAvailable;
|
2005-03-24 01:19:52 +00:00
|
|
|
private long _lastFetch;
|
2008-06-09 13:14:52 +00:00
|
|
|
private long _lastUpdated;
|
|
|
|
private String _updateVersion;
|
2009-08-09 14:28:20 +00:00
|
|
|
private String _unsignedUpdateVersion;
|
2008-01-09 04:11:12 +00:00
|
|
|
private String _lastModified;
|
Big directory rework.
Eliminate all uses of the current working directory, and
set up multiple directories specified by absolute paths for various uses.
Add a WorkingDir class to create a user config directory and
migrate files to it for new installs.
The directory will be $HOME/.i2p on linux and %APPDIR%\I2P on Windows,
or as specified in the system property -Di2p.dir.config=/path/to/i2pdir
All files except for the base install and temp files will be
in the config directory by default.
Temp files will be in a i2p-xxxxx subdirectory of the system temp directory
specified by the system property java.io.tmpdir.
Convert all file opens in the code to be relative to a specific directory,
as specified in the context. Code and applications should never open
files relative to the current working directory (e.g. new File("foo")).
All files should be accessed in the appropriate context directory,
e.g. new File(_context.getAppDir(), "foo").
The router.config file location may be specified as a system property on the
java command line with -Drouter.configLocation=/path/to/router.config
All directories may be specified as properties in the router.config file.
The migration will copy all files from an existing installation,
except i2psnark/, with the system property -Di2p.dir.migrate=true.
Otherwise it will just set up a new directory with a minimal configuration.
The migration will also create a modified wrapper.config and (on linux only)
a modified i2prouter script, and place them in the config directory.
There are no changes to the installer or the default i2prouter, i2prouter.bat,
i2prouter, wrapper.config, runplain.sh, windows service installer/uninstaller,
etc. in this checkin.
* Directories. These are all set at instantiation and will not be changed by
* subsequent property changes.
* All properties, if set, should be absolute paths.
*
* Name Property Method Files
* ----- -------- ----- -----
* Base i2p.dir.base getBaseDir() lib/, webapps/, docs/, geoip/, licenses/, ...
* Temp i2p.dir.temp getTempDir() Temporary files
* Config i2p.dir.config getConfigDir() *.config, hosts.txt, addressbook/, ...
*
* (the following all default to the same as Config)
*
* Router i2p.dir.router getRouterDir() netDb/, peerProfiles/, router.*, keyBackup/, ...
* Log i2p.dir.log getLogDir() wrapper.log*, logs/
* PID i2p.dir.pid getPIDDir() wrapper *.pid files, router.ping
* App i2p.dir.app getAppDir() eepsite/, ...
*
* Note that we can't control where the wrapper actually puts its files.
All these will be set appropriately in a Router Context.
In an I2P App Context, all except Temp will be the current working directory.
Lightly tested so far, needs much more testing.
2009-06-04 19:14:40 +00:00
|
|
|
private File _newsFile;
|
|
|
|
private File _tempFile;
|
2005-03-24 01:19:52 +00:00
|
|
|
private static NewsFetcher _instance;
|
2005-04-05 16:06:14 +00:00
|
|
|
//public static final synchronized NewsFetcher getInstance() { return _instance; }
|
|
|
|
public static final synchronized NewsFetcher getInstance(I2PAppContext ctx) {
|
|
|
|
if (_instance != null)
|
|
|
|
return _instance;
|
|
|
|
_instance = new NewsFetcher(ctx);
|
|
|
|
return _instance;
|
|
|
|
}
|
Big directory rework.
Eliminate all uses of the current working directory, and
set up multiple directories specified by absolute paths for various uses.
Add a WorkingDir class to create a user config directory and
migrate files to it for new installs.
The directory will be $HOME/.i2p on linux and %APPDIR%\I2P on Windows,
or as specified in the system property -Di2p.dir.config=/path/to/i2pdir
All files except for the base install and temp files will be
in the config directory by default.
Temp files will be in a i2p-xxxxx subdirectory of the system temp directory
specified by the system property java.io.tmpdir.
Convert all file opens in the code to be relative to a specific directory,
as specified in the context. Code and applications should never open
files relative to the current working directory (e.g. new File("foo")).
All files should be accessed in the appropriate context directory,
e.g. new File(_context.getAppDir(), "foo").
The router.config file location may be specified as a system property on the
java command line with -Drouter.configLocation=/path/to/router.config
All directories may be specified as properties in the router.config file.
The migration will copy all files from an existing installation,
except i2psnark/, with the system property -Di2p.dir.migrate=true.
Otherwise it will just set up a new directory with a minimal configuration.
The migration will also create a modified wrapper.config and (on linux only)
a modified i2prouter script, and place them in the config directory.
There are no changes to the installer or the default i2prouter, i2prouter.bat,
i2prouter, wrapper.config, runplain.sh, windows service installer/uninstaller,
etc. in this checkin.
* Directories. These are all set at instantiation and will not be changed by
* subsequent property changes.
* All properties, if set, should be absolute paths.
*
* Name Property Method Files
* ----- -------- ----- -----
* Base i2p.dir.base getBaseDir() lib/, webapps/, docs/, geoip/, licenses/, ...
* Temp i2p.dir.temp getTempDir() Temporary files
* Config i2p.dir.config getConfigDir() *.config, hosts.txt, addressbook/, ...
*
* (the following all default to the same as Config)
*
* Router i2p.dir.router getRouterDir() netDb/, peerProfiles/, router.*, keyBackup/, ...
* Log i2p.dir.log getLogDir() wrapper.log*, logs/
* PID i2p.dir.pid getPIDDir() wrapper *.pid files, router.ping
* App i2p.dir.app getAppDir() eepsite/, ...
*
* Note that we can't control where the wrapper actually puts its files.
All these will be set appropriately in a Router Context.
In an I2P App Context, all except Temp will be the current working directory.
Lightly tested so far, needs much more testing.
2009-06-04 19:14:40 +00:00
|
|
|
|
2005-03-24 01:19:52 +00:00
|
|
|
private static final String NEWS_FILE = "docs/news.xml";
|
Big directory rework.
Eliminate all uses of the current working directory, and
set up multiple directories specified by absolute paths for various uses.
Add a WorkingDir class to create a user config directory and
migrate files to it for new installs.
The directory will be $HOME/.i2p on linux and %APPDIR%\I2P on Windows,
or as specified in the system property -Di2p.dir.config=/path/to/i2pdir
All files except for the base install and temp files will be
in the config directory by default.
Temp files will be in a i2p-xxxxx subdirectory of the system temp directory
specified by the system property java.io.tmpdir.
Convert all file opens in the code to be relative to a specific directory,
as specified in the context. Code and applications should never open
files relative to the current working directory (e.g. new File("foo")).
All files should be accessed in the appropriate context directory,
e.g. new File(_context.getAppDir(), "foo").
The router.config file location may be specified as a system property on the
java command line with -Drouter.configLocation=/path/to/router.config
All directories may be specified as properties in the router.config file.
The migration will copy all files from an existing installation,
except i2psnark/, with the system property -Di2p.dir.migrate=true.
Otherwise it will just set up a new directory with a minimal configuration.
The migration will also create a modified wrapper.config and (on linux only)
a modified i2prouter script, and place them in the config directory.
There are no changes to the installer or the default i2prouter, i2prouter.bat,
i2prouter, wrapper.config, runplain.sh, windows service installer/uninstaller,
etc. in this checkin.
* Directories. These are all set at instantiation and will not be changed by
* subsequent property changes.
* All properties, if set, should be absolute paths.
*
* Name Property Method Files
* ----- -------- ----- -----
* Base i2p.dir.base getBaseDir() lib/, webapps/, docs/, geoip/, licenses/, ...
* Temp i2p.dir.temp getTempDir() Temporary files
* Config i2p.dir.config getConfigDir() *.config, hosts.txt, addressbook/, ...
*
* (the following all default to the same as Config)
*
* Router i2p.dir.router getRouterDir() netDb/, peerProfiles/, router.*, keyBackup/, ...
* Log i2p.dir.log getLogDir() wrapper.log*, logs/
* PID i2p.dir.pid getPIDDir() wrapper *.pid files, router.ping
* App i2p.dir.app getAppDir() eepsite/, ...
*
* Note that we can't control where the wrapper actually puts its files.
All these will be set appropriately in a Router Context.
In an I2P App Context, all except Temp will be the current working directory.
Lightly tested so far, needs much more testing.
2009-06-04 19:14:40 +00:00
|
|
|
private static final String TEMP_NEWS_FILE = "news.xml.temp";
|
2010-05-23 16:15:37 +00:00
|
|
|
/** @since 0.7.14 not configurable */
|
|
|
|
private static final String BACKUP_NEWS_URL = "http://www.i2p2.i2p/_static/news/news.xml";
|
2010-11-19 18:34:00 +00:00
|
|
|
private static final String PROP_LAST_CHECKED = "router.newsLastChecked";
|
2005-03-24 01:19:52 +00:00
|
|
|
|
2005-04-05 16:06:14 +00:00
|
|
|
private NewsFetcher(I2PAppContext ctx) {
|
2005-03-24 01:19:52 +00:00
|
|
|
_context = ctx;
|
|
|
|
_log = ctx.logManager().getLog(NewsFetcher.class);
|
|
|
|
_instance = this;
|
2010-11-19 18:34:00 +00:00
|
|
|
try {
|
|
|
|
String last = ctx.getProperty(PROP_LAST_CHECKED);
|
|
|
|
if (last != null)
|
|
|
|
_lastFetch = Long.parseLong(last);
|
|
|
|
} catch (NumberFormatException nfe) {}
|
2009-06-14 13:00:23 +00:00
|
|
|
_newsFile = new File(_context.getRouterDir(), NEWS_FILE);
|
Big directory rework.
Eliminate all uses of the current working directory, and
set up multiple directories specified by absolute paths for various uses.
Add a WorkingDir class to create a user config directory and
migrate files to it for new installs.
The directory will be $HOME/.i2p on linux and %APPDIR%\I2P on Windows,
or as specified in the system property -Di2p.dir.config=/path/to/i2pdir
All files except for the base install and temp files will be
in the config directory by default.
Temp files will be in a i2p-xxxxx subdirectory of the system temp directory
specified by the system property java.io.tmpdir.
Convert all file opens in the code to be relative to a specific directory,
as specified in the context. Code and applications should never open
files relative to the current working directory (e.g. new File("foo")).
All files should be accessed in the appropriate context directory,
e.g. new File(_context.getAppDir(), "foo").
The router.config file location may be specified as a system property on the
java command line with -Drouter.configLocation=/path/to/router.config
All directories may be specified as properties in the router.config file.
The migration will copy all files from an existing installation,
except i2psnark/, with the system property -Di2p.dir.migrate=true.
Otherwise it will just set up a new directory with a minimal configuration.
The migration will also create a modified wrapper.config and (on linux only)
a modified i2prouter script, and place them in the config directory.
There are no changes to the installer or the default i2prouter, i2prouter.bat,
i2prouter, wrapper.config, runplain.sh, windows service installer/uninstaller,
etc. in this checkin.
* Directories. These are all set at instantiation and will not be changed by
* subsequent property changes.
* All properties, if set, should be absolute paths.
*
* Name Property Method Files
* ----- -------- ----- -----
* Base i2p.dir.base getBaseDir() lib/, webapps/, docs/, geoip/, licenses/, ...
* Temp i2p.dir.temp getTempDir() Temporary files
* Config i2p.dir.config getConfigDir() *.config, hosts.txt, addressbook/, ...
*
* (the following all default to the same as Config)
*
* Router i2p.dir.router getRouterDir() netDb/, peerProfiles/, router.*, keyBackup/, ...
* Log i2p.dir.log getLogDir() wrapper.log*, logs/
* PID i2p.dir.pid getPIDDir() wrapper *.pid files, router.ping
* App i2p.dir.app getAppDir() eepsite/, ...
*
* Note that we can't control where the wrapper actually puts its files.
All these will be set appropriately in a Router Context.
In an I2P App Context, all except Temp will be the current working directory.
Lightly tested so far, needs much more testing.
2009-06-04 19:14:40 +00:00
|
|
|
_tempFile = new File(_context.getTempDir(), TEMP_NEWS_FILE);
|
2005-04-01 11:28:06 +00:00
|
|
|
updateLastFetched();
|
2008-06-09 13:14:52 +00:00
|
|
|
_updateVersion = "";
|
2005-04-01 11:28:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateLastFetched() {
|
Big directory rework.
Eliminate all uses of the current working directory, and
set up multiple directories specified by absolute paths for various uses.
Add a WorkingDir class to create a user config directory and
migrate files to it for new installs.
The directory will be $HOME/.i2p on linux and %APPDIR%\I2P on Windows,
or as specified in the system property -Di2p.dir.config=/path/to/i2pdir
All files except for the base install and temp files will be
in the config directory by default.
Temp files will be in a i2p-xxxxx subdirectory of the system temp directory
specified by the system property java.io.tmpdir.
Convert all file opens in the code to be relative to a specific directory,
as specified in the context. Code and applications should never open
files relative to the current working directory (e.g. new File("foo")).
All files should be accessed in the appropriate context directory,
e.g. new File(_context.getAppDir(), "foo").
The router.config file location may be specified as a system property on the
java command line with -Drouter.configLocation=/path/to/router.config
All directories may be specified as properties in the router.config file.
The migration will copy all files from an existing installation,
except i2psnark/, with the system property -Di2p.dir.migrate=true.
Otherwise it will just set up a new directory with a minimal configuration.
The migration will also create a modified wrapper.config and (on linux only)
a modified i2prouter script, and place them in the config directory.
There are no changes to the installer or the default i2prouter, i2prouter.bat,
i2prouter, wrapper.config, runplain.sh, windows service installer/uninstaller,
etc. in this checkin.
* Directories. These are all set at instantiation and will not be changed by
* subsequent property changes.
* All properties, if set, should be absolute paths.
*
* Name Property Method Files
* ----- -------- ----- -----
* Base i2p.dir.base getBaseDir() lib/, webapps/, docs/, geoip/, licenses/, ...
* Temp i2p.dir.temp getTempDir() Temporary files
* Config i2p.dir.config getConfigDir() *.config, hosts.txt, addressbook/, ...
*
* (the following all default to the same as Config)
*
* Router i2p.dir.router getRouterDir() netDb/, peerProfiles/, router.*, keyBackup/, ...
* Log i2p.dir.log getLogDir() wrapper.log*, logs/
* PID i2p.dir.pid getPIDDir() wrapper *.pid files, router.ping
* App i2p.dir.app getAppDir() eepsite/, ...
*
* Note that we can't control where the wrapper actually puts its files.
All these will be set appropriately in a Router Context.
In an I2P App Context, all except Temp will be the current working directory.
Lightly tested so far, needs much more testing.
2009-06-04 19:14:40 +00:00
|
|
|
if (_newsFile.exists()) {
|
2010-11-19 18:34:00 +00:00
|
|
|
if (_lastUpdated == 0)
|
|
|
|
_lastUpdated = _newsFile.lastModified();
|
2008-03-22 17:10:49 +00:00
|
|
|
if (_lastFetch == 0)
|
2010-11-19 18:34:00 +00:00
|
|
|
_lastFetch = _lastUpdated;
|
|
|
|
if (_lastModified == null)
|
2011-02-11 23:59:10 +00:00
|
|
|
_lastModified = RFC822Date.to822Date(_lastFetch);
|
2010-11-19 18:34:00 +00:00
|
|
|
} else {
|
|
|
|
_lastUpdated = 0;
|
2005-03-24 01:19:52 +00:00
|
|
|
_lastFetch = 0;
|
2010-11-19 18:34:00 +00:00
|
|
|
_lastModified = null;
|
|
|
|
}
|
2005-03-24 01:19:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean updateAvailable() { return _updateAvailable; }
|
2008-06-09 13:14:52 +00:00
|
|
|
public String updateVersion() { return _updateVersion; }
|
2009-08-09 14:28:20 +00:00
|
|
|
public boolean unsignedUpdateAvailable() { return _unsignedUpdateAvailable; }
|
|
|
|
public String unsignedUpdateVersion() { return _unsignedUpdateVersion; }
|
2008-06-09 13:14:52 +00:00
|
|
|
|
|
|
|
public String status() {
|
2009-10-26 21:48:46 +00:00
|
|
|
StringBuilder buf = new StringBuilder(128);
|
2008-06-09 13:14:52 +00:00
|
|
|
long now = _context.clock().now();
|
2009-10-26 21:48:46 +00:00
|
|
|
if (_lastUpdated > 0) {
|
|
|
|
buf.append(Messages.getString("News last updated {0} ago.",
|
2010-11-06 12:28:38 +00:00
|
|
|
DataHelper.formatDuration2(now - _lastUpdated),
|
2009-10-26 21:48:46 +00:00
|
|
|
_context))
|
|
|
|
.append('\n');
|
|
|
|
}
|
|
|
|
if (_lastFetch > _lastUpdated) {
|
|
|
|
buf.append(Messages.getString("News last checked {0} ago.",
|
2010-11-06 12:28:38 +00:00
|
|
|
DataHelper.formatDuration2(now - _lastFetch),
|
2009-10-26 21:48:46 +00:00
|
|
|
_context));
|
|
|
|
}
|
|
|
|
return buf.toString();
|
2008-06-09 13:14:52 +00:00
|
|
|
}
|
2005-03-24 01:19:52 +00:00
|
|
|
|
2010-06-03 16:51:37 +00:00
|
|
|
private static final long INITIAL_DELAY = 5*60*1000;
|
|
|
|
private static final long RUN_DELAY = 10*60*1000;
|
|
|
|
|
2005-03-24 01:19:52 +00:00
|
|
|
public void run() {
|
2010-06-03 16:51:37 +00:00
|
|
|
try { Thread.sleep(INITIAL_DELAY + _context.random().nextLong(INITIAL_DELAY)); } catch (InterruptedException ie) {}
|
2005-03-24 01:19:52 +00:00
|
|
|
while (true) {
|
|
|
|
if (!_updateAvailable) checkForUpdates();
|
2009-08-09 14:28:20 +00:00
|
|
|
if (shouldFetchNews()) {
|
2005-03-24 01:19:52 +00:00
|
|
|
fetchNews();
|
2009-08-09 14:28:20 +00:00
|
|
|
if (shouldFetchUnsigned())
|
|
|
|
fetchUnsignedHead();
|
|
|
|
}
|
2010-06-03 16:51:37 +00:00
|
|
|
try { Thread.sleep(RUN_DELAY); } catch (InterruptedException ie) {}
|
2005-03-24 01:19:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-02 15:25:26 +00:00
|
|
|
boolean dontInstall() {
|
|
|
|
File test = new File(_context.getBaseDir(), "history.txt");
|
|
|
|
boolean readonly = ((test.exists() && !test.canWrite()) || (!_context.getBaseDir().canWrite()));
|
|
|
|
boolean disabled = Boolean.valueOf(_context.getProperty(ConfigUpdateHandler.PROP_UPDATE_DISABLED)).booleanValue();
|
|
|
|
return readonly || disabled;
|
|
|
|
}
|
|
|
|
|
2005-03-24 01:19:52 +00:00
|
|
|
private boolean shouldInstall() {
|
|
|
|
String policy = _context.getProperty(ConfigUpdateHandler.PROP_UPDATE_POLICY);
|
2010-02-02 15:25:26 +00:00
|
|
|
if ("notify".equals(policy) || dontInstall())
|
2008-05-10 14:31:18 +00:00
|
|
|
return false;
|
Big directory rework.
Eliminate all uses of the current working directory, and
set up multiple directories specified by absolute paths for various uses.
Add a WorkingDir class to create a user config directory and
migrate files to it for new installs.
The directory will be $HOME/.i2p on linux and %APPDIR%\I2P on Windows,
or as specified in the system property -Di2p.dir.config=/path/to/i2pdir
All files except for the base install and temp files will be
in the config directory by default.
Temp files will be in a i2p-xxxxx subdirectory of the system temp directory
specified by the system property java.io.tmpdir.
Convert all file opens in the code to be relative to a specific directory,
as specified in the context. Code and applications should never open
files relative to the current working directory (e.g. new File("foo")).
All files should be accessed in the appropriate context directory,
e.g. new File(_context.getAppDir(), "foo").
The router.config file location may be specified as a system property on the
java command line with -Drouter.configLocation=/path/to/router.config
All directories may be specified as properties in the router.config file.
The migration will copy all files from an existing installation,
except i2psnark/, with the system property -Di2p.dir.migrate=true.
Otherwise it will just set up a new directory with a minimal configuration.
The migration will also create a modified wrapper.config and (on linux only)
a modified i2prouter script, and place them in the config directory.
There are no changes to the installer or the default i2prouter, i2prouter.bat,
i2prouter, wrapper.config, runplain.sh, windows service installer/uninstaller,
etc. in this checkin.
* Directories. These are all set at instantiation and will not be changed by
* subsequent property changes.
* All properties, if set, should be absolute paths.
*
* Name Property Method Files
* ----- -------- ----- -----
* Base i2p.dir.base getBaseDir() lib/, webapps/, docs/, geoip/, licenses/, ...
* Temp i2p.dir.temp getTempDir() Temporary files
* Config i2p.dir.config getConfigDir() *.config, hosts.txt, addressbook/, ...
*
* (the following all default to the same as Config)
*
* Router i2p.dir.router getRouterDir() netDb/, peerProfiles/, router.*, keyBackup/, ...
* Log i2p.dir.log getLogDir() wrapper.log*, logs/
* PID i2p.dir.pid getPIDDir() wrapper *.pid files, router.ping
* App i2p.dir.app getAppDir() eepsite/, ...
*
* Note that we can't control where the wrapper actually puts its files.
All these will be set appropriately in a Router Context.
In an I2P App Context, all except Temp will be the current working directory.
Lightly tested so far, needs much more testing.
2009-06-04 19:14:40 +00:00
|
|
|
File zip = new File(_context.getRouterDir(), Router.UPDATE_FILE);
|
2008-05-10 14:31:18 +00:00
|
|
|
return !zip.exists();
|
2005-03-24 01:19:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean shouldFetchNews() {
|
2005-04-01 11:28:06 +00:00
|
|
|
updateLastFetched();
|
2009-08-09 14:28:20 +00:00
|
|
|
String freq = _context.getProperty(ConfigUpdateHandler.PROP_REFRESH_FREQUENCY,
|
|
|
|
ConfigUpdateHandler.DEFAULT_REFRESH_FREQUENCY);
|
2005-03-24 01:19:52 +00:00
|
|
|
try {
|
|
|
|
long ms = Long.parseLong(freq);
|
|
|
|
if (ms <= 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (_lastFetch + ms < _context.clock().now()) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
if (_log.shouldLog(Log.DEBUG))
|
2010-11-19 18:34:00 +00:00
|
|
|
_log.debug("Last fetched " + DataHelper.formatDuration(_context.clock().now() - _lastFetch) + " ago");
|
2005-03-24 01:19:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} catch (NumberFormatException nfe) {
|
|
|
|
if (_log.shouldLog(Log.ERROR))
|
|
|
|
_log.error("Invalid refresh frequency: " + freq);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2005-04-26 02:59:23 +00:00
|
|
|
public void fetchNews() {
|
2009-06-19 00:04:19 +00:00
|
|
|
String newsURL = ConfigUpdateHelper.getNewsURL(_context);
|
2005-03-24 01:19:52 +00:00
|
|
|
boolean shouldProxy = Boolean.valueOf(_context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY)).booleanValue();
|
|
|
|
String proxyHost = _context.getProperty(ConfigUpdateHandler.PROP_PROXY_HOST, ConfigUpdateHandler.DEFAULT_PROXY_HOST);
|
2009-08-09 14:28:20 +00:00
|
|
|
int proxyPort = _context.getProperty(ConfigUpdateHandler.PROP_PROXY_PORT, ConfigUpdateHandler.DEFAULT_PROXY_PORT_INT);
|
Big directory rework.
Eliminate all uses of the current working directory, and
set up multiple directories specified by absolute paths for various uses.
Add a WorkingDir class to create a user config directory and
migrate files to it for new installs.
The directory will be $HOME/.i2p on linux and %APPDIR%\I2P on Windows,
or as specified in the system property -Di2p.dir.config=/path/to/i2pdir
All files except for the base install and temp files will be
in the config directory by default.
Temp files will be in a i2p-xxxxx subdirectory of the system temp directory
specified by the system property java.io.tmpdir.
Convert all file opens in the code to be relative to a specific directory,
as specified in the context. Code and applications should never open
files relative to the current working directory (e.g. new File("foo")).
All files should be accessed in the appropriate context directory,
e.g. new File(_context.getAppDir(), "foo").
The router.config file location may be specified as a system property on the
java command line with -Drouter.configLocation=/path/to/router.config
All directories may be specified as properties in the router.config file.
The migration will copy all files from an existing installation,
except i2psnark/, with the system property -Di2p.dir.migrate=true.
Otherwise it will just set up a new directory with a minimal configuration.
The migration will also create a modified wrapper.config and (on linux only)
a modified i2prouter script, and place them in the config directory.
There are no changes to the installer or the default i2prouter, i2prouter.bat,
i2prouter, wrapper.config, runplain.sh, windows service installer/uninstaller,
etc. in this checkin.
* Directories. These are all set at instantiation and will not be changed by
* subsequent property changes.
* All properties, if set, should be absolute paths.
*
* Name Property Method Files
* ----- -------- ----- -----
* Base i2p.dir.base getBaseDir() lib/, webapps/, docs/, geoip/, licenses/, ...
* Temp i2p.dir.temp getTempDir() Temporary files
* Config i2p.dir.config getConfigDir() *.config, hosts.txt, addressbook/, ...
*
* (the following all default to the same as Config)
*
* Router i2p.dir.router getRouterDir() netDb/, peerProfiles/, router.*, keyBackup/, ...
* Log i2p.dir.log getLogDir() wrapper.log*, logs/
* PID i2p.dir.pid getPIDDir() wrapper *.pid files, router.ping
* App i2p.dir.app getAppDir() eepsite/, ...
*
* Note that we can't control where the wrapper actually puts its files.
All these will be set appropriately in a Router Context.
In an I2P App Context, all except Temp will be the current working directory.
Lightly tested so far, needs much more testing.
2009-06-04 19:14:40 +00:00
|
|
|
if (_tempFile.exists())
|
|
|
|
_tempFile.delete();
|
2005-03-30 00:07:36 +00:00
|
|
|
|
2005-03-24 01:19:52 +00:00
|
|
|
try {
|
|
|
|
EepGet get = null;
|
|
|
|
if (shouldProxy)
|
2010-05-23 16:15:37 +00:00
|
|
|
get = new EepGet(_context, true, proxyHost, proxyPort, 0, _tempFile.getAbsolutePath(), newsURL, true, null, _lastModified);
|
2005-03-24 01:19:52 +00:00
|
|
|
else
|
Big directory rework.
Eliminate all uses of the current working directory, and
set up multiple directories specified by absolute paths for various uses.
Add a WorkingDir class to create a user config directory and
migrate files to it for new installs.
The directory will be $HOME/.i2p on linux and %APPDIR%\I2P on Windows,
or as specified in the system property -Di2p.dir.config=/path/to/i2pdir
All files except for the base install and temp files will be
in the config directory by default.
Temp files will be in a i2p-xxxxx subdirectory of the system temp directory
specified by the system property java.io.tmpdir.
Convert all file opens in the code to be relative to a specific directory,
as specified in the context. Code and applications should never open
files relative to the current working directory (e.g. new File("foo")).
All files should be accessed in the appropriate context directory,
e.g. new File(_context.getAppDir(), "foo").
The router.config file location may be specified as a system property on the
java command line with -Drouter.configLocation=/path/to/router.config
All directories may be specified as properties in the router.config file.
The migration will copy all files from an existing installation,
except i2psnark/, with the system property -Di2p.dir.migrate=true.
Otherwise it will just set up a new directory with a minimal configuration.
The migration will also create a modified wrapper.config and (on linux only)
a modified i2prouter script, and place them in the config directory.
There are no changes to the installer or the default i2prouter, i2prouter.bat,
i2prouter, wrapper.config, runplain.sh, windows service installer/uninstaller,
etc. in this checkin.
* Directories. These are all set at instantiation and will not be changed by
* subsequent property changes.
* All properties, if set, should be absolute paths.
*
* Name Property Method Files
* ----- -------- ----- -----
* Base i2p.dir.base getBaseDir() lib/, webapps/, docs/, geoip/, licenses/, ...
* Temp i2p.dir.temp getTempDir() Temporary files
* Config i2p.dir.config getConfigDir() *.config, hosts.txt, addressbook/, ...
*
* (the following all default to the same as Config)
*
* Router i2p.dir.router getRouterDir() netDb/, peerProfiles/, router.*, keyBackup/, ...
* Log i2p.dir.log getLogDir() wrapper.log*, logs/
* PID i2p.dir.pid getPIDDir() wrapper *.pid files, router.ping
* App i2p.dir.app getAppDir() eepsite/, ...
*
* Note that we can't control where the wrapper actually puts its files.
All these will be set appropriately in a Router Context.
In an I2P App Context, all except Temp will be the current working directory.
Lightly tested so far, needs much more testing.
2009-06-04 19:14:40 +00:00
|
|
|
get = new EepGet(_context, false, null, 0, 0, _tempFile.getAbsolutePath(), newsURL, true, null, _lastModified);
|
2005-03-24 01:19:52 +00:00
|
|
|
get.addStatusListener(this);
|
2010-05-23 16:15:37 +00:00
|
|
|
if (get.fetch()) {
|
2008-01-09 04:11:12 +00:00
|
|
|
_lastModified = get.getLastModified();
|
2010-05-23 16:15:37 +00:00
|
|
|
} else {
|
|
|
|
// backup news location - always proxied
|
|
|
|
_tempFile.delete();
|
|
|
|
get = new EepGet(_context, true, proxyHost, proxyPort, 0, _tempFile.getAbsolutePath(), BACKUP_NEWS_URL, true, null, _lastModified);
|
|
|
|
get.addStatusListener(this);
|
|
|
|
if (get.fetch())
|
|
|
|
_lastModified = get.getLastModified();
|
|
|
|
}
|
2005-03-24 01:19:52 +00:00
|
|
|
} catch (Throwable t) {
|
|
|
|
_log.error("Error fetching the news", t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-09 14:28:20 +00:00
|
|
|
public boolean shouldFetchUnsigned() {
|
|
|
|
String url = _context.getProperty(ConfigUpdateHandler.PROP_ZIP_URL);
|
|
|
|
return url != null && url.length() > 0 &&
|
2010-02-02 15:25:26 +00:00
|
|
|
Boolean.valueOf(_context.getProperty(ConfigUpdateHandler.PROP_UPDATE_UNSIGNED)).booleanValue() &&
|
|
|
|
!dontInstall();
|
2009-08-09 14:28:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* HEAD the update url, and if the last-mod time is newer than the last update we
|
|
|
|
* downloaded, as stored in the properties, then we download it using eepget.
|
|
|
|
*/
|
|
|
|
public void fetchUnsignedHead() {
|
|
|
|
String url = _context.getProperty(ConfigUpdateHandler.PROP_ZIP_URL);
|
|
|
|
if (url == null || url.length() <= 0)
|
|
|
|
return;
|
|
|
|
// assume always proxied for now
|
|
|
|
//boolean shouldProxy = Boolean.valueOf(_context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY)).booleanValue();
|
|
|
|
String proxyHost = _context.getProperty(ConfigUpdateHandler.PROP_PROXY_HOST, ConfigUpdateHandler.DEFAULT_PROXY_HOST);
|
|
|
|
int proxyPort = _context.getProperty(ConfigUpdateHandler.PROP_PROXY_PORT, ConfigUpdateHandler.DEFAULT_PROXY_PORT_INT);
|
|
|
|
|
|
|
|
try {
|
|
|
|
EepHead get = new EepHead(_context, proxyHost, proxyPort, 0, url);
|
|
|
|
if (get.fetch()) {
|
|
|
|
String lastmod = get.getLastModified();
|
|
|
|
if (lastmod != null) {
|
2009-12-19 16:37:44 +00:00
|
|
|
if (!(_context.isRouterContext())) return;
|
2011-02-11 23:59:10 +00:00
|
|
|
long modtime = RFC822Date.parse822Date(lastmod);
|
2009-08-09 14:28:20 +00:00
|
|
|
if (modtime <= 0) return;
|
|
|
|
String lastUpdate = _context.getProperty(UpdateHandler.PROP_LAST_UPDATE_TIME);
|
|
|
|
if (lastUpdate == null) {
|
|
|
|
// we don't know what version you have, so stamp it with the current time,
|
|
|
|
// and we'll look for something newer next time around.
|
|
|
|
((RouterContext)_context).router().setConfigSetting(UpdateHandler.PROP_LAST_UPDATE_TIME,
|
|
|
|
"" + _context.clock().now());
|
|
|
|
((RouterContext)_context).router().saveConfig();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
long ms = 0;
|
|
|
|
try {
|
|
|
|
ms = Long.parseLong(lastUpdate);
|
|
|
|
} catch (NumberFormatException nfe) {}
|
|
|
|
if (ms <= 0) return;
|
|
|
|
if (modtime > ms) {
|
|
|
|
_unsignedUpdateAvailable = true;
|
2009-08-19 20:20:25 +00:00
|
|
|
// '07-Jul 21:09 UTC' with month name in the system locale
|
|
|
|
_unsignedUpdateVersion = (new SimpleDateFormat("dd-MMM HH:mm")).format(new Date(modtime)) + " UTC";
|
2009-08-09 14:28:20 +00:00
|
|
|
if (shouldInstall())
|
|
|
|
fetchUnsigned();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Throwable t) {
|
|
|
|
_log.error("Error fetching the unsigned update", t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void fetchUnsigned() {
|
|
|
|
String url = _context.getProperty(ConfigUpdateHandler.PROP_ZIP_URL);
|
|
|
|
if (url == null || url.length() <= 0)
|
|
|
|
return;
|
|
|
|
UpdateHandler handler = new UnsignedUpdateHandler((RouterContext)_context, url,
|
|
|
|
_unsignedUpdateVersion);
|
|
|
|
handler.update();
|
|
|
|
}
|
|
|
|
|
2005-03-24 01:19:52 +00:00
|
|
|
private static final String VERSION_STRING = "version=\"" + RouterVersion.VERSION + "\"";
|
2005-03-24 03:18:15 +00:00
|
|
|
private static final String VERSION_PREFIX = "version=\"";
|
2005-03-24 01:19:52 +00:00
|
|
|
private void checkForUpdates() {
|
2005-04-01 13:29:26 +00:00
|
|
|
_updateAvailable = false;
|
Big directory rework.
Eliminate all uses of the current working directory, and
set up multiple directories specified by absolute paths for various uses.
Add a WorkingDir class to create a user config directory and
migrate files to it for new installs.
The directory will be $HOME/.i2p on linux and %APPDIR%\I2P on Windows,
or as specified in the system property -Di2p.dir.config=/path/to/i2pdir
All files except for the base install and temp files will be
in the config directory by default.
Temp files will be in a i2p-xxxxx subdirectory of the system temp directory
specified by the system property java.io.tmpdir.
Convert all file opens in the code to be relative to a specific directory,
as specified in the context. Code and applications should never open
files relative to the current working directory (e.g. new File("foo")).
All files should be accessed in the appropriate context directory,
e.g. new File(_context.getAppDir(), "foo").
The router.config file location may be specified as a system property on the
java command line with -Drouter.configLocation=/path/to/router.config
All directories may be specified as properties in the router.config file.
The migration will copy all files from an existing installation,
except i2psnark/, with the system property -Di2p.dir.migrate=true.
Otherwise it will just set up a new directory with a minimal configuration.
The migration will also create a modified wrapper.config and (on linux only)
a modified i2prouter script, and place them in the config directory.
There are no changes to the installer or the default i2prouter, i2prouter.bat,
i2prouter, wrapper.config, runplain.sh, windows service installer/uninstaller,
etc. in this checkin.
* Directories. These are all set at instantiation and will not be changed by
* subsequent property changes.
* All properties, if set, should be absolute paths.
*
* Name Property Method Files
* ----- -------- ----- -----
* Base i2p.dir.base getBaseDir() lib/, webapps/, docs/, geoip/, licenses/, ...
* Temp i2p.dir.temp getTempDir() Temporary files
* Config i2p.dir.config getConfigDir() *.config, hosts.txt, addressbook/, ...
*
* (the following all default to the same as Config)
*
* Router i2p.dir.router getRouterDir() netDb/, peerProfiles/, router.*, keyBackup/, ...
* Log i2p.dir.log getLogDir() wrapper.log*, logs/
* PID i2p.dir.pid getPIDDir() wrapper *.pid files, router.ping
* App i2p.dir.app getAppDir() eepsite/, ...
*
* Note that we can't control where the wrapper actually puts its files.
All these will be set appropriately in a Router Context.
In an I2P App Context, all except Temp will be the current working directory.
Lightly tested so far, needs much more testing.
2009-06-04 19:14:40 +00:00
|
|
|
if ( (!_newsFile.exists()) || (_newsFile.length() <= 0) ) return;
|
2005-03-24 01:19:52 +00:00
|
|
|
FileInputStream in = null;
|
|
|
|
try {
|
Big directory rework.
Eliminate all uses of the current working directory, and
set up multiple directories specified by absolute paths for various uses.
Add a WorkingDir class to create a user config directory and
migrate files to it for new installs.
The directory will be $HOME/.i2p on linux and %APPDIR%\I2P on Windows,
or as specified in the system property -Di2p.dir.config=/path/to/i2pdir
All files except for the base install and temp files will be
in the config directory by default.
Temp files will be in a i2p-xxxxx subdirectory of the system temp directory
specified by the system property java.io.tmpdir.
Convert all file opens in the code to be relative to a specific directory,
as specified in the context. Code and applications should never open
files relative to the current working directory (e.g. new File("foo")).
All files should be accessed in the appropriate context directory,
e.g. new File(_context.getAppDir(), "foo").
The router.config file location may be specified as a system property on the
java command line with -Drouter.configLocation=/path/to/router.config
All directories may be specified as properties in the router.config file.
The migration will copy all files from an existing installation,
except i2psnark/, with the system property -Di2p.dir.migrate=true.
Otherwise it will just set up a new directory with a minimal configuration.
The migration will also create a modified wrapper.config and (on linux only)
a modified i2prouter script, and place them in the config directory.
There are no changes to the installer or the default i2prouter, i2prouter.bat,
i2prouter, wrapper.config, runplain.sh, windows service installer/uninstaller,
etc. in this checkin.
* Directories. These are all set at instantiation and will not be changed by
* subsequent property changes.
* All properties, if set, should be absolute paths.
*
* Name Property Method Files
* ----- -------- ----- -----
* Base i2p.dir.base getBaseDir() lib/, webapps/, docs/, geoip/, licenses/, ...
* Temp i2p.dir.temp getTempDir() Temporary files
* Config i2p.dir.config getConfigDir() *.config, hosts.txt, addressbook/, ...
*
* (the following all default to the same as Config)
*
* Router i2p.dir.router getRouterDir() netDb/, peerProfiles/, router.*, keyBackup/, ...
* Log i2p.dir.log getLogDir() wrapper.log*, logs/
* PID i2p.dir.pid getPIDDir() wrapper *.pid files, router.ping
* App i2p.dir.app getAppDir() eepsite/, ...
*
* Note that we can't control where the wrapper actually puts its files.
All these will be set appropriately in a Router Context.
In an I2P App Context, all except Temp will be the current working directory.
Lightly tested so far, needs much more testing.
2009-06-04 19:14:40 +00:00
|
|
|
in = new FileInputStream(_newsFile);
|
2009-07-01 16:00:43 +00:00
|
|
|
StringBuilder buf = new StringBuilder(128);
|
2005-03-24 01:19:52 +00:00
|
|
|
while (DataHelper.readLine(in, buf)) {
|
2005-03-24 03:18:15 +00:00
|
|
|
int index = buf.indexOf(VERSION_PREFIX);
|
|
|
|
if (index == -1) {
|
|
|
|
// skip
|
|
|
|
} else {
|
|
|
|
int end = buf.indexOf("\"", index + VERSION_PREFIX.length());
|
|
|
|
if (end > index) {
|
|
|
|
String ver = buf.substring(index+VERSION_PREFIX.length(), end);
|
|
|
|
if (_log.shouldLog(Log.DEBUG))
|
|
|
|
_log.debug("Found version: [" + ver + "]");
|
2005-04-08 12:39:20 +00:00
|
|
|
if (TrustedUpdate.needsUpdate(RouterVersion.VERSION, ver)) {
|
2005-03-24 03:18:15 +00:00
|
|
|
if (_log.shouldLog(Log.DEBUG))
|
|
|
|
_log.debug("Our version is out of date, update!");
|
2008-06-09 13:14:52 +00:00
|
|
|
_updateVersion = ver;
|
2005-03-24 03:18:15 +00:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
if (_log.shouldLog(Log.DEBUG))
|
|
|
|
_log.debug("Our version is current");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-03-24 01:19:52 +00:00
|
|
|
if (buf.indexOf(VERSION_STRING) != -1) {
|
|
|
|
if (_log.shouldLog(Log.DEBUG))
|
|
|
|
_log.debug("Our version found, no need to update: " + buf.toString());
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
if (_log.shouldLog(Log.DEBUG))
|
|
|
|
_log.debug("No match in " + buf.toString());
|
|
|
|
}
|
|
|
|
buf.setLength(0);
|
|
|
|
}
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
if (_log.shouldLog(Log.WARN))
|
|
|
|
_log.warn("Error checking the news for an update", ioe);
|
|
|
|
return;
|
|
|
|
} finally {
|
|
|
|
if (in != null) try { in.close(); } catch (IOException ioe) {}
|
|
|
|
}
|
|
|
|
// could not find version="0.5.0.1", so there must be an update ;)
|
|
|
|
|
|
|
|
if (_log.shouldLog(Log.DEBUG))
|
|
|
|
_log.debug("Our version was NOT found (" + RouterVersion.VERSION + "), update needed");
|
2010-02-02 15:25:26 +00:00
|
|
|
_updateAvailable = !dontInstall();
|
2005-03-24 01:19:52 +00:00
|
|
|
|
|
|
|
if (shouldInstall()) {
|
|
|
|
if (_log.shouldLog(Log.DEBUG))
|
|
|
|
_log.debug("Policy requests update, so we update");
|
|
|
|
UpdateHandler handler = null;
|
2009-12-19 16:37:44 +00:00
|
|
|
if (_context.isRouterContext()) {
|
2005-03-24 01:19:52 +00:00
|
|
|
handler = new UpdateHandler((RouterContext)_context);
|
|
|
|
} else {
|
|
|
|
List contexts = RouterContext.listContexts();
|
2010-05-05 16:51:54 +00:00
|
|
|
if (!contexts.isEmpty())
|
2005-03-24 01:19:52 +00:00
|
|
|
handler = new UpdateHandler((RouterContext)contexts.get(0));
|
|
|
|
else
|
|
|
|
_log.log(Log.CRIT, "No router context to update with?");
|
|
|
|
}
|
|
|
|
if (handler != null)
|
|
|
|
handler.update();
|
|
|
|
} else {
|
|
|
|
if (_log.shouldLog(Log.DEBUG))
|
|
|
|
_log.debug("Policy requests manual update, so we do nothing");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void attemptFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt, int numRetries, Exception cause) {
|
|
|
|
// ignore
|
|
|
|
}
|
|
|
|
public void bytesTransferred(long alreadyTransferred, int currentWrite, long bytesTransferred, long bytesRemaining, String url) {
|
|
|
|
// ignore
|
|
|
|
}
|
2005-10-01 00:57:32 +00:00
|
|
|
public void transferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining, String url, String outputFile, boolean notModified) {
|
2005-03-24 01:19:52 +00:00
|
|
|
if (_log.shouldLog(Log.INFO))
|
2005-04-01 13:29:26 +00:00
|
|
|
_log.info("News fetched from " + url + " with " + (alreadyTransferred+bytesTransferred));
|
2005-03-30 00:07:36 +00:00
|
|
|
|
2008-11-02 21:37:28 +00:00
|
|
|
long now = _context.clock().now();
|
Big directory rework.
Eliminate all uses of the current working directory, and
set up multiple directories specified by absolute paths for various uses.
Add a WorkingDir class to create a user config directory and
migrate files to it for new installs.
The directory will be $HOME/.i2p on linux and %APPDIR%\I2P on Windows,
or as specified in the system property -Di2p.dir.config=/path/to/i2pdir
All files except for the base install and temp files will be
in the config directory by default.
Temp files will be in a i2p-xxxxx subdirectory of the system temp directory
specified by the system property java.io.tmpdir.
Convert all file opens in the code to be relative to a specific directory,
as specified in the context. Code and applications should never open
files relative to the current working directory (e.g. new File("foo")).
All files should be accessed in the appropriate context directory,
e.g. new File(_context.getAppDir(), "foo").
The router.config file location may be specified as a system property on the
java command line with -Drouter.configLocation=/path/to/router.config
All directories may be specified as properties in the router.config file.
The migration will copy all files from an existing installation,
except i2psnark/, with the system property -Di2p.dir.migrate=true.
Otherwise it will just set up a new directory with a minimal configuration.
The migration will also create a modified wrapper.config and (on linux only)
a modified i2prouter script, and place them in the config directory.
There are no changes to the installer or the default i2prouter, i2prouter.bat,
i2prouter, wrapper.config, runplain.sh, windows service installer/uninstaller,
etc. in this checkin.
* Directories. These are all set at instantiation and will not be changed by
* subsequent property changes.
* All properties, if set, should be absolute paths.
*
* Name Property Method Files
* ----- -------- ----- -----
* Base i2p.dir.base getBaseDir() lib/, webapps/, docs/, geoip/, licenses/, ...
* Temp i2p.dir.temp getTempDir() Temporary files
* Config i2p.dir.config getConfigDir() *.config, hosts.txt, addressbook/, ...
*
* (the following all default to the same as Config)
*
* Router i2p.dir.router getRouterDir() netDb/, peerProfiles/, router.*, keyBackup/, ...
* Log i2p.dir.log getLogDir() wrapper.log*, logs/
* PID i2p.dir.pid getPIDDir() wrapper *.pid files, router.ping
* App i2p.dir.app getAppDir() eepsite/, ...
*
* Note that we can't control where the wrapper actually puts its files.
All these will be set appropriately in a Router Context.
In an I2P App Context, all except Temp will be the current working directory.
Lightly tested so far, needs much more testing.
2009-06-04 19:14:40 +00:00
|
|
|
if (_tempFile.exists()) {
|
|
|
|
boolean copied = FileUtil.copy(_tempFile.getAbsolutePath(), _newsFile.getAbsolutePath(), true);
|
2005-04-01 13:29:26 +00:00
|
|
|
if (copied) {
|
2008-11-02 21:37:28 +00:00
|
|
|
_lastUpdated = now;
|
Big directory rework.
Eliminate all uses of the current working directory, and
set up multiple directories specified by absolute paths for various uses.
Add a WorkingDir class to create a user config directory and
migrate files to it for new installs.
The directory will be $HOME/.i2p on linux and %APPDIR%\I2P on Windows,
or as specified in the system property -Di2p.dir.config=/path/to/i2pdir
All files except for the base install and temp files will be
in the config directory by default.
Temp files will be in a i2p-xxxxx subdirectory of the system temp directory
specified by the system property java.io.tmpdir.
Convert all file opens in the code to be relative to a specific directory,
as specified in the context. Code and applications should never open
files relative to the current working directory (e.g. new File("foo")).
All files should be accessed in the appropriate context directory,
e.g. new File(_context.getAppDir(), "foo").
The router.config file location may be specified as a system property on the
java command line with -Drouter.configLocation=/path/to/router.config
All directories may be specified as properties in the router.config file.
The migration will copy all files from an existing installation,
except i2psnark/, with the system property -Di2p.dir.migrate=true.
Otherwise it will just set up a new directory with a minimal configuration.
The migration will also create a modified wrapper.config and (on linux only)
a modified i2prouter script, and place them in the config directory.
There are no changes to the installer or the default i2prouter, i2prouter.bat,
i2prouter, wrapper.config, runplain.sh, windows service installer/uninstaller,
etc. in this checkin.
* Directories. These are all set at instantiation and will not be changed by
* subsequent property changes.
* All properties, if set, should be absolute paths.
*
* Name Property Method Files
* ----- -------- ----- -----
* Base i2p.dir.base getBaseDir() lib/, webapps/, docs/, geoip/, licenses/, ...
* Temp i2p.dir.temp getTempDir() Temporary files
* Config i2p.dir.config getConfigDir() *.config, hosts.txt, addressbook/, ...
*
* (the following all default to the same as Config)
*
* Router i2p.dir.router getRouterDir() netDb/, peerProfiles/, router.*, keyBackup/, ...
* Log i2p.dir.log getLogDir() wrapper.log*, logs/
* PID i2p.dir.pid getPIDDir() wrapper *.pid files, router.ping
* App i2p.dir.app getAppDir() eepsite/, ...
*
* Note that we can't control where the wrapper actually puts its files.
All these will be set appropriately in a Router Context.
In an I2P App Context, all except Temp will be the current working directory.
Lightly tested so far, needs much more testing.
2009-06-04 19:14:40 +00:00
|
|
|
_tempFile.delete();
|
2008-03-22 17:10:49 +00:00
|
|
|
checkForUpdates();
|
2005-04-01 13:29:26 +00:00
|
|
|
} else {
|
|
|
|
if (_log.shouldLog(Log.ERROR))
|
|
|
|
_log.error("Failed to copy the news file!");
|
|
|
|
}
|
|
|
|
} else {
|
2008-01-09 04:11:12 +00:00
|
|
|
if (_log.shouldLog(Log.WARN))
|
|
|
|
_log.warn("Transfer complete, but no file? - probably 304 Not Modified");
|
2005-03-30 00:07:36 +00:00
|
|
|
}
|
2008-11-02 21:37:28 +00:00
|
|
|
_lastFetch = now;
|
2010-11-19 18:34:00 +00:00
|
|
|
if (_context.isRouterContext()) {
|
|
|
|
((RouterContext)_context).router().setConfigSetting(PROP_LAST_CHECKED, "" + now);
|
|
|
|
((RouterContext)_context).router().saveConfig();
|
|
|
|
}
|
2005-03-24 01:19:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void transferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt) {
|
2008-01-31 19:56:00 +00:00
|
|
|
if (_log.shouldLog(Log.WARN))
|
|
|
|
_log.warn("Failed to fetch the news from " + url);
|
Big directory rework.
Eliminate all uses of the current working directory, and
set up multiple directories specified by absolute paths for various uses.
Add a WorkingDir class to create a user config directory and
migrate files to it for new installs.
The directory will be $HOME/.i2p on linux and %APPDIR%\I2P on Windows,
or as specified in the system property -Di2p.dir.config=/path/to/i2pdir
All files except for the base install and temp files will be
in the config directory by default.
Temp files will be in a i2p-xxxxx subdirectory of the system temp directory
specified by the system property java.io.tmpdir.
Convert all file opens in the code to be relative to a specific directory,
as specified in the context. Code and applications should never open
files relative to the current working directory (e.g. new File("foo")).
All files should be accessed in the appropriate context directory,
e.g. new File(_context.getAppDir(), "foo").
The router.config file location may be specified as a system property on the
java command line with -Drouter.configLocation=/path/to/router.config
All directories may be specified as properties in the router.config file.
The migration will copy all files from an existing installation,
except i2psnark/, with the system property -Di2p.dir.migrate=true.
Otherwise it will just set up a new directory with a minimal configuration.
The migration will also create a modified wrapper.config and (on linux only)
a modified i2prouter script, and place them in the config directory.
There are no changes to the installer or the default i2prouter, i2prouter.bat,
i2prouter, wrapper.config, runplain.sh, windows service installer/uninstaller,
etc. in this checkin.
* Directories. These are all set at instantiation and will not be changed by
* subsequent property changes.
* All properties, if set, should be absolute paths.
*
* Name Property Method Files
* ----- -------- ----- -----
* Base i2p.dir.base getBaseDir() lib/, webapps/, docs/, geoip/, licenses/, ...
* Temp i2p.dir.temp getTempDir() Temporary files
* Config i2p.dir.config getConfigDir() *.config, hosts.txt, addressbook/, ...
*
* (the following all default to the same as Config)
*
* Router i2p.dir.router getRouterDir() netDb/, peerProfiles/, router.*, keyBackup/, ...
* Log i2p.dir.log getLogDir() wrapper.log*, logs/
* PID i2p.dir.pid getPIDDir() wrapper *.pid files, router.ping
* App i2p.dir.app getAppDir() eepsite/, ...
*
* Note that we can't control where the wrapper actually puts its files.
All these will be set appropriately in a Router Context.
In an I2P App Context, all except Temp will be the current working directory.
Lightly tested so far, needs much more testing.
2009-06-04 19:14:40 +00:00
|
|
|
_tempFile.delete();
|
2005-03-24 01:19:52 +00:00
|
|
|
}
|
2005-09-05 19:27:08 +00:00
|
|
|
public void headerReceived(String url, int attemptNum, String key, String val) {}
|
2007-09-08 02:24:01 +00:00
|
|
|
public void attempting(String url) {}
|
2005-03-24 01:19:52 +00:00
|
|
|
}
|