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
 public void handlePingReply(PingReply pingReply, ReplyHandler handler) {
   // Kill incoming connections that don't share.  Note that we randomly
   // allow some freeloaders.  (Hopefully they'll get some stuff and then
   // share!)  Note that we only consider killing them on the first ping.
   // (Message 1 is their ping, message 2 is their reply to our ping.)
   if ((pingReply.getHops() <= 1)
       && (handler.getNumMessagesReceived() <= 2)
       && (!handler.isOutgoing())
       && (handler.isKillable())
       && (pingReply.getFiles() < SharingSettings.FREELOADER_FILES.getValue())
       && ((int) (Math.random() * 100.f) > SharingSettings.FREELOADER_ALLOWED.getValue())
       && (handler instanceof RoutedConnection)
       && (handler.isStable())) {
     connectionManager.get().remove((RoutedConnection) handler);
   }
 }
Ejemplo n.º 3
0
  @Override
  protected void handleReplyMessage(String correlationID, Message message) {
    ReplyHandler handler = correlation.get(correlationID);
    if (handler == null && endpoint.isUseMessageIDAsCorrelationID()) {
      handler = waitForProvisionCorrelationToBeUpdated(correlationID, message);
    }

    if (handler != null) {
      correlation.remove(correlationID);
      handler.onReply(correlationID, message);
    } else {
      // we could not correlate the received reply message to a matching request and therefore
      // we cannot continue routing the unknown message
      // log a warn and then ignore the message
      log.warn(
          "Reply received for unknown correlationID [{}]. The message will be ignored: {}",
          correlationID,
          message);
    }
  }
Ejemplo n.º 4
0
  public void print(PrintWriter _ps) {
    if (included && !generateIncluded()) return;

    // divert output into individual .java files
    if (body != null) // forward declaration
    {
      printInterface();

      if (!is_pseudo) {
        if (!is_abstract) {
          printOperations();
        }

        printHelper();
        printHolder();

        if (parser.generate_stubs && !is_local) {
          printStub();
        }

        if (parser.generate_skeletons && !is_local && !is_abstract) {
          printImplSkeleton();
          printTieSkeleton();
        }

        if (parser.generateIR) {
          printIRHelper();
        }

        if (is_local) {
          printLocalBase();
          printLocalTie();
        }
      }

      // print class files for interface local definitions
      body.print(null);

      if (replyHandler != null) replyHandler.print(_ps);
    }
  }
Ejemplo n.º 5
0
  public void parse() {
    boolean justAnotherOne = false;

    if (parsed) {
      // there are occasions where the compiler may try to parse
      // an Interface type spec for a second time, viz if it is
      // referred to through a scoped name in another struct member.
      // that's not a problem, but we have to skip parsing again!
      // Fixes bug #629, copied from fix for bug #84
      return;
    }

    escapeName();

    ConstrTypeSpec ctspec = new ConstrTypeSpec(new_num());

    if (is_abstract) {
      if (logger.isDebugEnabled()) {
        logger.debug("Adding " + full_name() + " to abstract interface list");
      }

      if (abstractInterfaces == null) {
        abstractInterfaces = new HashSet();
      }

      abstractInterfaces.add(full_name());
    }

    try {
      ScopedName.definePseudoScope(full_name());
      ctspec.c_type_spec = this;

      if (is_pseudo) NameTable.define(full_name(), IDLTypes.PSEUDO_INTERFACE);
      else NameTable.define(full_name(), IDLTypes.INTERFACE);

      TypeMap.typedef(full_name(), ctspec);
    } catch (IllegalRedefinition ill) {
      parser.fatal_error(
          "Cannot redefine " + token.str_val + " in nested scope as " + ill.newDef, token);
    } catch (NameAlreadyDefined nad) {
      // if we get here, there is already a type spec for this interface
      // in the global type table for a forward declaration of this
      // interface. We must replace that table entry with this type spec
      // unless this is yet another forward declaration

      Object forwardDeclaration = parser.get_pending(full_name());

      if (forwardDeclaration != null) {
        if (!(forwardDeclaration instanceof Interface)) {
          parser.error(
              "Forward declaration types mismatch for "
                  + full_name()
                  + ": name already defined with another type",
              token);
        }

        if (body == null) {
          justAnotherOne = true;
        }

        // else actual definition

        if ((!(full_name().equals("CORBA.TypeCode")
                || full_name().equals("org.omg.CORBA.TypeCode")))
            && body != null) {
          TypeMap.replaceForwardDeclaration(full_name(), ctspec);
        }
      } else {
        // this is another forward declaration, ignore
      }
    }

    if (body != null) {
      if (inheritanceSpec != null && inheritanceSpec.v.size() > 0) {
        if (logger.isDebugEnabled()) logger.debug("Checking inheritanceSpec of " + full_name());

        HashSet h = new HashSet();

        for (Enumeration e = inheritanceSpec.v.elements(); e.hasMoreElements(); ) {
          ScopedName name = (ScopedName) e.nextElement();

          ConstrTypeSpec ts = unwindTypedefs(name);

          if (ts.declaration() instanceof Interface) {
            if (h.contains(ts.full_name())) {
              parser.fatal_error(
                  "Illegal inheritance spec: "
                      + inheritanceSpec
                      + " (repeated inheritance not allowed).",
                  token);
            }

            // else:
            h.add(ts.full_name());

            continue;
          }

          // else:
          parser.fatal_error(
              "Illegal inheritance spec: "
                  + inheritanceSpec
                  + " (ancestor "
                  + ts.full_name()
                  + " not an interface)",
              token);
        }

        body.set_ancestors(inheritanceSpec);
      }

      body.parse();
      NameTable.parsed_interfaces.put(full_name(), "");

      if (parser.generate_ami_callback) {
        replyHandler = new ReplyHandler(this);
        replyHandler.parse();
      }

    } else if (!justAnotherOne) {
      // i am forward declared, must set myself as
      // pending further parsing
      parser.set_pending(full_name(), this);
    }

    parsed = true;
  }
Ejemplo n.º 6
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);
    }
  }