net.i2p.data.Hash.equals()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(203)

本文整理了Java中net.i2p.data.Hash.equals()方法的一些代码示例,展示了Hash.equals()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Hash.equals()方法的具体详情如下:
包路径:net.i2p.data.Hash
类名称:Hash
方法名:equals

Hash.equals介绍

暂无

代码示例

代码示例来源:origin: i2p/i2p.i2p

public boolean equals(Object o) {
    if (o == null || !(o instanceof HashPair))
      return false;
    HashPair hp = (HashPair) o;
    return sh.equals(hp.sh) && dh.equals(hp.dh);
  }
}

代码示例来源:origin: i2p/i2p.i2p

@Override
public boolean equals(Object obj) {
  if (obj == null ||
    !(obj instanceof PeerProfile))
    return false;
  PeerProfile prof = (PeerProfile)obj;
  return _peer.equals(prof._peer);
}

代码示例来源:origin: i2p/i2p.i2p

/**
 *  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();
      }
    }
  }
}

代码示例来源:origin: i2p/i2p.i2p

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;
  }
}

代码示例来源:origin: i2p/i2p.i2p

@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;
  }
}

代码示例来源:origin: i2p/i2p.i2p

@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);
}

代码示例来源:origin: i2p/i2p.i2p

/**
 * 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;
}

代码示例来源:origin: i2p/i2p.i2p

public void tunnelDataPushed1m(Hash peer, int size) {
  if (_context.routerHash().equals(peer))
    return;
  PeerProfile data = getProfile(peer);
  //if (data != null)
    data.dataPushed1m(size);
}

代码示例来源:origin: i2p/i2p.i2p

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);
}

代码示例来源:origin: i2p/i2p.i2p

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
}

代码示例来源:origin: i2p/i2p.i2p

/**
 * 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(); }
}

代码示例来源:origin: i2p/i2p.i2p

/**
 * @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());
}

代码示例来源:origin: i2p/i2p.i2p

/**
 * 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;
}

代码示例来源:origin: i2p/i2p.i2p

/**
   *  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;
  }
}

代码示例来源:origin: i2p/i2p.i2p

/**
 *  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);
    }
  }
}

代码示例来源:origin: i2p/i2p.i2p

@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());
  }
}

代码示例来源:origin: i2p/i2p.i2p

/**
   *  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);
      }
    }
  }
}

代码示例来源:origin: i2p/i2p.i2p

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));
  }
}

代码示例来源:origin: i2p/i2p.i2p

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));
  }
}

代码示例来源:origin: i2p/i2p.i2p

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);
}

相关文章