Ejemplo n.º 1
0
  /** Send a search to the given peer */
  protected void sendSearch(RouterInfo router) {
    if (router.getIdentity().equals(getContext().router().getRouterInfo().getIdentity())) {
      // don't search ourselves
      if (_log.shouldLog(Log.ERROR))
        _log.error(getJobId() + ": Dont send search to ourselves - why did we try?");
      return;
    } else {
      if (_log.shouldLog(Log.INFO))
        _log.info(
            getJobId()
                + ": Send search to "
                + router.getIdentity().getHash().toBase64()
                + " for "
                + _state.getTarget().toBase64()
                + " w/ timeout "
                + getPerPeerTimeoutMs(router.getIdentity().calculateHash()));
    }

    getContext().statManager().addRateData("netDb.searchMessageCount", 1, 0);

    // if (_isLease || true) // always send searches out tunnels
    sendLeaseSearch(router);
    // else
    //    sendRouterSearch(router);
  }
Ejemplo n.º 2
0
 /**
  * Allow the choice as to whether failed searches should count against the peer (such as if we
  * search for a random key)
  */
 public FailedJob(RouterContext enclosingContext, RouterInfo peer, boolean penalizePeer) {
   super(enclosingContext);
   _penalizePeer = penalizePeer;
   _peer = peer.getIdentity().getHash();
   _sentOn = enclosingContext.clock().now();
   _isFloodfill = FloodfillNetworkDatabaseFacade.isFloodfill(peer);
 }
Ejemplo n.º 3
0
 @Override
 public String toString() {
   StringBuilder buf = new StringBuilder(256);
   buf.append("[OutNetMessage containing ");
   if (_message == null) {
     buf.append("*no message*");
   } else {
     buf.append("a ").append(_messageSize).append(" byte ");
     buf.append(getMessageType());
   }
   buf.append(" expiring on ").append(new Date(_expiration));
   if (_failedTransports != null)
     buf.append(" failed delivery on transports ").append(_failedTransports);
   if (_target == null) buf.append(" targetting no one in particular...");
   else buf.append(" targetting ").append(_target.getIdentity().getHash().toBase64());
   if (_onReply != null) buf.append(" with onReply job: ").append(_onReply);
   if (_onSend != null) buf.append(" with onSend job: ").append(_onSend);
   if (_onFailedReply != null) buf.append(" with onFailedReply job: ").append(_onFailedReply);
   if (_onFailedSend != null) buf.append(" with onFailedSend job: ").append(_onFailedSend);
   if (_timestamps != null && _timestampOrder != null && _log.shouldLog(Log.INFO)) {
     buf.append(" {timestamps: \n");
     renderTimestamps(buf);
     buf.append("}");
   }
   buf.append("]");
   return buf.toString();
 }
Ejemplo n.º 4
0
  /**
   * we're (probably) searching for a LeaseSet, so to be (overly) cautious, we're sending the
   * request out through a tunnel w/ reply back through another tunnel.
   */
  protected void sendLeaseSearch(RouterInfo router) {
    Hash to = router.getIdentity().getHash();
    TunnelInfo inTunnel = getContext().tunnelManager().selectInboundExploratoryTunnel(to);
    if (inTunnel == null) {
      _log.warn("No tunnels to get search replies through!  wtf!");
      getContext().jobQueue().addJob(new FailedJob(getContext(), router));
      return;
    }
    TunnelId inTunnelId = inTunnel.getReceiveTunnelId(0);

    // this will fail if we've shitlisted our inbound gateway, but the gw may not necessarily
    // be shitlisted by whomever needs to contact them, so we don't need to check this

    // RouterInfo inGateway = getContext().netDb().lookupRouterInfoLocally(inTunnel.getPeer(0));
    // if (inGateway == null) {
    //    _log.error("We can't find the gateway to our inbound tunnel?! wtf");
    //    getContext().jobQueue().addJob(new FailedJob(getContext(), router));
    //    return;
    // }

    int timeout = getPerPeerTimeoutMs(to);
    long expiration = getContext().clock().now() + timeout;

    DatabaseLookupMessage msg = buildMessage(inTunnelId, inTunnel.getPeer(0), expiration);

    TunnelInfo outTunnel = getContext().tunnelManager().selectOutboundExploratoryTunnel(to);
    if (outTunnel == null) {
      _log.warn("No tunnels to send search out through!  wtf!");
      getContext().jobQueue().addJob(new FailedJob(getContext(), router));
      return;
    }
    TunnelId outTunnelId = outTunnel.getSendTunnelId(0);

    if (_log.shouldLog(Log.DEBUG))
      _log.debug(
          getJobId()
              + ": Sending search to "
              + to
              + " for "
              + msg.getSearchKey().toBase64()
              + " w/ replies through ["
              + msg.getFrom().toBase64()
              + "] via tunnel ["
              + msg.getReplyTunnel()
              + "]");

    SearchMessageSelector sel =
        new SearchMessageSelector(getContext(), router, _expiration, _state);
    SearchUpdateReplyFoundJob reply =
        new SearchUpdateReplyFoundJob(
            getContext(), router, _state, _facade, this, outTunnel, inTunnel);

    if (FloodfillNetworkDatabaseFacade.isFloodfill(router)) _floodfillSearchesOutstanding++;
    getContext()
        .messageRegistry()
        .registerPending(sel, reply, new FailedJob(getContext(), router), timeout);
    getContext().tunnelDispatcher().dispatchOutbound(msg, outTunnelId, to);
  }
 /**
  * Send our RI to the closest floodfill.
  *
  * @throws IllegalArgumentException if the local router info is invalid
  */
 @Override
 public void publish(RouterInfo localRouterInfo) throws IllegalArgumentException {
   if (localRouterInfo == null) throw new IllegalArgumentException("wtf, null localRouterInfo?");
   // should this be after super? why not publish locally?
   if (_context.router().isHidden()) return; // DE-nied!
   super.publish(localRouterInfo);
   // wait until we've read in the RI's so we can find the closest floodfill
   if (!isInitialized()) return;
   // no use sending if we have no addresses
   // (unless maybe we used to have addresses? not worth it
   if (localRouterInfo.getAddresses().isEmpty()) return;
   _log.info("Publishing our RI");
   // Don't delay, helps IB tunnel builds
   // if (_context.router().getUptime() > PUBLISH_JOB_DELAY)
   sendStore(
       localRouterInfo.getIdentity().calculateHash(),
       localRouterInfo,
       null,
       null,
       PUBLISH_TIMEOUT,
       null);
 }
Ejemplo n.º 6
0
  /**
   * Resend the leaseSet to the peer who had previously failed to provide us with the data when we
   * asked them.
   */
  private boolean resend(RouterInfo toPeer, LeaseSet ls) {
    Hash to = toPeer.getIdentity().getHash();
    DatabaseStoreMessage msg = new DatabaseStoreMessage(getContext());
    msg.setEntry(ls);
    msg.setMessageExpiration(getContext().clock().now() + RESEND_TIMEOUT);

    TunnelInfo outTunnel = getContext().tunnelManager().selectOutboundExploratoryTunnel(to);

    if (outTunnel != null) {
      TunnelId targetTunnelId = null; // not needed
      Job onSend = null; // not wanted

      if (_log.shouldLog(Log.DEBUG))
        _log.debug("resending leaseSet out to " + to + " through " + outTunnel + ": " + msg);
      getContext().tunnelDispatcher().dispatchOutbound(msg, outTunnel.getSendTunnelId(0), null, to);
      return true;
    } else {
      if (_log.shouldLog(Log.WARN))
        _log.warn("unable to resend a leaseSet - no outbound exploratory tunnels!");
      return false;
    }
  }
Ejemplo n.º 7
0
 /**
  * Convenience method for getting the router hash. Equivalent to
  * context.router().getRouterInfo().getIdentity().getHash()
  *
  * @return may be null if called very early
  */
 public Hash routerHash() {
   if (_router == null) return null;
   RouterInfo ri = _router.getRouterInfo();
   if (ri == null) return null;
   return ri.getIdentity().getHash();
 }