Examples of ShortBuffer


Examples of freenet.support.ShortBuffer

  }};
 
  public static Message createUOMFetchDependency(long uid, byte[] hash, long length) {
    Message msg = new Message(UOMFetchDependency);
    msg.set(UID, uid);
    msg.set(EXPECTED_HASH, new ShortBuffer(hash));
    msg.set(FILE_LENGTH, length);
    return msg;
  }
View Full Code Here

Examples of freenet.support.ShortBuffer

    addField(NODE_UIDS, ShortBuffer.class);
  }};
 
  public static Message createFNPSwapLocations(long[] uids) {
    Message msg = new Message(FNPSwapNodeUIDs);
    msg.set(NODE_UIDS, new ShortBuffer(Fields.longsToBytes(uids)));
    return msg;
  }
View Full Code Here

Examples of freenet.support.ShortBuffer

    addField(BEST_LOCATIONS_NOT_VISITED, ShortBuffer.class);
  }};
 
  public static Message createFNPBestRoutesNotTaken(byte[] locs) {
    Message msg = new Message(FNPBestRoutesNotTaken);
    msg.set(BEST_LOCATIONS_NOT_VISITED, new ShortBuffer(locs));
    return msg;
  }
View Full Code Here

Examples of freenet.support.ShortBuffer

      if(logMINOR)
        Logger.minor(this, "Already disconnecting "+pn.shortToString());
      return;
    }
    if(sendDisconnectMessage) {
      Message msg = DMT.createFNPDisconnect(remove, purge, -1, new ShortBuffer(new byte[0]));
      try {
        pn.sendAsync(msg, new AsyncMessageCallback() {

          boolean done = false;
View Full Code Here

Examples of freenet.support.ShortBuffer

      if(isStopping) return;
      isStopping = true;
    }

    try {
      Message msg = DMT.createFNPDisconnect(false, false, -1, new ShortBuffer(new byte[0]));
      peers.localBroadcast(msg, true, false, peers.ctrDisconn);
    } catch (Throwable t) {
      try {
        // E.g. if we haven't finished startup
        Logger.error(this, "Failed to tell peers we are going down: "+t, t);
View Full Code Here

Examples of freenet.support.ShortBuffer

  /**
   * Handle a received node to node message
   */
  public void receivedNodeToNodeMessage(Message m, PeerNode src) {
    int type = ((Integer) m.getObject(DMT.NODE_TO_NODE_MESSAGE_TYPE)).intValue();
    ShortBuffer messageData = (ShortBuffer) m.getObject(DMT.NODE_TO_NODE_MESSAGE_DATA);
    receivedNodeToNodeMessage(src, type, messageData, false);
  }
View Full Code Here

Examples of freenet.support.ShortBuffer

      }
      // We claim it in any case
      return true;
    } else if(source.isRealConnection() && spec == DMT.FNPLocChangeNotificationNew) {
      double newLoc = m.getDouble(DMT.LOCATION);
      ShortBuffer buffer = ((ShortBuffer) m.getObject(DMT.PEER_LOCATIONS));
      double[] locs = Fields.bytesToDoubles(buffer.getData());
     
      /**
       * Do *NOT* remove the sanity check below!
       * @see http://archives.freenetproject.org/message/20080718.144240.359e16d3.en.html
       */
 
View Full Code Here

Examples of freenet.support.ShortBuffer

      if(om != null && source instanceof OpennetPeerNode)
        om.purgeOldOpennetPeer((OpennetPeerNode)source);
    }
    // Process parting message
    int type = m.getInt(DMT.NODE_TO_NODE_MESSAGE_TYPE);
    ShortBuffer messageData = (ShortBuffer) m.getObject(DMT.NODE_TO_NODE_MESSAGE_DATA);
    if(messageData.getLength() == 0) return;
    node.receivedNodeToNodeMessage(source, type, messageData, true);
  }
View Full Code Here

Examples of freenet.support.ShortBuffer

  }

  public void addDependency(byte[] expectedHash, File filename) {
    if(logMINOR) Logger.minor(this, "Add dependency: "+filename+" for "+HexUtil.bytesToHex(expectedHash));
    synchronized(dependencies) {
      dependencies.put(new ShortBuffer(expectedHash), filename);
    }
  }
View Full Code Here

Examples of freenet.support.ShortBuffer

 
  static final int MAX_TRANSFERS_PER_PEER = 2;

  public void handleFetchDependency(Message m, final PeerNode source) {
    File data;
    final ShortBuffer buf = (ShortBuffer)m.getObject(DMT.EXPECTED_HASH);
    long length = m.getLong(DMT.FILE_LENGTH);
    long uid = m.getLong(DMT.UID);
    synchronized(dependencies) {
      data = dependencies.get(buf);
    }
    boolean fail = !incrementDependencies(source);
    FileRandomAccessBuffer raf;
    final BulkTransmitter bt;
   
    try {
      if(data != null)
        raf = new FileRandomAccessBuffer(data, true);
      else {
        Logger.error(this, "Dependency with hash "+HexUtil.bytesToHex(buf.getData())+" not found!");
        fail = true;
        raf = null;
      }
    } catch(IOException e) {
      Logger.error(this, "Peer " + source + " asked us for the dependency with hash "+HexUtil.bytesToHex(buf.getData())+" jar, we have downloaded it but " +
              (e instanceof FileNotFoundException ? "don't have the file" : "can't read the file")+
              " even though we did have it when we checked!: " + e, e);
      raf = null;
      fail = true;
    }
   
    PartiallyReceivedBulk prb;
    if(raf != null) {
        long thisLength = raf.size();
        prb = new PartiallyReceivedBulk(updateManager.node.getUSM(), thisLength,
                Node.PACKET_SIZE, raf, true);
        if(length != thisLength) {
            fail = true;
        }
    } else {
        prb = new PartiallyReceivedBulk(updateManager.node.getUSM(), 0,
                Node.PACKET_SIZE, new ByteArrayRandomAccessBuffer(new byte[0]), true);
        fail = true;
    }
   
    try {
      bt = new BulkTransmitter(prb, source, uid, false, updateManager.ctr, true);
    } catch(DisconnectedException e) {
      Logger.error(this, "Peer " + source + " asked us for the dependency with hash "+HexUtil.bytesToHex(buf.getData())+" jar then disconnected", e);
      raf.close();
      decrementDependencies(source);
      return;
    }
   
    if(fail) {
      cancelSend(source, uid);
      decrementDependencies(source);
    } else {
      final FileRandomAccessBuffer r = raf;
      updateManager.node.executor.execute(new Runnable() {
       
        @Override
        public void run() {
          source.incrementUOMSends();
          try {
            bt.send();
          } catch (DisconnectedException e) {
            Logger.normal(this, "Disconnected while sending dependency with hash "+HexUtil.bytesToHex(buf.getData())+" to "+source);
          } finally {
            source.decrementUOMSends();
            decrementDependencies(source);
            r.close();
          }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.