/** @return the configured NamingService, or the root NamingService */ private static NamingService getNamingService(String srch) { NamingService root = I2PAppContext.getGlobalContext().namingService(); NamingService rv = searchNamingService(root, srch); return rv != null ? rv : root; }
/** * Warning - not recommended. * Use I2PAppContext.getGlobalContext().logManager().getLog(cls) */ public Log(Class<?> cls) { this(I2PAppContext.getGlobalContext().logManager(), cls, null); _manager.addLog(this); }
/** * Singleton for whatever PRNG i2p uses. * Same as I2PAppContext.getGlobalContext().random(); * use context.random() if you have a context already. * @return I2PAppContext.getGlobalContext().random() */ public static RandomSource getInstance() { return I2PAppContext.getGlobalContext().random(); }
/** * Save memory by not creating stats unless they are required for router operation. * For backward compatibility of any external clients, always returns false if not in router context. * * @param statName ignored * @return true if the stat should be ignored. */ public boolean ignoreStat(String statName) { return _context.isRouterContext() && !_context.getBooleanProperty(PROP_STAT_FULL); }
/** @since 0.8.2 */ static boolean canSetPerms() { if (!oneDotSix) return false; I2PAppContext ctx = I2PAppContext.getCurrentContext(); if (ctx == null) return true; return !ctx.getBooleanProperty("i2p.insecureFiles"); }
public void setUp(){ context = I2PAppContext.getGlobalContext(); log = context.logManager().getLog(KBucketSet.class); byte[] us = new byte[Hash.HASH_LENGTH]; context.random().nextBytes(us); usHash = new Hash(us); // We use the default RandomTrimmer so add() will never fail set = new KBucketSet<Hash>(context, usHash, K, B); // tests may be run in any order so prime it addRandom(1000); }
/** * Yes, the EepGet fetch() is done in here in next(). * * see java.util.Iterator#next() * @return non-null AddressBook (empty if the minimum delay has not been met, * or there is no proxy tunnel, or the fetch otherwise fails) */ public AddressBook next() { Subscription sub = this.subIterator.next(); if (sub.getLocation().startsWith("file:")) { // test only return new AddressBook(sub.getLocation().substring(5)); } else if (sub.getLastFetched() + this.delay < I2PAppContext.getGlobalContext().clock().now() && I2PAppContext.getGlobalContext().portMapper().getPort(PortMapper.SVC_HTTP_PROXY) >= 0 && !I2PAppContext.getGlobalContext().getBooleanProperty("i2p.vmCommSystem")) { //System.err.println("Fetching addressbook from " + sub.getLocation()); return new AddressBook(sub, this.proxyHost, this.proxyPort); } else { //System.err.println("Addressbook " + sub.getLocation() + " was last fetched " + // DataHelper.formatDuration(I2PAppContext.getGlobalContext().clock().now() - sub.getLastFetched()) + // " ago but the minimum delay is " + // DataHelper.formatDuration(this.delay)); return new AddressBook(Collections.<String, HostTxtEntry>emptyMap()); } }
public FragmentedMessage(I2PAppContext ctx, long messageId) { _context = ctx; _log = ctx.logManager().getLog(FragmentedMessage.class); _messageId = messageId; _fragments = new ByteArray[MAX_FRAGMENTS]; _highFragmentNum = -1; _releasedAfter = -1; _createdOn = ctx.clock().now(); }
public AsyncFortunaStandalone(I2PAppContext context) { super(); _bufferCount = Math.max(context.getProperty("prng.buffers", DEFAULT_BUFFERS), 2); _bufferSize = Math.max(context.getProperty("prng.bufferSize", DEFAULT_BUFSIZE), 16*1024); _emptyBuffers = new LinkedBlockingQueue<AsyncBuffer>(_bufferCount); _fullBuffers = new LinkedBlockingQueue<AsyncBuffer>(_bufferCount); _context = context; context.statManager().createRequiredRateStat("prng.bufferWaitTime", "Delay for random number buffer (ms)", "Encryption", new long[] { 60*1000, 10*60*1000, 60*60*1000 } ); context.statManager().createRequiredRateStat("prng.bufferFillTime", "Time to fill random number buffer (ms)", "Encryption", new long[] { 60*1000, 10*60*1000, 60*60*1000 } ); _log = context.logManager().getLog(AsyncFortunaStandalone.class); }
public I2CPMessageProducer(I2PAppContext context) { _context = context; _log = context.logManager().getLog(I2CPMessageProducer.class); _lock = new ReentrantLock(true); context.statManager().createRateStat("client.sendThrottled", "Times waited for bandwidth", "ClientMessages", new long[] { 60*1000 }); context.statManager().createRateStat("client.sendDropped", "Length of msg dropped waiting for bandwidth", "ClientMessages", new long[] { 60*1000 }); }
/** * */ public SU3File(File file) { this(I2PAppContext.getGlobalContext(), file); }
public void closed() { if (_closed) return; _closed = true; long lifetime = _context.clock().now() - _started; _context.statManager().addRateData("send." + _connectionId + ".lifetime", lifetime, lifetime); try { _in.close(); } catch (IOException ioe) {} }
/** * @param name b64 or b32 or host name * @since 0.9.11 */ private Destination lookup(String name) { I2PAppContext ctx = I2PAppContext.getGlobalContext(); boolean b32 = name.length() == 60 && name.toLowerCase(Locale.US).endsWith(".b32.i2p"); if (ctx.isRouterContext() && !b32) { // Local lookup. // Even though we could do b32 outside router ctx here, // we do it below instead so we can use the session, // which we can't do with lookup() Destination dest = ctx.namingService().lookup(name); if (dest != null || ctx.isRouterContext() || name.length() >= 516) return dest; } try { I2PSession sess = sockMgr.getSession(); return sess.lookupDest(name); } catch (I2PSessionException ise) { _log.error("Error looking up " + name, ise); return null; } } }
PeerCheckerTask(I2PSnarkUtil util, PeerCoordinator coordinator) { _util = util; _log = util.getContext().logManager().getLog(PeerCheckerTask.class); random = util.getContext().random(); this.coordinator = coordinator; }
/** Creates a new instance of ConnectionHandler */ public ConnectionHandler(I2PAppContext context, ConnectionManager mgr, SimpleTimer2 timer) { _context = context; _log = context.logManager().getLog(ConnectionHandler.class); _manager = mgr; _timer = timer; _synQueue = new LinkedBlockingQueue<Packet>(MAX_QUEUE_SIZE); _acceptTimeout = DEFAULT_ACCEPT_TIMEOUT; }
/** * @since 0.7.12 */ public boolean getBooleanPropertyDefaultTrue(String propName) { return getProperty(propName, true); }
/** * Replay resistant message Id */ public long getUniqueId() { // Lazy initialization of value if (_uniqueId < 0) { _uniqueId = _context.random().nextLong(MAX_ID_VALUE); } return _uniqueId; }
private ByteCache(int maxCachedEntries, int entrySize) { super(new ByteArrayFactory(entrySize), maxCachedEntries); _entrySize = entrySize; int stagger = SystemVersion.isAndroid() ? 0 : (entrySize % 777); SimpleTimer2.getInstance().addPeriodicEvent(new Cleanup(), CLEANUP_FREQUENCY + stagger); I2PAppContext.getGlobalContext().statManager().createRateStat("byteCache.memory." + entrySize, "Memory usage (B)", "Router", new long[] { 10*60*1000 }); }
/** * @throws IllegalStateException if not in RouterContext */ public boolean validateRoutingKey() { I2PAppContext ctx = I2PAppContext.getGlobalContext(); if (!ctx.isRouterContext()) throw new IllegalStateException("Not in router context"); RoutingKeyGenerator gen = ctx.routingKeyGenerator(); Hash destKey = getHash(); Hash rk = gen.getRoutingKey(destKey); return rk.equals(getRoutingKey()); }
boolean useKeytool = I2PAppContext.getGlobalContext().getBooleanProperty("crypto.useExternalKeytool"); if (useKeytool) { if (altNames != null)