private void initDirectory(boolean noLocalFileSystemAccess) throws IOException { // what to do, if no local files shall be touched if (noLocalFileSystemAccess) { dir = new Directory(this, privateKeyHandler.getIdentity()); return; } // load stable dir first // log.logDirectory(Logger.INFO,"Tor.initDirectory(): load stable dir"); // dir = new Directory(this,privateKeyHandler.getIdentity(), config.TOR_STABLE_DIR_FILENAME, // ""); // load cache-file over stable-dir long age = System.currentTimeMillis() - TorConfig.cacheMaxAgeSeconds * 1000L; File cacheFile = new File(TorConfig.getCacheFilename()); if (cacheFile.exists() && cacheFile.lastModified() >= age) { try { // TODO-FIXME-SECURITY-BUG-FIX: use fingerprint of dirServerKeys // dir.readDirectoryFromFile(config.getCacheFilename(), ""); dir = new Directory(this, privateKeyHandler.getIdentity(), TorConfig.getCacheFilename(), ""); } catch (Exception e) { Logger.logDirectory(Logger.WARNING, "Tor.initDirectory(): " + e.getMessage()); } } else { dir = new Directory(this, privateKeyHandler.getIdentity()); } /* uneccessary // check if in cache-file and/or stable-file have been some tor nodes if ((dir==null) || (dir.torServers==null) || (dir.torServers.size()<1)) throw new IOException("no Tor nodes found"); */ // update from network in the background // -> will be done by TorBackgroundMgmt! }
/** * shut down everything * * @param force set to true, if everything shall go fast. For graceful end, set to false */ public void close(boolean force) { Logger.logGeneral(Logger.INFO, "TorJava ist closing down"); // shutdown mgmt mgmt.close(); // shut down connections fnh.close(force); // shutdown/save directory dir.close(TorConfig.getCacheFilename()); // write config file config.close(); // close hidden services // TODO close hidden services, once they are implemented and work // kill logger Logger.logGeneral(Logger.INFO, "Tor.close(): CLOSED"); log.close(); }
public void reloadConfig() { if (config != null) config.reload(); }