/** * BEP 6 * Ignored for now * @since 0.9.21 */ void allowedFastMessage(int piece) { if (_log.shouldInfo()) _log.info("Ignoring allowed_fast(" + piece + ") from " + peer); }
/** * Handlers must call on stop * @since 0.9.20 */ public void unregister(Handler handler) { if (_log.shouldInfo()) _log.info("Unregister " + handler); synchronized (_handlers) { _handlers.remove(handler); } }
/** * Handlers must call on startup * @since 0.9.20 */ public void register(Handler handler) { if (_log.shouldInfo()) _log.info("Register " + handler); synchronized (_handlers) { _handlers.add(handler); } }
@Override public void pingReceived(String data) { if (_log.shouldInfo()) _log.info("Got PING " + data + ", sending PONG " + data); synchronized (_out) { try { _out.write(("PONG " + data + '\n').getBytes("UTF-8")); _out.flush(); } catch (IOException ioe) { _log.error("PONG fail", ioe); } } }
protected void changeState(State state) { if (_log.shouldInfo()) _log.info(getPrefix() + "Change state to " + state); synchronized (_stateLock) { _state = state; _stateLock.notifyAll(); } }
/** * Stop all the handlers. * @since 0.9.20 */ private void stopHandlers() { List<Handler> handlers = null; synchronized (_handlers) { if (!_handlers.isEmpty()) { handlers = new ArrayList<Handler>(_handlers); _handlers.clear(); } } if (handlers != null) { for (Handler handler : handlers) { if (_log.shouldInfo()) _log.info("Stopping " + handler); handler.stopHandling(); } } }
public void gotTermination(int reason, long lastReceived) { if (_log.shouldInfo()) _log.info("Got Termination: " + reason + " total rcvd: " + lastReceived + " on " + NTCPConnection.this); // close() calls destroy() sets _terminated close(); }
/** * BEP 6 * Treated as "have" for now * @since 0.9.21 */ void suggestMessage(int piece) { if (_log.shouldInfo()) _log.info("Handling suggest as have(" + piece + ") from " + peer); haveMessage(piece); }
public void destroy() { if (_log.shouldInfo()) _log.info("NTCP2 read state destroy() on " + NTCPConnection.this, new Exception("I did it")); if (_dataBuf != null && _dataBuf.getData().length == BUFFER_SIZE) releaseReadBuf(_dataBuf); _dataBuf = null; _rcvr.destroy(); _terminated = true; }
/** * Stop the SAM handler, close the client socket, * unregister with the bridge. */ public void stopHandling() { if (_log.shouldInfo()) _log.info("Stopping: " + this, new Exception("I did it")); synchronized (stopLock) { stopHandler = true; } try { closeClientSocket(); } catch (IOException e) {} bridge.unregister(this); }
/** * @since 0.9.23 */ private void locked_saveTorrentStatus(byte[] ih, Properties config) { File conf = configFile(_configDir, ih); File subdir = conf.getParentFile(); if (!subdir.exists()) subdir.mkdirs(); try { DataHelper.storeProps(config, conf); if (_log.shouldInfo()) _log.info("Saved config to " + conf); } catch (IOException ioe) { _log.error("Unable to save the config to " + conf); } }
/** * Store the current keys to disk in the location specified on creation. */ private void storeKeys() { synchronized (nameToPrivKeys) { File file = new File(persistFilename); // now in config dir but check base dir too... if (!file.exists() && !file.isAbsolute()) file = new File(I2PAppContext.getGlobalContext().getConfigDir(), persistFilename); try { Properties props = new OrderedProperties(); props.putAll(nameToPrivKeys); DataHelper.storeProps(props, file); if (_log.shouldInfo()) _log.info("Saved " + nameToPrivKeys.size() + " private keys to " + file); } catch (IOException ioe) { _log.error("Error writing out the SAM keys to " + file, ioe); } } }
public synchronized void setActive(boolean active) { // FIXME active=false this only kills for one thread in accept() // if there are more, they won't get a poison packet. if (_log.shouldInfo()) _log.info("setActive(" + active + ") called, previously " + _active, new Exception("I did it")); // if starting, clear any old poison if (active && !_active) { _restartPending = false; _synQueue.clear(); } boolean wasActive = _active; _active = active; if (wasActive && !active) { // stopping, clear any pending sockets _synQueue.clear(); _synQueue.offer(new PoisonPacket()); } }
/** * Stop the SAM handler, close the socket, * unregister with the bridge. * * Overridden to not close the client socket if stolen. * * @since 0.9.20 */ @Override public void stopHandling() { if (_log.shouldInfo()) _log.info("Stopping (stolen? " + stolenSocket + "): " + this, new Exception("I did it")); synchronized (stopLock) { stopHandler = true; } if (!stolenSocket) { try { closeClientSocket(); } catch (IOException e) {} } bridge.unregister(this); }
/** * Remove and add to peersByRemoteHost map * @since 0.9.3 */ void changePeerPort(PeerState peer, int newPort) { // this happens a lot int oldPort; synchronized (_addDropLock) { oldPort = peer.getRemotePort(); if (oldPort != newPort) { _peersByRemoteHost.remove(peer.getRemoteHostId()); peer.changePort(newPort); _peersByRemoteHost.put(peer.getRemoteHostId(), peer); } } if (_log.shouldInfo() && oldPort != newPort) _log.info("Changed port from " + oldPort + " to " + newPort + " for " + peer); }
/** * Remove the status of a torrent by removing the config file. */ private void removeTorrentStatus(Snark snark) { byte[] ih = snark.getInfoHash(); File conf = configFile(_configDir, ih); File comm = commentFile(_configDir, ih); synchronized (_configLock) { comm.delete(); boolean ok = conf.delete(); if (ok) { if (_log.shouldInfo()) _log.info("Deleted " + conf + " for " + snark.getName()); } else { if (_log.shouldWarn()) _log.warn("Failed to delete " + conf + " for " + snark.getName()); } File subdir = conf.getParentFile(); String[] files = subdir.list(); if (files != null && files.length == 0) subdir.delete(); } }
/** * Lookup using the client's tunnels * Succeeds even if LS validation and store fails due to unsupported sig type, expired, etc. * * Note that there are not separate success and fail jobs. Caller must call * lookupDestinationLocally() in the job to determine success. * * @param onFinishedJob non-null * @param fromLocalDest use these tunnels for the lookup, or null for exploratory * @since 0.9.16 */ public void lookupDestination(Hash key, Job onFinishedJob, long timeoutMs, Hash fromLocalDest) { if (!_initialized) return; Destination d = lookupDestinationLocally(key); if (d != null) { _context.jobQueue().addJob(onFinishedJob); } else if (isNegativeCached(key)) { if (_log.shouldInfo()) _log.info("Negative cached, not searching dest: " + key); } else { search(key, onFinishedJob, onFinishedJob, timeoutMs, true, fromLocalDest); } }
public void gotRI(RouterInfo ri, boolean isHandshake, boolean flood) throws DataFormatException { if (_log.shouldDebug()) _log.debug("Got updated RI"); _messagesRead.incrementAndGet(); try { Hash h = ri.getHash(); RouterInfo old = _context.netDb().store(h, ri); if (flood && !ri.equals(old)) { FloodfillNetworkDatabaseFacade fndf = (FloodfillNetworkDatabaseFacade) _context.netDb(); if (fndf.floodConditional(ri)) { if (_log.shouldDebug()) _log.debug("Flooded the RI: " + h); } else { if (_log.shouldInfo()) _log.info("Flood request but we didn't: " + h); } } } catch (IllegalArgumentException iae) { throw new DataFormatException("RI store fail: " + ri, iae); } }
public synchronized void receiveSessionRequest(UDPPacketReader.SessionRequestReader req) { if (_receivedX == null) _receivedX = new byte[UDPPacketReader.SessionRequestReader.X_LENGTH]; req.readX(_receivedX, 0); if (_bobIP == null) _bobIP = new byte[req.readIPSize()]; req.readIP(_bobIP, 0); byte[] ext = req.readExtendedOptions(); if (ext != null && ext.length >= UDPPacket.SESS_REQ_MIN_EXT_OPTIONS_LENGTH) { _introductionRequested = (ext[1] & (byte) UDPPacket.SESS_REQ_EXT_FLAG_REQUEST_RELAY_TAG) != 0; if (_log.shouldInfo()) _log.info("got sess req. w/ ext. options, need intro? " + _introductionRequested + ' ' + this); } if (_log.shouldLog(Log.DEBUG)) _log.debug("Receive sessionRequest, BobIP = " + Addresses.toString(_bobIP)); if (_currentState == InboundState.IB_STATE_UNKNOWN) _currentState = InboundState.IB_STATE_REQUEST_RECEIVED; packetReceived(); }
public void lookupRouterInfo(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs) { if (!_initialized) return; RouterInfo ri = lookupRouterInfoLocally(key); if (ri != null) { if (onFindJob != null) _context.jobQueue().addJob(onFindJob); } else if (_context.banlist().isBanlistedForever(key)) { if (onFailedLookupJob != null) _context.jobQueue().addJob(onFailedLookupJob); } else if (isNegativeCached(key)) { if (_log.shouldInfo()) _log.info("Negative cached, not searching RI: " + key); } else { search(key, onFindJob, onFailedLookupJob, timeoutMs, false); } }