Package freenet.keys

Examples of freenet.keys.Key


    if(logMINOR) Logger.minor(this, "Found "+block.getKey());
    if(!(node.enableULPRDataPropagation || node.enablePerNodeFailureTables)) {
      if(logMINOR) Logger.minor(this, "Ignoring onFound because enable ULPR = "+node.enableULPRDataPropagation+" and enable failure tables = "+node.enablePerNodeFailureTables);
      return;
    }
    Key key = block.getKey();
    if(key == null) throw new NullPointerException();
    FailureTableEntry entry;
    synchronized(blockOfferListByKey) {
      blockOfferListByKey.removeKey(key);
    }
View Full Code Here


    return 1;
  }
 
  @Override
  public SendableRequestItem chooseKey(KeysFetchingLocally fetching, ClientContext context) {
    Key k = key.getNodeKey(false);
    if(fetching.hasKey(k, this)) return null;
    long l = fetching.checkRecentlyFailed(k, realTimeFlag);
    long now = System.currentTimeMillis();
    if(l > 0 && l > now) {
      if(maxRetries == -1 || (maxRetries >= RequestScheduler.COOLDOWN_RETRIES)) {
View Full Code Here

    }
    if(key == null) {
      Logger.error(this, "Key is null - left over BSSF? on "+this+" in makeKeyListener()", new Exception("error"));
      return null;
    }
    Key newKey = key.getNodeKey(true);
    if(parent == null) {
      Logger.error(this, "Parent is null on "+this+" persistent="+persistent+" key="+key+" ctx="+ctx);
      return null;
    }
    short prio = parent.getPriorityClass();
View Full Code Here

  @Override
  public synchronized SendableRequestItem chooseKey(KeysFetchingLocally fetching, ClientContext context) {
    assert(keysList.size() == keys.size());
    if(keys.size() == 1) {
      // Shortcut the common case
      Key k = keysList.get(0);
      if(fetching.hasKey(k, null)) return null;
      // Ignore RecentlyFailed because an offered key overrides it.
      keys.remove(k);
      keysList.remove(0);
      keysList.trimToSize();
      return new MySendableRequestItem(k);
    }
    for(int i=0;i<10;i++) {
      // Pick a random key
      if(keysList.isEmpty()) return null;
      int ptr = random.nextInt(keysList.size());
      // Avoid shuffling penalty by swapping the chosen element with the end.
      Key k = keysList.get(ptr);
      if(fetching.hasKey(k, null)) continue;
      // Ignore RecentlyFailed because an offered key overrides it.
      ListUtils.removeBySwapLast(keysList, ptr);
      keys.remove(k);
      assert(keysList.size() == keys.size());
View Full Code Here

  public SendableRequestSender getSender(ClientContext context) {
    return new SendableRequestSender() {

      @Override
      public boolean send(NodeClientCore core, final RequestScheduler sched, ClientContext context, ChosenBlock req) {
        final Key key = ((MySendableRequestItem) req.token).key;
        // Have to cache it in order to propagate it; FIXME
        // Don't let a node force us to start a real request for a specific key.
        // We check the datastore, take up offers if any (on a short timeout), and then quit if we still haven't fetched the data.
        // Obviously this may have a marginal impact on load but it should only be marginal.
        core.asyncGet(key, true, new RequestCompletionListener() {
View Full Code Here

   * Add a block to the binary blob.
   * @throws IOException
   * @throws BinaryBlobAlreadyClosedException
   */
  public synchronized void addKey(ClientKeyBlock block, ClientContext context) throws IOException, BinaryBlobAlreadyClosedException {
    Key key = block.getKey();
    if(_binaryBlobKeysAddedAlready.contains(key)) return;
    BinaryBlob.writeKey(getOutputStream(), block.getBlock(), key);
    _binaryBlobKeysAddedAlready.add(key);
  }
View Full Code Here

        } else {
          block = ClientCHKBlock.encode(buf, false, false, (short)-1, buf.length, COMPRESSOR_TYPE.DEFAULT_COMPRESSORDESCRIPTOR, false);
          insertKey = fetchKey = block.getClientKey();
          testKey = insertKey.getURI();
        }
        final Key nodeKey = fetchKey.getNodeKey(false);
       
        System.err.println();
        System.err.println("Created random test key "+testKey+" = "+nodeKey);
        System.err.println();
        Logger.error(RealNodeULPRTest.class, "Starting ULPR test #"+successfulTests+": "+testKey+" = "+fetchKey+" = "+nodeKey);
       
        waitForAllConnected(nodes);
       
        // Fetch the key from each node.
       
        // Only those nodes which have been asked by another node (not directly here) for the key will want it.
        // Further, only those nodes on the actual DNF path will learn from their mistakes: a RejectedLoop doesn't tell you much.
       
        // Lets track which nodes have been visited.
       
        final boolean[] visited = new boolean[nodes.length];
       
        NodeDispatcherCallback cb = new NodeDispatcherCallback() {

      @Override
      public void snoop(Message m, Node n) {
        if(((!isSSK) && m.getSpec() == DMT.FNPCHKDataRequest) ||
            (isSSK && m.getSpec() == DMT.FNPSSKDataRequest)) {
          Key key = (Key) m.getObject(DMT.FREENET_ROUTING_KEY);
          if(key.equals(nodeKey)) {
            visited[n.getDarknetPortNumber() - DARKNET_PORT_BASE] = true;
          }
        }
      }
         
View Full Code Here

    source.setUptime(uptime);
    return true;
  }

  private boolean handleOfferKey(Message m, PeerNode source) {
    Key key = (Key) m.getObject(DMT.KEY);
    byte[] authenticator = ((ShortBuffer) m.getObject(DMT.OFFER_AUTHENTICATOR)).getData();
    node.failureTable.onOffer(key, source, authenticator);
    return true;
  }
View Full Code Here

    node.failureTable.onOffer(key, source, authenticator);
    return true;
  }

  private boolean handleGetOfferedKey(Message m, PeerNode source) {
    Key key = (Key) m.getObject(DMT.KEY);
    byte[] authenticator = ((ShortBuffer) m.getObject(DMT.OFFER_AUTHENTICATOR)).getData();
    long uid = m.getLong(DMT.UID);
    if(!HMAC.verifyWithSHA256(node.failureTable.offerAuthenticatorKey, key.getFullKey(), authenticator)) {
      Logger.error(this, "Invalid offer request from "+source+" : authenticator did not verify");
      try {
        source.sendAsync(DMT.createFNPGetOfferedKeyInvalid(uid, DMT.GET_OFFERED_KEY_REJECTED_BAD_AUTHENTICATOR), null, node.failureTable.senderCounter);
      } catch (NotConnectedException e) {
        // Too bad.
View Full Code Here

    }
    long id = m.getLong(DMT.UID);
    ByteCounter ctr = isSSK ? node.nodeStats.sskRequestCtr : node.nodeStats.chkRequestCtr;
        short htl = m.getShort(DMT.HTL);
    if(htl <= 0) htl = 1;
        Key key = (Key) m.getObject(DMT.FREENET_ROUTING_KEY);
        boolean realTimeFlag = DMT.getRealTimeFlag(m);
        final RequestTag tag = new RequestTag(isSSK, RequestTag.START.REMOTE, source, realTimeFlag, id, node);
    if(!tracker.lockUID(id, isSSK, false, 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 request from "+source.getPeer()+": "+e);
      }
      node.failureTable.onFinalFailure(key, null, htl, htl, -1, -1, source);
      return;
    } else {
      if(logMINOR) Logger.minor(this, "Locked "+id);
    }
   
    // There are at least 2 threads that call this function.
    // DO NOT reuse the meta object, unless on a per-thread basis.
    // Object allocation is pretty cheap in modern Java anyway...
    // If we do reuse it, call reset().
    BlockMetadata meta = new BlockMetadata();
    KeyBlock block = node.fetch(key, false, false, false, false, meta);
    if(block != null)
      tag.setNotRoutedOnwards();
   
    RejectReason rejectReason = nodeStats.shouldRejectRequest(!isSSK, false, isSSK, false, false, source, block != null, false, realTimeFlag, tag);
    if(rejectReason != null) {
      // can accept 1 CHK request every so often, but not with SSKs because they aren't throttled so won't sort out bwlimitDelayTime, which was the whole reason for accepting them when overloaded...
      Logger.normal(this, "Rejecting "+(isSSK ? "SSK" : "CHK")+" request 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) data request from "+source.getPeer()+": "+e);
      }
      tag.setRejected();
      tag.unlockHandler(rejectReason.soft);
      // Do not tell failure table.
      // Otherwise an attacker can flood us with requests very cheaply and purge our
      // failure table even though we didn't accept any of them.
      return;
    }
    nodeStats.reportIncomingRequestLocation(key.toNormalizedDouble());
    //if(!node.lockUID(id)) return false;
    boolean needsPubKey = false;
    if(key instanceof NodeSSK)
      needsPubKey = m.getBoolean(DMT.NEED_PUB_KEY);
    RequestHandler rh = new RequestHandler(source, id, node, htl, key, tag, block, realTimeFlag, needsPubKey);
View Full Code Here

TOP

Related Classes of freenet.keys.Key

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.