@Override public boolean equals(Object obj) { if (obj == null || !(obj instanceof PeerProfile)) return false; PeerProfile prof = (PeerProfile)obj; return _peer.equals(prof._peer); }
/** * Called by the message handler * on reception of DestReplyMessage * @param h non-null */ void destLookupFailed(Hash h) { for (LookupWaiter w : _pendingLookups) { if (h.equals(w.hash)) { synchronized (w) { w.notifyAll(); } } } }
public boolean isMatch(I2NPMessage message) { if (message instanceof DatabaseStoreMessage) { DatabaseStoreMessage dsm = (DatabaseStoreMessage)message; return _key.equals(dsm.getKey()); } else if (message instanceof DatabaseSearchReplyMessage) { DatabaseSearchReplyMessage dsrm = (DatabaseSearchReplyMessage)message; return _key.equals(dsrm.getSearchKey()); } return false; } }
@Override public boolean equals(Object o) { try { NodeInfo ni = (NodeInfo) o; // assume dest matches, ignore it return this.hash.equals(ni.hash) && nID.equals(ni.nID) && port == ni.port; } catch (RuntimeException e) { return false; } }
@Override public boolean equals(Object obj) { if (obj == null || !(obj instanceof ReplyTunnel)) return false; return this.h.equals(((ReplyTunnel)obj).h) && this.id.equals(((ReplyTunnel)obj).id); }
/** * 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; }
public void tunnelDataPushed1m(Hash peer, int size) { if (_context.routerHash().equals(peer)) return; PeerProfile data = getProfile(peer); //if (data != null) data.dataPushed1m(size); }
public void tunnelLifetimePushed(Hash peer, long lifetime, long size) { if (_context.routerHash().equals(peer)) return; PeerProfile data = getProfile(peer); //if (data != null) data.tunnelDataTransferred(size); }
public void tunnelDataPushed(Hash peer, long rtt, int size) { if (_context.routerHash().equals(peer)) return; PeerProfile data = getProfile(peer); //if (data != null) data.dataPushed(size); // ignore rtt, as we are averaging over a minute }
/** * Retrieve the profile for the given peer, if one exists (else null). * Blocking if a reorganize is happening. */ public PeerProfile getProfile(Hash peer) { if (peer.equals(_us)) { if (_log.shouldWarn()) _log.warn("Who wanted our own profile?", new Exception("I did")); return null; } getReadLock(); try { return locked_getProfile(peer); } finally { releaseReadLock(); } }
/** * @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()); }
/** * Retrieve the profile for the given peer, if one exists (else null). * Non-blocking. Returns null if a reorganize is happening. * @since 0.8.12 */ public PeerProfile getProfileNonblocking(Hash peer) { if (peer.equals(_us)) { if (_log.shouldWarn()) _log.warn("Who wanted our own profile?", new Exception("I did")); return null; } if (tryReadLock()) { try { return locked_getProfile(peer); } finally { releaseReadLock(); } } return null; }
/** * 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; } }
/** * Fail all (outbound) tunnels with this peer as first hop (not counting us) * * @since 0.8.13 */ private void failTunnelsWithFirstHop(TunnelPool pool, Hash peer) { for (TunnelInfo tun : pool.listTunnels()) { int len = tun.getLength(); if (len > 1 && tun.getPeer(1).equals(peer)) { if (_log.shouldLog(Log.WARN)) _log.warn("Removing OB tunnel, first hop banlisted: " + tun); pool.tunnelFailed(tun, peer); } } }
@Override public boolean equals(Object o) { if (o == null) return false; if (o.getClass() != Tunnel.class) return false; Tunnel t = (Tunnel)o; return (getTunnel() == t.getTunnel()) && getGateway().equals(t.getGateway()); } }
/** * Fail all (inbound) tunnels with this peer as last hop (not counting us) * * @since 0.8.13 */ private void failTunnelsWithLastHop(TunnelPool pool, Hash peer) { for (TunnelInfo tun : pool.listTunnels()) { int len = tun.getLength(); if (len > 1 && tun.getPeer(len - 2).equals(peer)) { if (_log.shouldLog(Log.WARN)) _log.warn("Removing IB tunnel, prev. hop banlisted: " + tun); pool.tunnelFailed(tun, peer); } } } }
private void addRandom(int count) { for (int i = 0; i < count; i++) { byte val[] = new byte[Hash.HASH_LENGTH]; context.random().nextBytes(val); Hash h = new Hash(val); // in the highly unlikely chance we randomly generate a hash equal to us assertTrue(set.add(h) || h.equals(usHash)); } }
public void runJob() { Hash from = _dsrm.getFromHash(); int limit = Math.min(_dsrm.getNumReplies(), MAX_TO_FOLLOW); for (int i = 0; i < limit; i++) { Hash peer = _dsrm.getReply(i); if (peer.equals(getContext().routerHash())) // us continue; if (peer.equals(from)) // unusual? continue; RouterInfo ri = getContext().netDb().lookupRouterInfoLocally(peer); if (ri == null) getContext().jobQueue().addJob(new SingleSearchJob(getContext(), peer, from)); else if (ri.getPublished() < getContext().clock().now() - 60*60*1000 || !FloodfillNetworkDatabaseFacade.isFloodfill(ri)) getContext().jobQueue().addJob(new SingleSearchJob(getContext(), peer, peer)); } }
private void sendData(Hash key, DatabaseEntry data, Hash toPeer, TunnelId replyTunnel) { if (!key.equals(data.getHash())) { _log.error("Hash mismatch HDLMJ"); return; } if (_log.shouldLog(Log.DEBUG)) _log.debug("Sending data matching key " + key + " to peer " + toPeer + " tunnel " + replyTunnel); DatabaseStoreMessage msg = new DatabaseStoreMessage(getContext()); if (data.isLeaseSet()) { getContext().statManager().addRateData("netDb.lookupsMatchedLeaseSet", 1); } msg.setEntry(data); getContext().statManager().addRateData("netDb.lookupsMatched", 1); getContext().statManager().addRateData("netDb.lookupsHandled", 1); sendMessage(msg, toPeer, replyTunnel); }