Examples of KeyBlock


Examples of freenet.keys.KeyBlock

        try {
          node.storeInsert(block, deep, false, canWriteClientCache, false);
        } catch(KeyCollisionException e) {
          LowLevelPutException failed = new LowLevelPutException(LowLevelPutException.COLLISION);
          NodeSSK key = block.getKey();
          KeyBlock collided = node.fetch(key, true, canWriteClientCache, false, false, null);
          if(collided == null) {
            Logger.error(this, "Collided but no key?!");
            // Could be a race condition.
            try {
              node.store(block, false, canWriteClientCache, false, false);
View Full Code Here

Examples of freenet.keys.KeyBlock

    }

    ArrayList<MySendableInsert> myInserters = new ArrayList<MySendableInsert>();
    int x=0;
    for(Key key: blocks.keys()) {
      KeyBlock block = blocks.get(key);
      MySendableInsert inserter =
        new MySendableInsert(x++, block, prioClass, getScheduler(block, context), clientContext);
      myInserters.add(inserter);
    }
View Full Code Here

Examples of freenet.keys.KeyBlock

        byte[] pubkeyBytes = new byte[pubkeyLen];
        dis.readFully(keyBytes);
        dis.readFully(headersBytes);
        dis.readFully(dataBytes);
        dis.readFully(pubkeyBytes);
        KeyBlock block;
        try {
          block = Key.createBlock(keyType, keyBytes, headersBytes, dataBytes, pubkeyBytes);
        } catch (KeyVerifyException e) {
          throw new BinaryBlobFormatException("Invalid key: "+e.getMessage(), e);
        }
View Full Code Here

Examples of freenet.keys.KeyBlock

        if(random.nextInt(RESET_COUNTER) < KILL_BLOCKS) {
          anyValid = true;
          continue;
        }
      }
      KeyBlock block;
      if(blocks != null)
        block = blocks.get(key);
      else
        block = node.fetch(key, true, true, false, false, null);
      if(block != null) {
View Full Code Here

Examples of freenet.keys.KeyBlock

   * @param canWriteDatastore If the request HTL is too high, including if it is local, we
   * cannot write to the datastore.
   * @return A KeyBlock for the key requested or null.
   */
  private KeyBlock makeRequestLocal(Key key, long uid, boolean canReadClientCache, boolean canWriteClientCache, boolean canWriteDatastore, boolean offersOnly) {
    KeyBlock kb = null;

    if (key instanceof NodeCHK) {
      kb = fetch(key, false, canReadClientCache, canWriteClientCache, canWriteDatastore, null);
    } else if (key instanceof NodeSSK) {
      NodeSSK sskKey = (NodeSSK) key;
View Full Code Here

Examples of freenet.keys.KeyBlock

  public Object makeRequestSender(Key key, short htl, long uid, RequestTag tag, PeerNode source, boolean localOnly, boolean ignoreStore, boolean offersOnly, boolean canReadClientCache, boolean canWriteClientCache, boolean realTimeFlag) {
    boolean canWriteDatastore = canWriteDatastoreRequest(htl);
    if(logMINOR) Logger.minor(this, "makeRequestSender("+key+ ',' +htl+ ',' +uid+ ',' +source+") on "+getDarknetPortNumber());
    // In store?
    if(!ignoreStore) {
      KeyBlock kb = makeRequestLocal(key, uid, canReadClientCache, canWriteClientCache, canWriteDatastore, offersOnly);
      if (kb != null)
        return kb;
    }
    if(localOnly) return null;
    if(logMINOR) Logger.minor(this, "Not in store locally");
View Full Code Here

Examples of freenet.keys.KeyBlock

    // 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) {
View Full Code Here

Examples of freenet.keys.KeyBlock

    return blocksByKey.keySet();
  }

  @Override
  public ClientKeyBlock get(ClientKey key) {
    KeyBlock block = get(key.getNodeKey(false));
    if(block == null) return null;
    try {
      return Key.createKeyBlock(key, block);
    } catch (KeyVerifyException e) {
      Logger.error(this, "Caught decoding block with "+key+" : "+e, e);
View Full Code Here

Examples of freenet.keys.KeyBlock

    @Override
    public boolean send(NodeClientCore core, RequestScheduler sched, final ClientContext context, final ChosenBlock req) {
      // Ignore keyNum, key, since we're only sending one block.
      ClientKeyBlock encodedBlock;
      KeyBlock b;
      final ClientKey key;
      ClientKey k = null;
      if(SingleBlockInserter.logMINOR) Logger.minor(this, "Starting request");
      BlockItem block = (BlockItem) req.token;
      try {
        try {
          encodedBlock = innerEncode(context.random, block.uri, block.copyBucket, block.isMetadata, block.compressionCodec, block.sourceLength, compressorDescriptor, block.pre1254, block.cryptoAlgorithm, block.cryptoKey);
          b = encodedBlock.getBlock();
        } catch (CHKEncodeException e) {
          throw new LowLevelPutException(LowLevelPutException.INTERNAL_ERROR, e.toString() + ":" + e.getMessage(), e);
        } catch (SSKEncodeException e) {
          throw new LowLevelPutException(LowLevelPutException.INTERNAL_ERROR, e.toString() + ":" + e.getMessage(), e);
        } catch (MalformedURLException e) {
          throw new LowLevelPutException(LowLevelPutException.INTERNAL_ERROR, e.toString() + ":" + e.getMessage(), e);
        } catch (InsertException e) {
          throw new LowLevelPutException(LowLevelPutException.INTERNAL_ERROR, e.toString() + ":" + e.getMessage(), e);
        } catch (IOException e) {
          throw new LowLevelPutException(LowLevelPutException.INTERNAL_ERROR, e.toString() + ":" + e.getMessage(), e);
        } catch (InvalidCompressionCodecException e) {
          throw new LowLevelPutException(LowLevelPutException.INTERNAL_ERROR, e.toString() + ":" + e.getMessage(), e);
        }
        if (b==null) {
          Logger.error(this, "Asked to send empty block", new Exception("error"));
          return false;
        }
        key = encodedBlock.getClientKey();
        k = key;
        context.getJobRunner(block.persistent).queueNormalOrDrop(new PersistentJob() {
           
            @Override
            public boolean run(ClientContext context) {
                orig.onEncode(key, context);
                return true;
            }
           
        });
        if(req.localRequestOnly)
          try {
            core.node.store(b, false, req.canWriteClientCache, true, false);
          } catch (KeyCollisionException e) {
            LowLevelPutException failed = new LowLevelPutException(LowLevelPutException.COLLISION);
            KeyBlock collided = core.node.fetch(k.getNodeKey(), true, req.canWriteClientCache, false, false, null);
            if(collided == null) {
              Logger.error(this, "Collided but no key?!");
              // Could be a race condition.
              try {
                core.node.store(b, false, req.canWriteClientCache, true, false);
              } catch (KeyCollisionException e2) {
                Logger.error(this, "Collided but no key and still collided!");
                throw new LowLevelPutException(LowLevelPutException.INTERNAL_ERROR, "Collided, can't find block, but still collides!", e);
              }
            }
           
            failed.setCollidedBlock(collided);
            throw failed;
          }
        else
          core.realPut(b, req.canWriteClientCache, req.forkOnCacheable, Node.PREFER_INSERT_DEFAULT, Node.IGNORE_LOW_BACKOFF_DEFAULT, req.realTimeFlag);
      } catch (LowLevelPutException e) {
        if(logMINOR) Logger.minor(this, "Caught "+e, e);
        if(e.code == LowLevelPutException.COLLISION) {
          // Collision
          try {
            ClientSSKBlock collided = ClientSSKBlock.construct(((SSKBlock)e.getCollidedBlock()), (ClientSSK)k);
            byte[] data = collided.memoryDecode(true);
            byte[] inserting = BucketTools.toByteArray(block.copyBucket);
            if(collided.isMetadata() == block.isMetadata && collided.getCompressionCodec() == block.compressionCodec && Arrays.equals(data, inserting)) {
              if(SingleBlockInserter.logMINOR) Logger.minor(this, "Collided with identical data");
              req.onInsertSuccess(k, context);
              return true;
            } else {
              if(SingleBlockInserter.logMINOR) Logger.minor(this, "Apparently real collision: collided.isMetadata="+collided.isMetadata()+" block.isMetadata="+block.isMetadata+
                  " collided.codec="+collided.getCompressionCodec()+" block.codec="+block.compressionCodec+
                  " collided.datalength="+data.length+" block.datalength="+inserting.length+" H(collided)="+Fields.hashCode(data)+" H(inserting)="+Fields.hashCode(inserting));
            }
          } catch (KeyVerifyException e1) {
            Logger.error(this, "Caught "+e1+" when checking collision!", e1);
          } catch (KeyDecodeException e1) {
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.