Ejemplo n.º 1
0
  /**
   * Handles a query reply locally.
   *
   * @param address can be null, if not null overrides the address info in <code>reply</code>
   */
  public void handleQueryReply(QueryReply reply, ReplyHandler handler, Address address) {
    // do not allow a faked multicast reply.
    if (reply.isFakeMulticast()) {
      return;
    }

    // Drop if it's a reply to mcast and conditions aren't met ...
    if (reply.isReplyToMulticastQuery()) {
      if (reply.isTCP()) return; // shouldn't be on TCP.
      if (reply.getHops() != 1 || reply.getTTL() != 0) return; // should only have hopped once.
    }

    // XML must be added to the response first, so that
    // whomever calls toRemoteFileDesc on the response
    // will create the cachedRFD with the correct XML.
    boolean validResponses = addXMLToResponses(reply, limeXMLDocumentHelper);
    // responses invalid?  exit.
    if (!validResponses) {
      return;
    }

    // check for unwanted results after xml has been constructed
    if (handler != null && handler.isPersonalSpam(reply)) {
      return;
    }

    if (reply.hasSecureData() && ApplicationSettings.USE_SECURE_RESULTS.getValue()) {
      secureMessageVerifier.verify(reply, this);
    } else {
      routeQueryReplyInternal(reply, address);
    }
  }
Ejemplo n.º 2
0
  /**
   * If there are problems with the request, just ignore it. There's no point in sending them a GIV
   * to have them send a GET just to return a 404 or Busy or Malformed Request, etc..
   */
  public void handlePushRequest(PushRequest pushRequest, ReplyHandler handler) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("push: " + pushRequest + "\nfrom: " + handler);
    }

    // Ignore push request from banned hosts.
    if (handler.isPersonalSpam(pushRequest)) {
      LOG.debug("discarded as personal spam");
      return;
    }

    byte[] ip = pushRequest.getIP();
    String host = NetworkUtils.ip2string(ip);

    // check whether we serviced this push request already
    GUID guid = new GUID(pushRequest.getGUID());
    if (GUID_REQUESTS.put(guid, guid) != null) {
      LOG.debug("already serviced");
      return;
    }

    // make sure the guy isn't hammering us
    AtomicInteger i = PUSH_REQUESTS.get(host);
    if (i == null) {
      i = new AtomicInteger(1);
      PUSH_REQUESTS.put(host, i);
    } else {
      i.addAndGet(1);
      // if we're over the max push requests for this host, exit.
      if (i.get() > UploadSettings.MAX_PUSHES_PER_HOST.getValue()) {
        LOG.debug("over max pushes per host");
        return;
      }
    }

    // if the IP is banned, don't accept it
    if (!ipFilterProvider.get().allow(ip)) {
      LOG.debug("blocked by ip filter");
      return;
    }

    int port = pushRequest.getPort();
    // if invalid port, exit
    if (!NetworkUtils.isValidAddressAndPort(host, port)) {
      LOG.debug("invalid host or port");
      return;
    }

    try {
      Connectable address = new ConnectableImpl(host, port, pushRequest.isTLSCapable());
      pushManager
          .get()
          .acceptPushUpload(
              address,
              new GUID(pushRequest.getClientGUID()),
              pushRequest.isMulticast(), // force accept
              pushRequest.isFirewallTransferPush());
    } catch (UnknownHostException e) {
      throw new RuntimeException(e);
    }
  }