Examples of MessageFilter


Examples of freenet.io.comm.MessageFilter

   * @param htl current probe HTL; used to calculate timeout.
   * @return filter for the requested result type, probe error, and probe refusal.
   */
  private static MessageFilter createResponseFilter(final Type type, final PeerNode candidate, final long uid, final byte htl) {
    final long timeout = (htl - 1) * TIMEOUT_PER_HTL + TIMEOUT_HTL1;
    final MessageFilter filter = createFilter(candidate, uid, timeout);

    switch (type) {
      case BANDWIDTH: filter.setType(DMT.ProbeBandwidth); break;
      case BUILD: filter.setType(DMT.ProbeBuild); break;
      case IDENTIFIER: filter.setType(DMT.ProbeIdentifier); break;
      case LINK_LENGTHS: filter.setType(DMT.ProbeLinkLengths); break;
      case LOCATION: filter.setType(DMT.ProbeLocation); break;
      case STORE_SIZE: filter.setType(DMT.ProbeStoreSize); break;
      case UPTIME_48H:
      case UPTIME_7D: filter.setType(DMT.ProbeUptime); break;
      case REJECT_STATS: filter.setType(DMT.ProbeRejectStats); break;
      case OVERALL_BULK_OUTPUT_CAPACITY_USAGE: filter.setType(DMT.ProbeOverallBulkOutputCapacityUsage); break;
      default: throw new UnsupportedOperationException("Missing filter for " + type.name());
    }

    //Refusal or an error should also be listened for so it can be relayed.
    filter.or(createFilter(candidate, uid, timeout).setType(DMT.ProbeRefused)
          .or(createFilter(candidate, uid, timeout).setType(DMT.ProbeError)));

    return filter;
  }
View Full Code Here

Examples of freenet.io.comm.MessageFilter

         * FNPAccepted - continue
         * FNPRejectedLoop - go to another node
         * FNPRejectedOverload - go to another node
         */

        MessageFilter mfAccepted = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(ACCEPTED_TIMEOUT).setType(DMT.FNPAccepted);
        MessageFilter mfRejectedLoop = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(ACCEPTED_TIMEOUT).setType(DMT.FNPRejectedLoop);
        MessageFilter mfRejectedOverload = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(ACCEPTED_TIMEOUT).setType(DMT.FNPRejectedOverload);
        MessageFilter mfOpennetDisabled = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(ACCEPTED_TIMEOUT).setType(DMT.FNPOpennetDisabled);

        // mfRejectedOverload must be the last thing in the or
        // So its or pointer remains null
        // Otherwise we need to recreate it below
        MessageFilter mf = mfAccepted.or(mfRejectedLoop.or(mfRejectedOverload.or(mfOpennetDisabled)));

        try {
          msg = node.usm.waitFor(mf, this);
          if(logMINOR) Logger.minor(this, "first part got "+msg);
        } catch (DisconnectedException e) {
          Logger.normal(this, "Disconnected from "+next+" while waiting for Accepted on "+uid);
          break;
        }

        if(msg == null) {
          if(logMINOR) Logger.minor(this, "Timeout waiting for Accepted");
          // Try next node
          msg = null;
          break;
        }

        if(msg.getSpec() == DMT.FNPRejectedLoop) {
          if(logMINOR) Logger.minor(this, "Rejected loop");
          // Find another node to route to
          msg = null;
          break;
        }

        if(msg.getSpec() == DMT.FNPRejectedOverload) {
          if(logMINOR) Logger.minor(this, "Rejected: overload");
          // Give up on this one, try another
          msg = null;
          break;
        }

        if(msg.getSpec() == DMT.FNPOpennetDisabled) {
          if(logMINOR) Logger.minor(this, "Opennet disabled");
          msg = null;
          break;
        }

        if(msg.getSpec() != DMT.FNPAccepted) {
          Logger.error(this, "Unrecognized message: "+msg);
          continue;
        }

        break;
      }

      if((msg == null) || (msg.getSpec() != DMT.FNPAccepted)) {
        // Try another node
        continue;
      }

      if(logMINOR) Logger.minor(this, "Got Accepted");
     
      if(cb != null)
        cb.acceptedSomewhere();

      // Send the rest

      try {
        sendRest(next, xferUID);
      } catch (NotConnectedException e1) {
        if(logMINOR)
          Logger.minor(this, "Not connected while sending noderef on "+next);
        continue;
      }

      // Otherwise, must be Accepted

      // So wait...

      while(true) {

        MessageFilter mfAnnounceCompleted = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(ANNOUNCE_TIMEOUT).setType(DMT.FNPOpennetAnnounceCompleted);
        MessageFilter mfRouteNotFound = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(ANNOUNCE_TIMEOUT).setType(DMT.FNPRouteNotFound);
        MessageFilter mfRejectedOverload = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(ANNOUNCE_TIMEOUT).setType(DMT.FNPRejectedOverload);
        MessageFilter mfAnnounceReply = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(ANNOUNCE_TIMEOUT).setType(DMT.FNPOpennetAnnounceReply);
        MessageFilter mfOpennetDisabled = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(ANNOUNCE_TIMEOUT).setType(DMT.FNPOpennetDisabled);
        MessageFilter mfNotWanted = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(ANNOUNCE_TIMEOUT).setType(DMT.FNPOpennetAnnounceNodeNotWanted);
        MessageFilter mfOpennetNoderefRejected = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(ANNOUNCE_TIMEOUT).setType(DMT.FNPOpennetNoderefRejected);
        MessageFilter mf = mfAnnounceCompleted.or(mfRouteNotFound.or(mfRejectedOverload.or(mfAnnounceReply.or(mfOpennetDisabled.or(mfNotWanted.or(mfOpennetNoderefRejected))))));

        try {
          msg = node.usm.waitFor(mf, this);
        } catch (DisconnectedException e) {
          Logger.normal(this, "Disconnected from "+next+" while waiting for announcement");
View Full Code Here

Examples of freenet.io.comm.MessageFilter

      }
    }
   
        // Source will send us a DataInsert
       
        MessageFilter mf;
        mf = makeDataInsertFilter(DATA_INSERT_TIMEOUT);
       
        Message msg;
        try {
            msg = node.usm.waitFor(mf, this);
View Full Code Here

Examples of freenet.io.comm.MessageFilter

            return;
        }
  }

  private MessageFilter makeDataInsertFilter(long timeout) {
      MessageFilter mfDataInsert = MessageFilter.create().setType(DMT.FNPDataInsert).setField(DMT.UID, uid).setSource(source).setTimeout(timeout);
      // DataInsertRejected means the transfer failed upstream so a DataInsert will not be sent.
      MessageFilter mfDataInsertRejected = MessageFilter.create().setType(DMT.FNPDataInsertRejected).setField(DMT.UID, uid).setSource(source).setTimeout(timeout);
      return mfDataInsert.or(mfDataInsertRejected);
  }
View Full Code Here

Examples of freenet.io.comm.MessageFilter

        source.localRejectedOverload("TimedOutAwaitingDataInsert", realTimeFlag);
       
        // Two stage timeout. Don't go fatal unless no response in 60 seconds.
        // Yes it's ugly everywhere but since we have a longish connection timeout it's necessary everywhere. :|
        // FIXME review two stage timeout everywhere with some low level networking guru.
        MessageFilter mf = makeDataInsertFilter(SECONDS.toMillis(60));
        node.usm.addAsyncFilter(mf, new SlowAsyncMessageFilterCallback() {

          @Override
          public void onMatched(Message m) {
            // Okay, great.
View Full Code Here

Examples of freenet.io.comm.MessageFilter

            byte[] myHash = md.digest(myValue);

            Message m = DMT.createFNPSwapReply(uid, myHash);

            MessageFilter filter =
                MessageFilter.create().setType(DMT.FNPSwapCommit).setField(DMT.UID, uid).setTimeout(TIMEOUT).setSource(pn);

            node.usm.send(pn, m, LocationManager.this);

            Message commit;
View Full Code Here

Examples of freenet.io.comm.MessageFilter

                // Only 1 ID because we are sending; we won't receive
                item = addForwardedItem(uid, uid, null, pn);

                if(logMINOR) Logger.minor(this, "Sending SwapRequest "+uid+" to "+pn);

                MessageFilter filter1 =
                    MessageFilter.create().setType(DMT.FNPSwapRejected).setField(DMT.UID, uid).setSource(pn).setTimeout(TIMEOUT);
                MessageFilter filter2 =
                    MessageFilter.create().setType(DMT.FNPSwapReply).setField(DMT.UID, uid).setSource(pn).setTimeout(TIMEOUT);
                MessageFilter filter = filter1.or(filter2);

                node.usm.send(pn, m, LocationManager.this);

                if(logMINOR) Logger.minor(this, "Waiting for SwapReply/SwapRejected on "+uid);
                Message reply;
                try {
                    reply = node.usm.waitFor(filter, LocationManager.this);
                } catch (DisconnectedException e) {
                  if(logMINOR) Logger.minor(this, "Disconnected while waiting for SwapReply/SwapRejected for "+uid);
                    return;
                }

                if(reply == null) {
                    if(pn.isRoutable() && (System.currentTimeMillis() - pn.timeLastConnectionCompleted() > TIMEOUT*2)) {
                        // Timed out! Abort...
                        Logger.error(this, "Timed out waiting for SwapRejected/SwapReply on "+uid);
                    }
                    return;
                }

                if(reply.getSpec() == DMT.FNPSwapRejected) {
                    // Failed. Abort.
                  if(logMINOR) Logger.minor(this, "Swap rejected on "+uid);
                    return;
                }

                // We have an FNPSwapReply, yay
                // FNPSwapReply is exactly the same format as FNPSwapRequest
                byte[] hisHash = ((ShortBuffer)reply.getObject(DMT.HASH)).getData();

                Message confirm = DMT.createFNPSwapCommit(uid, myValue);
                //confirm.addSubMessage(DMT.createFNPSwapLocations(extractUIDs(friendLocsAndUIDs)));

                filter1.clearOr();
                MessageFilter filter3 = MessageFilter.create().setField(DMT.UID, uid).setType(DMT.FNPSwapComplete).setTimeout(TIMEOUT).setSource(pn);
                filter = filter1.or(filter3);

                node.usm.send(pn, confirm, LocationManager.this);

                if(logMINOR) Logger.minor(this, "Waiting for SwapComplete: uid = "+uid);
View Full Code Here

Examples of freenet.io.comm.MessageFilter

    Message m = DMT.createFNPRoutedPing(uid, loc2, maxHTL, initialX, pubKeyHash);
    Logger.normal(this, "Message: "+m);

    dispatcher.handleRouted(m, null);
    // FIXME: might be rejected
    MessageFilter mf1 = MessageFilter.create().setField(DMT.UID, uid).setType(DMT.FNPRoutedPong).setTimeout(5000);
    try {
      //MessageFilter mf2 = MessageFilter.create().setField(DMT.UID, uid).setType(DMT.FNPRoutedRejected).setTimeout(5000);
      // Ignore Rejected - let it be retried on other peers
      m = usm.waitFor(mf1/*.or(mf2)*/, null);
    } catch (DisconnectedException e) {
View Full Code Here

Examples of freenet.io.comm.MessageFilter

         *   an SVK/SSK/KSK, therefore could be different to what we are
         *   inserting.
         * - FNPDataInsertRejected - the insert was invalid
         */
       
        MessageFilter mfInsertReply = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(searchTimeout).setType(DMT.FNPInsertReply);
        MessageFilter mfRejectedOverload = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(searchTimeout).setType(DMT.FNPRejectedOverload);
        MessageFilter mfRouteNotFound = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(searchTimeout).setType(DMT.FNPRouteNotFound);
        MessageFilter mfDataInsertRejected = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(searchTimeout).setType(DMT.FNPDataInsertRejected);
        MessageFilter mfSSKDataFoundHeaders = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(searchTimeout).setType(DMT.FNPSSKDataFoundHeaders);
       
        return mfRouteNotFound.or(mfInsertReply.or(mfRejectedOverload.or(mfDataInsertRejected.or(mfSSKDataFoundHeaders))));
  }
View Full Code Here

Examples of freenet.io.comm.MessageFilter

    final long uid = tag.uid;
    tag.handlingTimeout(next);
    // The node didn't accept the request. So we don't need to send them the data.
    // However, we do need to wait a bit longer to try to postpone the fatalTimeout().
    // Somewhat intricate logic to try to avoid fatalTimeout() if at all possible.
    MessageFilter mf = makeAcceptedRejectedFilter(next, TIMEOUT_AFTER_ACCEPTEDREJECTED_TIMEOUT, tag);
    try {
      node.usm.addAsyncFilter(mf, new SlowAsyncMessageFilterCallback() {

        @Override
        public void onMatched(Message m) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.