Package freenet.keys

Examples of freenet.keys.CHKBlock


      if(needPubKey) {
        Message pk = DMT.createFNPSSKPubKey(uid, block.getPubKey(), realTimeFlag);
        source.sendAsync(pk, null, senderCounter);
      }
    } else {
      CHKBlock block = node.fetch((NodeCHK)key, false, false, false, false, true, null);
      if(block == null) {
        // Don't have the key
        source.sendAsync(DMT.createFNPGetOfferedKeyInvalid(uid, DMT.GET_OFFERED_KEY_REJECTED_NO_KEY), null, senderCounter);
        tag.unlockHandler();
        return;
      }
      Message df = DMT.createFNPCHKDataFound(uid, block.getRawHeaders());
      source.sendAsync(df, null, senderCounter);
          PartiallyReceivedBlock prb =
            new PartiallyReceivedBlock(Node.PACKETS_IN_BLOCK, Node.PACKET_SIZE, block.getRawData());
          final BlockTransmitter bt =
            new BlockTransmitter(node.usm, node.getTicker(), source, uid, prb, senderCounter, BlockTransmitter.NEVER_CASCADE,
                new BlockTransmitterCompletion() {

          @Override
View Full Code Here


          // Ignore
        }
      }
      }
   
    CHKBlock block = verify();
    // If we wanted to reduce latency at the cost of security (bug 3338), we'd commit here, or even on the receiver thread.
   
        // Wait for completion
        boolean sentCompletionWasSet;
        synchronized(sentCompletionLock) {
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;
            try {
                if(!canCommit) return null;
                if(!prb.allReceived()) return null;
                block = new CHKBlock(prb.getBlock(), headers, key);
            } catch (CHKVerifyException e) {
              Logger.error(this, "Verify failed in CHKInsertHandler: "+e+" - headers: "+HexUtil.bytesToHex(headers), e);
                toSend = DMT.createFNPDataInsertRejected(uid, DMT.DATA_INSERT_REJECTED_VERIFY_FAILED);
            } catch (AbortedException e) {
              Logger.error(this, "Receive failed: "+e);
View Full Code Here

        public boolean send(NodeClientCore node, final RequestScheduler sched, ClientContext context,
                final ChosenBlock request) {
            final BlockInsert token = (BlockInsert) request.token;
            try {
                ClientCHKBlock clientBlock = token.segment.encodeBlock(token.blockNumber);
                CHKBlock block = clientBlock.getBlock();
                final ClientCHK key = (ClientCHK) clientBlock.getClientKey();
                context.getJobRunner(request.isPersistent()).queueNormalOrDrop(new PersistentJob() {
                   
                    @Override
                    public boolean run(ClientContext context) {
View Full Code Here

            Node randomNode = nodes[node1];
            String dataString = baseString + i;
            byte[] data = dataString.getBytes("UTF-8");
            ClientCHKBlock b;
            b = ClientCHKBlock.encode(data, false, false, (short)-1, 0, COMPRESSOR_TYPE.DEFAULT_COMPRESSORDESCRIPTOR, false);
            CHKBlock block = b.getBlock();
            ClientCHK chk = b.getClientKey();
            byte[] encData = block.getData();
            byte[] encHeaders = block.getHeaders();
            ClientCHKBlock newBlock = new ClientCHKBlock(encData, encHeaders, chk, true);
            keys[i] = chk;
            Logger.minor(RealNodeRequestInsertTest.class, "Decoded: "+new String(newBlock.memoryDecode(), "UTF-8"));
            Logger.normal(RealNodeRequestInsertTest.class,"CHK: "+chk.getURI());
            Logger.minor(RealNodeRequestInsertTest.class,"Headers: "+HexUtil.bytesToHex(block.getHeaders()));
            // Insert it.
      try {
        randomNode.clientCore.realPut(block, false, FORK_ON_CACHEABLE, false, false, REAL_TIME_FLAG);
        Logger.error(RealNodeRequestInsertTest.class, "Inserted to "+node1);
        Logger.minor(RealNodeRequestInsertTest.class, "Data: "+Fields.hashCode(encData)+", Headers: "+Fields.hashCode(encHeaders));
View Full Code Here

  public CHKBlock fetch(NodeCHK key, boolean dontPromote, boolean canReadClientCache, boolean canWriteClientCache, boolean canWriteDatastore, boolean forULPR, BlockMetadata meta) {
    double loc=key.toNormalizedDouble();
    double dist=Location.distance(lm.getLocation(), loc);
    if(canReadClientCache) {
      try {
        CHKBlock block = chkClientcache.fetch(key, dontPromote || !canWriteClientCache, false, meta);
        if(block != null) {
          nodeStats.avgClientCacheCHKSuccess.report(loc);
          if (dist > nodeStats.furthestClientCacheCHKSuccess)
          nodeStats.furthestClientCacheCHKSuccess=dist;
          return block;
        }
      } catch (IOException e) {
        Logger.error(this, "Could not read from client cache: "+e, e);
      }
    }
    if(forULPR || useSlashdotCache || canReadClientCache) {
      try {
        CHKBlock block = chkSlashdotcache.fetch(key, dontPromote, false, meta);
        if(block != null) {
          nodeStats.avgSlashdotCacheCHKSucess.report(loc);
          if (dist > nodeStats.furthestSlashdotCacheCHKSuccess)
          nodeStats.furthestSlashdotCacheCHKSuccess=dist;
          return block;
        }
      } catch (IOException e) {
        Logger.error(this, "Could not read from slashdot/ULPR cache: "+e, e);
      }
    }
    boolean ignoreOldBlocks = !writeLocalToDatastore;
    if(canReadClientCache) ignoreOldBlocks = false;
    if(logMINOR) dumpStoreHits();
    try {
      nodeStats.avgRequestLocation.report(loc);
      CHKBlock block = chkDatastore.fetch(key, dontPromote || !canWriteDatastore, ignoreOldBlocks, meta);
      if(block == null) {
        CHKStore store = oldCHK;
        if(store != null)
          block = store.fetch(key, dontPromote || !canWriteDatastore, ignoreOldBlocks, meta);
      }
View Full Code Here

    getPubKey.cacheKey(clientSSK.pubKeyHash, key, false, canWriteClientCache, canWriteDatastore, false, writeLocalToDatastore);
    return ClientSSKBlock.construct(block, clientSSK);
  }

  private ClientKeyBlock fetch(ClientCHK clientCHK, boolean canReadClientCache, boolean canWriteClientCache, boolean canWriteDatastore) throws CHKVerifyException {
    CHKBlock block = fetch(clientCHK.getNodeCHK(), false, canReadClientCache, canWriteClientCache, canWriteDatastore, false, null);
    if(block == null) return null;
    return new ClientCHKBlock(block, clientCHK);
  }
View Full Code Here

    ClientCHKBlock block = encodeBlock(test, newFormat);
    store.put(block.getBlock(), false);

    ClientCHK key = block.getClientKey();

    CHKBlock verify = store.fetch(key.getNodeCHK(), false, false, null);
    String data = decodeBlock(verify, key);
    assertEquals(test, data);
  }
View Full Code Here

    ClientCHKBlock block = encodeBlock(test, false);
    store.put(block.getBlock(), true);

    ClientCHK key = block.getClientKey();

    CHKBlock verify = store.fetch(key.getNodeCHK(), false, false, null);
    String data = decodeBlock(verify, key);
    assertEquals(test, data);
   
    // ignoreOldBlocks works.
    assertEquals(null, store.fetch(key.getNodeCHK(), false, true, null));
View Full Code Here

      ClientCHKBlock block = encodeBlock(test, newFormat);
      store.put(block.getBlock(), false);
     
      ClientCHK key = block.getClientKey();
     
      CHKBlock verify = store.fetch(key.getNodeCHK(), false, false, null);
      String data = decodeBlock(verify, key);
      assertEquals(test, data);
    }
   
    saltStore.close();
View Full Code Here

TOP

Related Classes of freenet.keys.CHKBlock

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.