Package freenet.io.comm

Examples of freenet.io.comm.Message


    long id = m.getLong(DMT.UID);
        boolean realTimeFlag = DMT.getRealTimeFlag(m);
    InsertTag tag = new InsertTag(isSSK, InsertTag.START.REMOTE, source, realTimeFlag, id, node);
    if(!tracker.lockUID(id, isSSK, true, false, false, realTimeFlag, tag)) {
      if(logMINOR) Logger.minor(this, "Could not lock ID "+id+" -> rejecting (already running)");
      Message rejected = DMT.createFNPRejectedLoop(id);
      try {
        source.sendAsync(rejected, null, ctr);
      } catch (NotConnectedException e) {
        Logger.normal(this, "Rejecting insert request from "+source.getPeer()+": "+e);
      }
      return;
    }
    boolean preferInsert = Node.PREFER_INSERT_DEFAULT;
    boolean ignoreLowBackoff = Node.IGNORE_LOW_BACKOFF_DEFAULT;
    boolean forkOnCacheable = Node.FORK_ON_CACHEABLE_DEFAULT;
    Message forkControl = m.getSubMessage(DMT.FNPSubInsertForkControl);
    if(forkControl != null)
      forkOnCacheable = forkControl.getBoolean(DMT.ENABLE_INSERT_FORK_WHEN_CACHEABLE);
    Message lowBackoff = m.getSubMessage(DMT.FNPSubInsertIgnoreLowBackoff);
    if(lowBackoff != null)
      ignoreLowBackoff = lowBackoff.getBoolean(DMT.IGNORE_LOW_BACKOFF);
    Message preference = m.getSubMessage(DMT.FNPSubInsertPreferInsert);
    if(preference != null)
      preferInsert = preference.getBoolean(DMT.PREFER_INSERT);
    // SSKs don't fix bwlimitDelayTime so shouldn't be accepted when overloaded.
    RejectReason rejectReason = nodeStats.shouldRejectRequest(!isSSK, true, isSSK, false, false, source, false, preferInsert, realTimeFlag, tag);
    if(rejectReason != null) {
      Logger.normal(this, "Rejecting insert from "+source.getPeer()+" preemptively because "+rejectReason);
      Message rejected = DMT.createFNPRejectedOverload(id, true, true, realTimeFlag);
      if(rejectReason.soft)
        rejected.addSubMessage(DMT.createFNPRejectIsSoft());
      try {
        source.sendAsync(rejected, null, ctr);
      } catch (NotConnectedException e) {
        Logger.normal(this, "Rejecting (overload) insert request from "+source.getPeer()+": "+e);
      }
View Full Code Here


    // Only accept a valid message. See comments at top of NodeDispatcher, but it's a good idea anyway.
    if(target < 0.0 || target >= 1.0 || htl <= 0 ||
        paddedLength < 0 || paddedLength > OpennetManager.MAX_OPENNET_NODEREF_LENGTH ||
        noderefLength > paddedLength) {
      Message msg = DMT.createFNPRejectedOverload(uid, true, false, false);
      try {
        source.sendAsync(msg, null, node.nodeStats.announceByteCounter);
      } catch (NotConnectedException e) {
        // OK
      }
      if(logMINOR) Logger.minor(this, "Got bogus announcement message from "+source);
      return true;
    }
   
    OpennetManager om = node.getOpennet();
    if(om == null || !source.canAcceptAnnouncements()) {
      if(om != null && source instanceof SeedClientPeerNode)
        om.seedTracker.rejectedAnnounce((SeedClientPeerNode)source);
      Message msg = DMT.createFNPOpennetDisabled(uid);
      try {
        source.sendAsync(msg, null, node.nodeStats.announceByteCounter);
      } catch (NotConnectedException e) {
        // OK
      }
      if(logMINOR) Logger.minor(this, "Rejected announcement (opennet or announcement disabled) from "+source);
      return true;
    }
    boolean success = false;
    try {
      // UIDs for announcements are separate from those for requests.
      // So we don't need to, and should not, ask Node.
      if(!node.nodeStats.shouldAcceptAnnouncement(uid)) {
        if(om != null && source instanceof SeedClientPeerNode)
          om.seedTracker.rejectedAnnounce((SeedClientPeerNode)source);
        Message msg = DMT.createFNPRejectedOverload(uid, true, false, false);
        try {
          source.sendAsync(msg, null, node.nodeStats.announceByteCounter);
        } catch (NotConnectedException e) {
          // OK
        }
        if(logMINOR) Logger.minor(this, "Rejected announcement (overall overload) from "+source);
        return true;
      }
      if(!source.shouldAcceptAnnounce(uid)) {
        if(om != null && source instanceof SeedClientPeerNode)
          om.seedTracker.rejectedAnnounce((SeedClientPeerNode)source);
        node.nodeStats.endAnnouncement(uid);
        Message msg = DMT.createFNPRejectedOverload(uid, true, false, false);
        try {
          source.sendAsync(msg, null, node.nodeStats.announceByteCounter);
        } catch (NotConnectedException e) {
          // OK
        }
        if(logMINOR) Logger.minor(this, "Rejected announcement (peer limit) from "+source);
        return true;
      }
      if(om != null && source instanceof SeedClientPeerNode) {
        if(!om.seedTracker.acceptAnnounce((SeedClientPeerNode)source, node.fastWeakRandom)) {
          node.nodeStats.endAnnouncement(uid);
          Message msg = DMT.createFNPRejectedOverload(uid, true, false, false);
          try {
            source.sendAsync(msg, null, node.nodeStats.announceByteCounter);
          } catch (NotConnectedException e) {
            // OK
          }
View Full Code Here

      // Handle locally
      // Message type specific processing
      dispatchRoutedMessage(m, source, id);
      return true;
    } else if(htl == 0) {
      Message reject = DMT.createFNPRoutedRejected(id, (short)0);
      if(source != null) try {
        source.sendAsync(reject, null, nodeStats.routedMessageCtr);
      } catch (NotConnectedException e) {
        if(logMINOR) Logger.minor(this, "Lost connection rejecting "+m);
      }
View Full Code Here

          continue;
        }
      } else {
        if(logMINOR) Logger.minor(this, "Reached dead end for "+m.getSpec()+" on "+node.getDarknetPortNumber());
        // Reached a dead end...
        Message reject = DMT.createFNPRoutedRejected(id, htl);
        if(pn != null) try {
          pn.sendAsync(reject, null, nodeStats.routedMessageCtr);
        } catch (NotConnectedException e) {
          Logger.error(this, "Cannot send reject message back to source "+pn);
          return true;
View Full Code Here

   */
  private boolean dispatchRoutedMessage(Message m, PeerNode src, long id) {
    if(m.getSpec() == DMT.FNPRoutedPing) {
      if(logMINOR) Logger.minor(this, "RoutedPing reached other side! ("+id+")");
      int x = m.getInt(DMT.COUNTER);
      Message reply = DMT.createFNPRoutedPong(id, x);
      if(logMINOR) Logger.minor(this, "Replying - counter = "+x+" for "+id);
      try {
        src.sendAsync(reply, null, nodeStats.routedMessageCtr);
      } catch (NotConnectedException e) {
        if(logMINOR) Logger.minor(this, "Lost connection replying to "+m+" in dispatchRoutedMessage");
View Full Code Here

        }
        timeLastSentAllocationNotice = now;
        countAllocationNotices++;
        if(logMINOR) Logger.minor(this, "Sending allocation notice to "+this+" allocation is "+lastSentAllocationInput+" input "+lastSentAllocationOutput+" output.");
      }
      Message msg = DMT.createFNPPeerLoadStatus(stats);
      return msg;
    }
View Full Code Here

    }

    @Override
    public void processDecryptedMessage(byte[] data, int offset,
        int length, int overhead) {
      Message m = node.usm.decodeSingleMessage(data, offset, length, PeerNode.this, overhead);
      if(m == null) {
        if(logMINOR) Logger.minor(this, "Message not decoded from "+PeerNode.this+" ("+PeerNode.this.getVersionNumber()+")");
        return;
      }
      if(DMT.isPeerLoadStatusMessage(m)) {
View Full Code Here

      disableRouting = disableRoutingHasBeenSetLocally || disableRoutingHasBeenSetRemotely;
    }

    if(localRequest) {
      Message msg = DMT.createRoutingStatus(shouldRoute);
      try {
        sendAsync(msg, null, node.nodeStats.setRoutingStatusCtr);
      } catch(NotConnectedException e) {
      // ok
      }
View Full Code Here

      return false;
    } else if(extraPeerDataType == Node.EXTRA_PEER_DATA_TYPE_QUEUED_TO_SEND_N2NM) {
      boolean sendSuccess = false;
      int type = fs.getInt("n2nType");
      if(isConnected()) {
        Message n2nm;
        if(fs.get("extraPeerDataType") != null) {
          fs.removeValue("extraPeerDataType");
        }
        if(fs.get("senderFileNumber") != null) {
          fs.removeValue("senderFileNumber");
View Full Code Here

      return false;
    }
    System.arraycopy(noderef, 0, padded, 0, noderef.length);
    Util.randomBytes(node.fastWeakRandom, padded, noderef.length, padded.length-noderef.length);
    long xferUID = node.random.nextLong();
    Message msg2 = isReply ? DMT.createFNPOpennetConnectReplyNew(uid, xferUID, noderef.length, padded.length) :
      DMT.createFNPOpennetConnectDestinationNew(uid, xferUID, noderef.length, padded.length);
    peer.sendAsync(msg2, null, ctr);
    return innerSendOpennetRef(xferUID, padded, peer, ctr, cb);
  }
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.