Package freenet.io.comm

Examples of freenet.io.comm.MessageFilter


    private DO waitForAccepted(RequestLikelyAcceptedState expectedAcceptState, PeerNode next, UIDTag origTag) {
      while(true) {
       
        Message msg;
       
        MessageFilter mf = makeAcceptedRejectedFilter(next, getAcceptedTimeout(), origTag);
       
        try {
          msg = node.usm.waitFor(mf, this);
          if(logMINOR) Logger.minor(this, "first part got "+msg);
        } catch (DisconnectedException e) {
View Full Code Here


   * Receive the file.
   * @return True if the whole file was received, false otherwise.
   */
  public boolean receive() {
    while(true) {
      MessageFilter mfSendKilled = MessageFilter.create().setSource(peer).setType(DMT.FNPBulkSendAborted) .setField(DMT.UID, uid).setTimeout(TIMEOUT);
      MessageFilter mfPacket = MessageFilter.create().setSource(peer).setType(DMT.FNPBulkPacketSend) .setField(DMT.UID, uid).setTimeout(TIMEOUT);
      if(prb.hasWholeFile()) {
        try {
          peer.sendAsync(DMT.createFNPBulkReceivedAll(uid), null, ctr);
        } catch (NotConnectedException e) {
          // Ignore, we have the data.
View Full Code Here

          }
        });
      }
      _senderThread.schedule();

      MessageFilter mfAllReceived = MessageFilter.create().setType(DMT.allReceived).setField(DMT.UID, _uid).setSource(_destination).setNoTimeout();
      MessageFilter mfSendAborted = MessageFilter.create().setType(DMT.sendAborted).setField(DMT.UID, _uid).setSource(_destination).setNoTimeout();
     
      try {
        _usm.addAsyncFilter(mfAllReceived, cbAllReceived, _ctr);
        _usm.addAsyncFilter(mfSendAborted, cbSendAborted, _ctr);
      } catch (DisconnectedException e) {
View Full Code Here

    }
    _usm.addAsyncFilter(relevantMessages(timeout), notificationWaiter, _ctr);
  }

  private MessageFilter relevantMessages(long timeout) {
    MessageFilter mfPacketTransmit = MessageFilter.create().setTimeout(timeout).setType(DMT.packetTransmit).setField(DMT.UID, _uid).setSource(_sender);
    MessageFilter mfAllSent = MessageFilter.create().setTimeout(timeout).setType(DMT.allSent).setField(DMT.UID, _uid).setSource(_sender);
    MessageFilter mfSendAborted = MessageFilter.create().setTimeout(timeout).setType(DMT.sendAborted).setField(DMT.UID, _uid).setSource(_sender);
    return mfPacketTransmit.or(mfAllSent.or(mfSendAborted));
  }
View Full Code Here

        // Ignore.
      }
    }
   
    while(headers == null || data == null || pubKey == null) {
      MessageFilter mfDataInsertRejected = MessageFilter.create().setType(DMT.FNPDataInsertRejected).setField(DMT.UID, uid).setSource(source).setTimeout(DATA_INSERT_TIMEOUT);
      MessageFilter mf = mfDataInsertRejected;
      if(headers == null) {
        MessageFilter m = MessageFilter.create().setType(DMT.FNPSSKInsertRequestHeaders).setField(DMT.UID, uid).setSource(source).setTimeout(DATA_INSERT_TIMEOUT);
        mf = m.or(mf);
      }
      if(data == null) {
        MessageFilter m = MessageFilter.create().setType(DMT.FNPSSKInsertRequestData).setField(DMT.UID, uid).setSource(source).setTimeout(DATA_INSERT_TIMEOUT);
        mf = m.or(mf);
      }
      if(pubKey == null) {
        MessageFilter m = MessageFilter.create().setType(DMT.FNPSSKPubKey).setField(DMT.UID, uid).setSource(source).setTimeout(DATA_INSERT_TIMEOUT);
        mf = m.or(mf);
      }
      Message msg;
      try {
        msg = node.usm.waitFor(mf, this);
      } catch (DisconnectedException e) {
View Full Code Here

        if (logDEBUG) Logger.debug(Probe.class, "acceptProbability is " + acceptProbability);
        if (node.random.nextFloat() < acceptProbability) {
          if (logDEBUG) Logger.debug(Probe.class, "Accepted candidate.");
          //Filter for response to this probe with requested result type.
          final MessageFilter filter = createResponseFilter(type, candidate, uid, htl);
          message.set(DMT.HTL, htl);
          try {
            node.getUSM().addAsyncFilter(filter, new ResultListener(listener), this);
            if (logDEBUG) Logger.debug(Probe.class, "Sending.");
            candidate.sendAsync(message, null, this);
View Full Code Here

   * @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

         * 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

      }
    }
   
        // 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

            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

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.