/** * Negative cache the hash until restart, * but cache the destination. * * @since 0.9.16 */ public void failPermanently(Destination dest) { Hash h = dest.calculateHash(); synchronized(badDests) { badDests.put(h, dest); } }
/** * This can come in later but the hash must match. * @throws IllegalArgumentException if hash of dest doesn't match previous hash */ public void setDestination(Destination dest) throws IllegalArgumentException { if (this.dest != null) return; if (!dest.calculateHash().equals(this.hash)) throw new IllegalArgumentException("Hash mismatch, was: " + this.hash + " new: " + dest.calculateHash()); this.dest = dest; }
@Override public String toString() { StringBuilder buf = new StringBuilder(); if (_dest != null) buf.append(_dest.calculateHash().toString()); else buf.append(_host); buf.append(':'); buf.append(_port); return buf.toString(); }
/** * @param options ignored * @since 0.9.26 */ @Override public List<String> reverseLookupAll(Destination d, Properties options) { return reverseLookupAll(d.calculateHash()); }
/** * With a fake NID used for pings */ public NodeInfo(Destination dest, int port) { super(); this.nID = KRPC.FAKE_NID; this.dest = dest; this.hash = dest.calculateHash(); this.port = port; initialize(); }
/** * @since 0.8.9 */ private static Integer getReverseKey(Destination dest) { return getReverseKey(dest.calculateHash()); }
/** * @param options ignored * @since 0.8.9 */ @Override public String reverseLookup(Destination d, Properties options) { return reverseLookup(d.calculateHash()); }
/** client */ public LeaseSetKeys getKeys(Destination dest) { return getKeys(dest.calculateHash()); }
@Override public String toString() { StringBuilder buf = new StringBuilder(32); buf.append("Session: "); if (_myDestination != null) buf.append(_myDestination.calculateHash().toBase64().substring(0, 4)); else buf.append("[null dest]"); buf.append(getPrefix()); return buf.toString(); } }
/** client */ public LeaseSetKeys unregisterKeys(Destination dest) { if (_log.shouldLog(Log.INFO)) _log.info("Unregistering keys for destination " + dest.calculateHash().toBase64()); return _leaseSetKeys.remove(dest.calculateHash()); }
/** * Pick an arbitrary inbound tunnel for any deliveryStatusMessage to come back in * */ private TunnelInfo selectInboundTunnel() { // Use tunnel EP closest to his hash, as a simple cache to minimize connections return getContext().tunnelManager().selectInboundTunnel(_from.calculateHash(), _to.calculateHash()); }
/** client */ public void registerKeys(Destination dest, SigningPrivateKey leaseRevocationPrivateKey, PrivateKey endpointDecryptionKey) { if (_log.shouldLog(Log.INFO)) _log.info("Registering keys for destination " + dest.calculateHash().toBase64()); LeaseSetKeys keys = new LeaseSetKeys(dest, leaseRevocationPrivateKey, endpointDecryptionKey); _leaseSetKeys.put(dest.calculateHash(), keys); }
public PeerID(byte[] id, Destination address) { this.id = id; this.address = address; this.port = TrackerClient.PORT; this.destHash = address.calculateHash().getData(); hash = calculateHash(); util = null; }
/** * Return the client's current config, or null if not connected * */ public SessionConfig getClientSessionConfig(Destination dest) { ClientConnectionRunner runner = getRunner(dest); if (runner != null) return runner.getConfig(dest.calculateHash()); else return null; }
/** * Use this if we have the full destination * @throws IllegalArgumentException */ public NodeInfo(NID nID, Destination dest, int port) { super(); this.nID = nID; this.dest = dest; this.hash = dest.calculateHash(); this.port = port; initialize(); verify(); }
/** * Pick an arbitrary outbound tunnel to send the message through, or null if * there aren't any around * * Rather than pick one at random, pick the "closest" to the lease, * to minimize network OBEP - IBGW connections? * This would also eliminate a connection when OBEP == IBGW. * Anonymity issues? */ private TunnelInfo selectOutboundTunnel() { // hurts reliability? let's try picking at random again //Hash gw = _lease.getGateway(); //return getContext().tunnelManager().selectOutboundTunnel(_from.calculateHash(), gw); return getContext().tunnelManager().selectOutboundTunnel(_from.calculateHash()); }
/** * May throw RuntimeException from underlying sinks * @throws RuntimeException */ public void send(Destination from, byte[] data) { Sink s = this.cache.get(from); if (s == null) { Log log = I2PAppContext.getGlobalContext().logManager().getLog(MultiSink.class); log.error("No where to go for " + from.calculateHash().toBase64().substring(0, 6)); return; } s.send(from, data); }
/** * So LocalClientMessageEventListener can lookup other local dests */ public Destination localLookup(Hash h) { for (Destination d : _manager.getRunnerDestinations()) { if (d.calculateHash().equals(h)) return d; } return null; } }
public void unpublish(LeaseSet localLeaseSet) { if (!_initialized) return; Hash h = localLeaseSet.getDestination().calculateHash(); DatabaseEntry data = _ds.remove(h); if (data == null) { if (_log.shouldLog(Log.WARN)) _log.warn("Unpublished a lease we don't know...: " + localLeaseSet); } else { if (_log.shouldLog(Log.INFO)) _log.info("Unpublished a lease: " + h); } // now update it if we can to remove any leases }
@Test public void testToString() throws Exception { Destination dest = I2PClientFactory.createClient().createDestination(new ByteArrayOutputStream()); I2PSocketAddress addr = new I2PSocketAddress(dest, 1234); assertThat(addr.toString(), is(equalTo(dest.calculateHash().toString() + ":1234"))); }