Package freenet.io.comm

Examples of freenet.io.comm.MessageFilter


        Logger.minor(this, "Node "+pn+" rejected FNPGetOfferedKey as invalid with reason "+reply.getShort(DMT.REASON));
      return OFFER_STATUS.TRY_ANOTHER;
    } else if(reply.getSpec() == DMT.FNPSSKDataFoundHeaders) {
      byte[] headers = ((ShortBuffer) reply.getObject(DMT.BLOCK_HEADERS)).getData();
      // Wait for the data
      MessageFilter mfData = MessageFilter.create().setSource(pn).setField(DMT.UID, uid).setTimeout(getOfferedTimeout).setType(DMT.FNPSSKDataFoundData);
      Message dataMessage;
      try {
        dataMessage = node.usm.waitFor(mfData, this);
      } catch (DisconnectedException e) {
        if(logMINOR)
          Logger.minor(this, "Disconnected: "+pn+" getting data for offer for "+key);
        return OFFER_STATUS.TRY_ANOTHER;
      }
      if(dataMessage == null) {
        Logger.error(this, "Got headers but not data from "+pn+" for offer for "+key+" on "+this);
        return OFFER_STATUS.TRY_ANOTHER;
      }
      byte[] sskData = ((ShortBuffer) dataMessage.getObject(DMT.DATA)).getData();
      if(pubKey == null) {
        MessageFilter mfPK = MessageFilter.create().setSource(pn).setField(DMT.UID, uid).setTimeout(getOfferedTimeout).setType(DMT.FNPSSKPubKey);
        Message pk;
        try {
          pk = node.usm.waitFor(mfPK, this);
        } catch (DisconnectedException e) {
          if(logMINOR)
View Full Code Here


     * FNPAccepted - continue
     * FNPRejectedLoop - go to another node
     * FNPRejectedOverload - propagate back to source, go to another node if local
     */
   
    MessageFilter mfAccepted = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(acceptedTimeout).setType(DMT.FNPAccepted);
    MessageFilter mfRejectedLoop = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(acceptedTimeout).setType(DMT.FNPRejectedLoop);
    MessageFilter mfRejectedOverload = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(acceptedTimeout).setType(DMT.FNPRejectedOverload);
   
    // mfRejectedOverload must be the last thing in the or
    // So its or pointer remains null
    // Otherwise we need to recreate it below
    return mfAccepted.or(mfRejectedLoop.or(mfRejectedOverload));
View Full Code Here

    // Otherwise we need to recreate it below
    return mfAccepted.or(mfRejectedLoop.or(mfRejectedOverload));
  }

  private MessageFilter createMessageFilter(int timeout, PeerNode next) {
    MessageFilter mfDNF = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(timeout).setType(DMT.FNPDataNotFound);
    MessageFilter mfRF = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(timeout).setType(DMT.FNPRecentlyFailed);
    MessageFilter mfRouteNotFound = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(timeout).setType(DMT.FNPRouteNotFound);
    MessageFilter mfRejectedOverload = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(timeout).setType(DMT.FNPRejectedOverload);
   
    MessageFilter mf = mfDNF.or(mfRF.or(mfRouteNotFound.or(mfRejectedOverload)));
    if(!isSSK) {
      MessageFilter mfRealDFCHK = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(timeout).setType(DMT.FNPCHKDataFound);
      mf = mfRealDFCHK.or(mf);
    } else {
      MessageFilter mfPubKey = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(timeout).setType(DMT.FNPSSKPubKey);
      MessageFilter mfDFSSKHeaders = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(timeout).setType(DMT.FNPSSKDataFoundHeaders);
      MessageFilter mfDFSSKData = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(timeout).setType(DMT.FNPSSKDataFoundData);
      mf = mfPubKey.or(mfDFSSKHeaders.or(mfDFSSKData.or(mf)));
    }
    return mf;
  }
View Full Code Here

    final short htl = this.htl;
    origTag.handlingTimeout(next);

    long timeout = MINUTES.toMillis(1);

    MessageFilter mf = makeAcceptedRejectedFilter(next, timeout, origTag);
    try {
      node.usm.addAsyncFilter(mf, new SlowAsyncMessageFilterCallback() {

        @Override
        public void onMatched(Message m) {
View Full Code Here

   
    public void schedule() {
          long now = System.currentTimeMillis();
          int timeout = (int)(Math.min(Integer.MAX_VALUE, deadline - now));
          if(timeout >= 0) {
            MessageFilter mf = createMessageFilter(timeout, waitingFor);
            try {
              node.usm.addAsyncFilter(mf, this, RequestSender.this);
            } catch (DisconnectedException e) {
              onDisconnect(lastNode);
            }
View Full Code Here

  @Override
  protected MessageFilter makeAcceptedRejectedFilter(PeerNode next, long acceptedTimeout, UIDTag tag) {
    // Use the right UID here, in case we fork on cacheable.
    final long uid = tag.uid;
        MessageFilter mfAccepted = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(acceptedTimeout).setType(DMT.FNPAccepted);
        MessageFilter mfRejectedLoop = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(acceptedTimeout).setType(DMT.FNPRejectedLoop);
        MessageFilter mfRejectedOverload = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(acceptedTimeout).setType(DMT.FNPRejectedOverload);
       
        // mfRejectedOverload must be the last thing in the or
        // So its or pointer remains null
        // Otherwise we need to recreate it below
        mfRejectedOverload.clearOr();
        return mfAccepted.or(mfRejectedLoop.or(mfRejectedOverload));
  }
View Full Code Here

    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

         * - FNPRejectTimeout - we took too long to send the DataInsert
         * - FNPDataInsertRejected - the insert was invalid
         */
       
        int searchTimeout = calculateTimeout(htl);
        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 mfTimeout = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(searchTimeout).setType(DMT.FNPRejectedTimeout);
       
        MessageFilter mf = mfInsertReply.or(mfRouteNotFound.or(mfDataInsertRejected.or(mfTimeout.or(mfRejectedOverload))));

        InsertTag thisTag = forkedRequestTag;
        if(forkedRequestTag == null) thisTag = origTag;
       
        if(logMINOR) Logger.minor(this, "Sending DataInsert");
        try {
      next.sendSync(dataInsert, this, realTimeFlag);
    } catch (NotConnectedException e1) {
      if(logMINOR) Logger.minor(this, "Not connected sending DataInsert: "+next+" for "+uid);
      next.noLongerRoutingTo(thisTag, false);
      routeRequests();
      return;
    } catch (SyncSendWaitedTooLongException e) {
      Logger.error(this, "Unable to send "+dataInsert+" to "+next+" in a reasonable time");
      // Other side will fail. No need to do anything.
      next.noLongerRoutingTo(thisTag, false);
      routeRequests();
      return;
    }

    if(logMINOR) Logger.minor(this, "Sending data");
    final BackgroundTransfer transfer =
      startBackgroundTransfer(next, prb, thisTag);
   
    // Once the transfer has started, we only unlock the tag after the transfer completes (successfully or not).
   
        while (true) {

          Message msg;
         
      if(failIfReceiveFailed(thisTag, next)) {
        // The transfer has started, it will be cancelled.
        transfer.onCompleted();
        return;
      }
     
      try {
        msg = node.usm.waitFor(mf, this);
      } catch (DisconnectedException e) {
        Logger.normal(this, "Disconnected from " + next
            + " while waiting for InsertReply on " + this);
        transfer.onDisconnect(next);
        break;
      }
      if(failIfReceiveFailed(thisTag, next)) {
        // The transfer has started, it will be cancelled.
        transfer.onCompleted();
        return;
      }
     
      if (msg == null) {
       
        Logger.warning(this, "Timeout on insert "+this+" to "+next);
       
        // First timeout.
        // Could be caused by the next node, or could be caused downstream.
        next.localRejectedOverload("AfterInsertAcceptedTimeout2", realTimeFlag);
        forwardRejectedOverload();

        synchronized(this) {
          status = TIMED_OUT;
          notifyAll();
        }
       
        // Wait for the second timeout off-thread.
        // FIXME wait asynchronously.
       
        final InsertTag tag = thisTag;
        final PeerNode waitingFor = next;
        final short htl = this.htl;
       
        Runnable r = new Runnable() {

          @Override
          public void run() {
            // We do not need to unlock the tag here.
            // That will happen in the BackgroundTransfer, which has already started.
           
            // FIXME factor out
                int searchTimeout = calculateTimeout(htl);
                    MessageFilter mfInsertReply = MessageFilter.create().setSource(waitingFor).setField(DMT.UID, uid).setTimeout(searchTimeout).setType(DMT.FNPInsertReply);
                    MessageFilter mfRejectedOverload = MessageFilter.create().setSource(waitingFor).setField(DMT.UID, uid).setTimeout(searchTimeout).setType(DMT.FNPRejectedOverload);
                    MessageFilter mfRouteNotFound = MessageFilter.create().setSource(waitingFor).setField(DMT.UID, uid).setTimeout(searchTimeout).setType(DMT.FNPRouteNotFound);
                    MessageFilter mfDataInsertRejected = MessageFilter.create().setSource(waitingFor).setField(DMT.UID, uid).setTimeout(searchTimeout).setType(DMT.FNPDataInsertRejected);
                    MessageFilter mfTimeout = MessageFilter.create().setSource(waitingFor).setField(DMT.UID, uid).setTimeout(searchTimeout).setType(DMT.FNPRejectedTimeout);
                   
                    MessageFilter mf = mfInsertReply.or(mfRouteNotFound.or(mfDataInsertRejected.or(mfTimeout.or(mfRejectedOverload))));

                  while (true) {
                   
                    Message msg;

View Full Code Here

    return cb.waitForResult();
  }
 
  public static void waitForOpennetNoderef(final boolean isReply, final PeerNode source, final long uid, final ByteCounter ctr, final NoderefCallback callback, final Node node) {
    // FIXME remove back compat code
    MessageFilter mf =
      MessageFilter.create().setSource(source).setField(DMT.UID, uid).
      setTimeout(RequestSender.OPENNET_TIMEOUT).
      setType(isReply ? DMT.FNPOpennetConnectReplyNew : DMT.FNPOpennetConnectDestinationNew);
    // Also waiting for an ack
    MessageFilter mfAck =
      MessageFilter.create().setSource(source).setField(DMT.UID, uid).
      setTimeout(RequestSender.OPENNET_TIMEOUT).setType(DMT.FNPOpennetCompletedAck);
    // Also waiting for an upstream timed out.
    MessageFilter mfAckTimeout =
      MessageFilter.create().setSource(source).setField(DMT.UID, uid).
      setTimeout(RequestSender.OPENNET_TIMEOUT).setType(DMT.FNPOpennetCompletedTimeout);
   
    mf = mfAck.or(mfAckTimeout.or(mf));
    try {
      node.usm.addAsyncFilter(mf, new SlowAsyncMessageFilterCallback() {
       
        boolean completed;
View Full Code Here

TOP

Related Classes of freenet.io.comm.MessageFilter

Copyright © 2018 www.massapicom. 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.