Package freenet.io.comm

Examples of freenet.io.comm.Message


  private void handleNoDataInsert() {
      try {
        // Nodes wait until they have the DataInsert before forwarding, so there is absolutely no excuse: There is a local problem here!
        if(source.isConnected() && (startTime > (source.timeLastConnectionCompleted()+Node.HANDSHAKE_TIMEOUT*4)))
          Logger.warning(this, "Did not receive DataInsert on "+uid+" from "+source+" !");
        Message tooSlow = DMT.createFNPRejectedTimeout(uid);
        source.sendAsync(tooSlow, null, this);
        Message m = DMT.createFNPInsertTransfersCompleted(uid, true);
        source.sendAsync(m, null, this);
        prb = new PartiallyReceivedBlock(Node.PACKETS_IN_BLOCK, Node.PACKET_SIZE);
        br = new BlockReceiver(node.usm, source, uid, prb, this, node.getTicker(), false, realTimeFlag, null, false);
        prb.abort(RetrievalException.NO_DATAINSERT, "No DataInsert", true);
        source.localRejectedOverload("TimedOutAwaitingDataInsert", realTimeFlag);
View Full Code Here


        synchronized(sentCompletionLock) {
          sentCompletionWasSet = sentCompletion;
          sentCompletion = true;
        }
       
    Message m=null;
   
    boolean routingTookTooLong = false;
        if((sender != null) && (!sentCompletionWasSet)) {
            if(logMINOR) Logger.minor(this, "Waiting for completion");
            long startedTime = System.currentTimeMillis();
View Full Code Here

   
    /**
     * Verify data, or send DataInsertRejected.
     */
    private CHKBlock verify() {
        Message toSend = null;
       
        CHKBlock block = null;
       
        synchronized(this) {
          if((prb == null) || prb.isAborted()) return null;
View Full Code Here

              // Cancel the sender
              if(sender != null)
                sender.onReceiveFailed(); // tell it to stop if it hasn't already failed... unless it's sending from store
              runThread.interrupt();
              tag.timedOutToHandlerButContinued(); // sender is finished, or will be very soon; we may however be waiting for the sendAborted downstream.
              Message msg = DMT.createFNPDataInsertRejected(uid, DMT.DATA_INSERT_REJECTED_RECEIVE_FAILED);
              try {
                source.sendSync(msg, CHKInsertHandler.this, realTimeFlag);
              } catch (NotConnectedException ex) {
                //If they are not connected, that's probably why the receive failed!
                if (logMINOR) Logger.minor(this, "Can't send "+msg+" to "+source+": "+ex);
View Full Code Here

    protected void announceLocChange() {
      announceLocChange(false, false, false);
    }

    private void announceLocChange(boolean log, boolean randomReset, boolean fromDupLocation) {
        Message msg = DMT.createFNPLocChangeNotificationNew(getLocation(), node.peers.getPeerLocationDoubles(true));
        node.peers.localBroadcast(msg, false, true, this);
  if(log)
    recordLocChange(randomReset, fromDupLocation);
    }
View Full Code Here

    /**
     * Unlock the node for swapping.
     * @param logSwapTime If true, log the swap time. */
    void unlock(boolean logSwapTime) {
      Message nextMessage;
      synchronized(this) {
        if(!locked)
            throw new IllegalStateException("Unlocking when not locked!");
        long lockTime = System.currentTimeMillis() - lockedTime;
        if(logMINOR) {
          Logger.minor(this, "Unlocking on port "+node.getDarknetPortNumber());
          Logger.minor(this, "lockTime: "+lockTime);
        }
        averageSwapTime.report(lockTime);

        if(incomingMessageQueue.isEmpty()) {
          locked = false;
          return;
        }

        // Otherwise, stay locked, and start the next one from the queue.

        nextMessage = incomingMessageQueue.removeFirst();
        lockedTime = System.currentTimeMillis();

      }

        long oldID = nextMessage.getLong(DMT.UID);
        long newID = oldID+1;
        PeerNode pn = (PeerNode) nextMessage.getSource();

      innerHandleSwapRequest(oldID, newID, pn, nextMessage);
    }
View Full Code Here

    /** Prevent timeouts and deadlocks due to A waiting for B waiting for A */
    static final long MAX_TIME_ON_INCOMING_QUEUE = SECONDS.toMillis(30);

    void removeTooOldQueuedItems() {
      while(true) {
        Message first;
        synchronized(this) {
          if(incomingMessageQueue.isEmpty()) return;
          first = incomingMessageQueue.getFirst();
          if(first.age() < MAX_TIME_ON_INCOMING_QUEUE) return;
          incomingMessageQueue.removeFirst();
          if(logMINOR) Logger.minor(this, "Cancelling queued item: "+first+" - too long on queue, maybe circular waiting?");
          swapsRejectedAlreadyLocked++;
        }
            long oldID = first.getLong(DMT.UID);
            PeerNode pn = (PeerNode) first.getSource();

            // Reject
            Message reject = DMT.createFNPSwapRejected(oldID);
            try {
                pn.sendAsync(reject, null, this);
            } catch (NotConnectedException e1) {
              if(logMINOR) Logger.minor(this, "Lost connection rejecting SwapRequest (locked) from "+pn);
            }
View Full Code Here

         */
        RecentlyForwardedItem item = recentlyForwardedIDs.get(oldID);
        if(item != null) {
          if(logMINOR) Logger.minor(this, "Rejecting - same ID as previous request");
            // Reject
            Message reject = DMT.createFNPSwapRejected(oldID);
            try {
                pn.sendAsync(reject, null, this);
            } catch (NotConnectedException e) {
              if(logMINOR) Logger.minor(this, "Lost connection to "+pn+" rejecting SwapRequest");
            }
            swapsRejectedRecognizedID++;
            return true;
        }
        if(pn.shouldRejectSwapRequest()) {
          if(logMINOR) Logger.minor(this, "Advised to reject SwapRequest by PeerNode - rate limit");
            // Reject
            Message reject = DMT.createFNPSwapRejected(oldID);
            try {
                pn.sendAsync(reject, null, this);
            } catch (NotConnectedException e) {
              if(logMINOR) Logger.minor(this, "Lost connection rejecting SwapRequest from "+pn);
            }
            swapsRejectedRateLimit++;
            return true;
        }
        if(logMINOR) Logger.minor(this, "SwapRequest from "+pn+" - uid="+oldID);
        int htl = m.getInt(DMT.HTL);
        if(htl > SWAP_MAX_HTL) {
          Logger.error(this, "Bogus swap HTL: "+htl+" from "+pn+" uid="+oldID);
          htl = SWAP_MAX_HTL;
        }
        htl--;
        if(!node.enableSwapping || htl <= 0 && swappingDisabled()) {
            // Reject
            Message reject = DMT.createFNPSwapRejected(oldID);
            try {
                pn.sendAsync(reject, null, this);
            } catch (NotConnectedException e1) {
              if(logMINOR) Logger.minor(this, "Lost connection rejecting SwapRequest (locked) from "+pn);
            }
            return true;
        }
        // Either forward it or handle it
        if(htl <= 0) {
          if(logMINOR) Logger.minor(this, "Accepting?... "+oldID);
            // Accept - handle locally
          lockOrQueue(m, oldID, newID, pn);
          return true;
        } else {
            m.set(DMT.HTL, htl);
            m.set(DMT.UID, newID);
            if(logMINOR) Logger.minor(this, "Forwarding... "+oldID);
            while(true) {
                // Forward
                PeerNode randomPeer = node.peers.getRandomPeer(pn);
                if(randomPeer == null) {
                  if(logMINOR) Logger.minor(this, "Late reject "+oldID);
                    Message reject = DMT.createFNPSwapRejected(oldID);
                    try {
                        pn.sendAsync(reject, null, this);
                    } catch (NotConnectedException e1) {
                        Logger.normal(this, "Late reject but disconnected from sender: "+pn);
                    }
View Full Code Here

          }
        }
      }
      if(reject) {
        if(logMINOR) Logger.minor(this, "Rejecting "+msg);
            Message rejected = DMT.createFNPSwapRejected(oldID);
            try {
                pn.sendAsync(rejected, null, this);
            } catch (NotConnectedException e1) {
              if(logMINOR) Logger.minor(this, "Lost connection rejecting SwapRequest (locked) from "+pn);
            }
View Full Code Here

     */
    private void spyOnLocations(Message m, boolean ignoreIfOld, boolean swappingWithMe, double myLoc) {

      long[] uids = null;

      Message uidsMessage = m.getSubMessage(DMT.FNPSwapNodeUIDs);
      if(uidsMessage != null) {
        uids = Fields.bytesToLongs(((ShortBuffer) uidsMessage.getObject(DMT.NODE_UIDS)).getData());
      }

        byte[] data = ((ShortBuffer)m.getObject(DMT.DATA)).getData();

        if(data.length < 16 || data.length % 8 != 0) {
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.