示例#1
0
文件: SearchJob.java 项目: hilbix/i2p
  /**
   * 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);
  }
示例#2
0
文件: SearchJob.java 项目: hilbix/i2p
 /**
  * Build the database search message
  *
  * @param replyTunnelId tunnel to receive replies through
  * @param replyGateway gateway for the reply tunnel
  * @param expiration when the search should stop
  */
 protected DatabaseLookupMessage buildMessage(
     TunnelId replyTunnelId, Hash replyGateway, long expiration) {
   DatabaseLookupMessage msg = new DatabaseLookupMessage(getContext(), true);
   msg.setSearchKey(_state.getTarget());
   // msg.setFrom(replyGateway.getIdentity().getHash());
   msg.setFrom(replyGateway);
   msg.setDontIncludePeers(_state.getClosestAttempted(MAX_CLOSEST));
   msg.setMessageExpiration(expiration);
   msg.setReplyTunnel(replyTunnelId);
   return msg;
 }