Package freenet.io.comm

Examples of freenet.io.comm.Message


        source.sendAsync(DMT.createFNPGetOfferedKeyInvalid(uid, DMT.GET_OFFERED_KEY_REJECTED_NO_KEY), null, senderCounter);
        tag.unlockHandler();
        return;
      }
     
      final Message data = DMT.createFNPSSKDataFoundData(uid, block.getRawData(), realTimeFlag);
      Message headers = DMT.createFNPSSKDataFoundHeaders(uid, block.getRawHeaders(), realTimeFlag);
      final int dataLength = block.getRawData().length;
     
      source.sendAsync(headers, null, senderCounter);
     
      node.executor.execute(new PrioRunnable() {

        @Override
        public int getPriority() {
          return NativeThread.HIGH_PRIORITY;
        }

        @Override
        public void run() {
          try {
            source.sendSync(data, senderCounter, realTimeFlag);
            senderCounter.sentPayload(dataLength);
          } catch (NotConnectedException e) {
            // :(
          } catch (SyncSendWaitedTooLongException e) {
            // Impossible
          } finally {
            tag.unlockHandler();
          }
        }
       
      }, "Send offered SSK");
     
      if(needPubKey) {
        Message pk = DMT.createFNPSSKPubKey(uid, block.getPubKey(), realTimeFlag);
        source.sendAsync(pk, null, senderCounter);
      }
    } else {
      CHKBlock block = node.fetch((NodeCHK)key, false, false, false, false, true, null);
      if(block == null) {
        // Don't have the key
        source.sendAsync(DMT.createFNPGetOfferedKeyInvalid(uid, DMT.GET_OFFERED_KEY_REJECTED_NO_KEY), null, senderCounter);
        tag.unlockHandler();
        return;
      }
      Message df = DMT.createFNPCHKDataFound(uid, block.getRawHeaders());
      source.sendAsync(df, null, senderCounter);
          PartiallyReceivedBlock prb =
            new PartiallyReceivedBlock(Node.PACKETS_IN_BLOCK, Node.PACKET_SIZE, block.getRawData());
          final BlockTransmitter bt =
            new BlockTransmitter(node.usm, node.getTicker(), source, uid, prb, senderCounter, BlockTransmitter.NEVER_CASCADE,
View Full Code Here


  private void realRun() throws NotConnectedException {
    if(logMINOR)
      Logger.minor(this, "Handling a request: " + uid);

    Message accepted = DMT.createFNPAccepted(uid);
    source.sendAsync(accepted, null, this);
   
    if(tag.shouldSlowDown()) {
      try {
        source.sendAsync(DMT.createFNPRejectedOverload(uid, false, false, realTimeFlag), null, this);
      } catch (NotConnectedException e) {
        // Ignore.
      }
    }
   
    Object o;
    if(passedInKeyBlock != null) {
      tag.setServedFromDatastore();
      returnLocalData(passedInKeyBlock);
      passedInKeyBlock = null; // For GC
      return;
    } else
      o = node.makeRequestSender(key, htl, uid, tag, source, false, true, false, false, false, realTimeFlag);

    if(o == null) { // ran out of htl?
      Message dnf = DMT.createFNPDataNotFound(uid);
      status = RequestSender.DATA_NOT_FOUND; // for byte logging
      node.failureTable.onFinalFailure(key, null, htl, htl, FailureTable.RECENTLY_FAILED_TIME, FailureTable.REJECT_TIME, source);
      sendTerminal(dnf);
      node.nodeStats.remoteRequest(key instanceof NodeSSK, false, false, htl, key.toNormalizedDouble(), realTimeFlag, false);
      return;
View Full Code Here

    try {
      if(!sentRejectedOverload) {
        if(logMINOR) Logger.minor(this, "Propagating RejectedOverload on "+this);
        // Forward RejectedOverload
        //Note: This message is only discernible from the terminal messages by the IS_LOCAL flag being false. (!IS_LOCAL)->!Terminal
        Message msg = DMT.createFNPRejectedOverload(uid, false, true, realTimeFlag);
        source.sendAsync(msg, null, this);
        //If the status changes (e.g. to SUCCESS), there is little need to send yet another reject overload.
        sentRejectedOverload = true;
      }
    } catch(NotConnectedException e) {
View Full Code Here

      return;
    }
    if(logMINOR) Logger.minor(this, "CHK transfer start on "+this);
    try {
      // Is a CHK.
      Message df = DMT.createFNPCHKDataFound(uid, rs.getHeaders());
      source.sendAsync(df, null, this);

      PartiallyReceivedBlock prb = rs.getPRB();
      bt =
        new BlockTransmitter(node.usm, node.getTicker(), source, uid, prb, this, new ReceiverAbortHandler() {
View Full Code Here

   
    try {
      switch(status) {
        case RequestSender.NOT_FINISHED:
        case RequestSender.DATA_NOT_FOUND:
          Message dnf = DMT.createFNPDataNotFound(uid);
          sendTerminal(dnf);
          return;
        case RequestSender.RECENTLY_FAILED:
          Message rf = DMT.createFNPRecentlyFailed(uid, rs.getRecentlyFailedTimeLeft());
          sendTerminal(rf);
          return;
        case RequestSender.GENERATED_REJECTED_OVERLOAD:
        case RequestSender.TIMED_OUT:
        case RequestSender.INTERNAL_ERROR:
          // Locally generated.
          // Propagate back to source who needs to reduce send rate
          ///@bug: we may not want to translate fatal timeouts into non-fatal timeouts.
          Message reject = DMT.createFNPRejectedOverload(uid, true, true, realTimeFlag);
          sendTerminal(reject);
          return;
        case RequestSender.ROUTE_NOT_FOUND:
          // Tell source
          Message rnf = DMT.createFNPRouteNotFound(uid, rs.getHTL());
          sendTerminal(rnf);
          return;
        case RequestSender.SUCCESS:
          if(key instanceof NodeSSK)
            sendSSK(rs.getHeaders(), rs.getSSKData(), needsPubKey, (rs.getSSKBlock().getKey()).getPubKey());
View Full Code Here

   * a flag so that we will complete when we do.
   * @throws NotConnectedException If we didn't start the transfer and were not
   * connected to the source.
   */
  private void maybeCompleteTransfer() throws NotConnectedException {
    Message reject = null;
    boolean disconn = false;
    boolean xferFinished = false;
    boolean xferSuccess = false;
    synchronized(this) {
      if(disconnected)
View Full Code Here

        // So it is neither beneficial for the node nor a viable DoS.
        // Alternative solution would be to wait until the pubkey and data have been acked before unlocking and sending the headers, but this appears not to be necessary.
        tag.unlockHandler();
      }
    };
    Message headersMsg = DMT.createFNPSSKDataFoundHeaders(uid, headers, realTimeFlag);
    source.sendAsync(headersMsg, mcb.make(), this);
    final Message dataMsg = DMT.createFNPSSKDataFoundData(uid, data, realTimeFlag);
    if(needsPubKey) {
      Message pk = DMT.createFNPSSKPubKey(uid, pubKey, realTimeFlag);
      source.sendAsync(pk, mcb.make(), this);
    }
    source.sendAsync(dataMsg, mcb.make(), this);
    if(mcb != null) mcb.arm();
  }
View Full Code Here

  static void sendSSK(byte[] headers, byte[] data, boolean needsPubKey, DSAPublicKey pubKey, final PeerNode source, long uid, ByteCounter ctr, boolean realTimeFlag) throws NotConnectedException, WaitedTooLongException, PeerRestartedException, SyncSendWaitedTooLongException {
    // SUCCESS requires that BOTH the pubkey AND the data/headers have been received.
    // The pubKey will have been set on the SSK key, and the SSKBlock will have been constructed.
    WaitingMultiMessageCallback mcb = null;
    mcb = new WaitingMultiMessageCallback();
    Message headersMsg = DMT.createFNPSSKDataFoundHeaders(uid, headers, realTimeFlag);
    source.sendAsync(headersMsg, mcb.make(), ctr);
    final Message dataMsg = DMT.createFNPSSKDataFoundData(uid, data, realTimeFlag);
    source.sendAsync(dataMsg, mcb.make(), ctr);

    if(needsPubKey) {
      Message pk = DMT.createFNPSSKPubKey(uid, pubKey, realTimeFlag);
      source.sendAsync(pk, mcb.make(), ctr);
    }
   
    mcb.arm();
    mcb.waitFor();
View Full Code Here

      sendSSK(block.getRawHeaders(), block.getRawData(), needsPubKey, ((SSKBlock) block).getPubKey());
      status = RequestSender.SUCCESS; // for byte logging
      // Assume local SSK sending will succeed?
      node.nodeStats.remoteRequest(true, true, true, htl, key.toNormalizedDouble(), realTimeFlag, false);
    } else if(block instanceof CHKBlock) {
      Message df = DMT.createFNPCHKDataFound(uid, block.getRawHeaders());
      PartiallyReceivedBlock prb =
        new PartiallyReceivedBlock(Node.PACKETS_IN_BLOCK, Node.PACKET_SIZE, block.getRawData());
      BlockTransmitter bt =
        new BlockTransmitter(node.usm, node.getTicker(), source, uid, prb, this, BlockTransmitter.NEVER_CASCADE,
            new BlockTransmitterCompletion() {
View Full Code Here

  }
 
  /** Acknowledge the opennet path folding attempt without sending a reference. Once
   * the send completes (asynchronously), unlock everything. */
  private void ackOpennet() {
    Message msg = DMT.createFNPOpennetCompletedAck(uid);
    sendTerminal(msg);
  }
View Full Code Here

TOP

Related Classes of freenet.io.comm.Message

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.