protected void removeRequest(PeerNATTraversal request, int outcome) {
    synchronized (initiators) {
      LinkedList requests = (LinkedList) initiators.get(request.getInitiator());

      if (requests != null) {

        requests.remove(request);
      }

      pending_requests.remove(request);

      if (active_requests.remove(request)) {

        usage_average.addValue(request.getTimeUsed());

        if (outcome == OUTCOME_SUCCESS) {

          success_count++;

        } else {

          InetSocketAddress target = request.getTarget();

          negative_result_bloom.add(target.toString().getBytes());

          if (outcome == OUTCOME_FAILED_NO_REND) {

            failed_no_rendezvous++;
          }
        }
      }
    }
  }
Exemplo n.º 2
0
  protected void findContacts() {
    DHTTransportContact[] reachables = dht.getTransport().getReachableContacts();

    for (int i = 0; i < reachables.length; i++) {

      DHTTransportContact contact = reachables[i];

      byte[] address = contact.getAddress().getAddress().getAddress();

      if (tried_bloom == null || tried_bloom.getEntryCount() > 500) {

        tried_bloom = BloomFilterFactory.createAddOnly(4096);
      }

      if (!tried_bloom.contains(address)) {

        tried_bloom.add(address);

        synchronized (pending_contacts) {
          potentialPing ping =
              new potentialPing(
                  contact,
                  DHTNetworkPositionManager.estimateRTT(
                      contact.getNetworkPositions(),
                      dht.getTransport().getLocalContact().getNetworkPositions()));

          pending_contacts.add(0, ping);

          if (pending_contacts.size() > 60) {

            pending_contacts.removeLast();
          }
        }
      }
    }
  }
  public void create(
      PeerNATInitiator initiator, InetSocketAddress target, PeerNATTraversalAdapter adapter) {
    boolean bad = false;

    synchronized (initiators) {
      if (negative_result_bloom.contains(target.toString().getBytes())) {

        bad = true;

        failed_negative_bloom++;

      } else {

        LinkedList requests = (LinkedList) initiators.get(initiator);

        if (requests == null) {

          // we get here when download stopped at same time
          // Debug.out( "initiator not found" );

          bad = true;

        } else {

          PeerNATTraversal traversal = new PeerNATTraversal(initiator, target, adapter);

          requests.addLast(traversal);

          pending_requests.addLast(traversal);

          if (Logger.isEnabled()) {
            Logger.log(
                new LogEvent(
                    LOGID,
                    "created NAT traversal for " + initiator.getDisplayName() + "/" + target));
          }
        }
      }
    }

    if (bad) {

      adapter.failed();
    }
  }