Package freenet.keys

Examples of freenet.keys.ClientCHKBlock


    CachingFreenetStore<CHKBlock> cachingStore = new CachingFreenetStore<CHKBlock>(store, cachingFreenetStoreMaxSize, cachingFreenetStorePeriod, saltStore, ticker);
    cachingStore.start(null, true);

    for(int i=0;i<5;i++) {
      String test = "test" + i;
      ClientCHKBlock block = encodeBlockCHK(test);
      store.put(block.getBlock(), false);
      ClientCHK key = block.getClientKey();
      // Check that it's in the cache, *not* the underlying store.
      assertEquals(saltStore.fetch(key.getRoutingKey(), key.getNodeCHK().getFullKey(), false, false, false, false, null), null);
      CHKBlock verify = store.fetch(key.getNodeCHK(), false, false, null);
      String data = decodeBlockCHK(verify, key);
      assertEquals(test, data);
View Full Code Here


    CachingFreenetStore<CHKBlock> cachingStore = new CachingFreenetStore<CHKBlock>(store, 0, cachingFreenetStorePeriod, saltStore, ticker);
    cachingStore.start(null, true);

    for(int i=0;i<5;i++) {
      String test = "test" + i;
      ClientCHKBlock block = encodeBlockCHK(test);
      store.put(block.getBlock(), false);
      ClientCHK key = block.getClientKey();
      // It should pass straight through.
      assertNotNull(saltStore.fetch(key.getRoutingKey(), key.getNodeCHK().getFullKey(), false, false, false, false, null));
      CHKBlock verify = store.fetch(key.getNodeCHK(), false, false, null);
      String data = decodeBlockCHK(verify, key);
      assertEquals(test, data);
View Full Code Here

    List<ClientCHKBlock> chkBlocks = new ArrayList<ClientCHKBlock>();
    List<String> tests = new ArrayList<String>();

    for(int i=0;i<5;i++) {
      String test = "test" + i;
      ClientCHKBlock block = encodeBlockCHK(test);
      // Check that it's in the cache, *not* the underlying store.
      assertEquals(saltStore.fetch(block.getKey().getRoutingKey(), block.getKey().getFullKey(), false, false, false, false, null), null);
      store.put(block.getBlock(), false);
      tests.add(test);
      chkBlocks.add(block);
    }
   
    cachingStore.close();
   
    SaltedHashFreenetStore<CHKBlock> saltStore2 = SaltedHashFreenetStore.construct(f, "testCachingFreenetStoreOnClose", store, weakPRNG, 10, false, SemiOrderedShutdownHook.get(), true, true, ticker, null);
    cachingStore = new CachingFreenetStore<CHKBlock>(store, cachingFreenetStoreMaxSize, cachingFreenetStorePeriod, saltStore2, ticker);
    cachingStore.start(null, true);

    for(int i=0;i<5;i++) {
      String test = tests.remove(0); //get the first element
      ClientCHKBlock block = chkBlocks.remove(0); //get the first element
      ClientCHK key = block.getClientKey();
      CHKBlock verify = store.fetch(key.getNodeCHK(), false, false, null);
      String data = decodeBlockCHK(verify, key);
      assertEquals(test, data);
    }
   
View Full Code Here

    SaltedHashFreenetStore<CHKBlock> saltStore = SaltedHashFreenetStore.construct(f, "testSaltedHashFreenetStoreCHK", store, weakPRNG, 10, false, SemiOrderedShutdownHook.get(), true, true, ticker, null);
    saltStore.start(null, true);

    for(int i=0;i<5;i++) {
      String test = "test" + i;
      ClientCHKBlock block = encodeBlockCHK(test);
      store.put(block.getBlock(), false);
      ClientCHK key = block.getClientKey();
      CHKBlock verify = store.fetch(key.getNodeCHK(), false, false, null);
      String data = decodeBlockCHK(verify, key);
      assertEquals(test, data);
    }
   
View Full Code Here

   
    saltStore.close();
  }

  private String decodeBlockCHK(CHKBlock verify, ClientCHK key) throws CHKVerifyException, CHKDecodeException, IOException {
    ClientCHKBlock cb = new ClientCHKBlock(verify, key);
    Bucket output = cb.decode(new ArrayBucketFactory(), 32768, false);
    byte[] buf = BucketTools.toByteArray(output);
    return new String(buf, "UTF-8");
  }
View Full Code Here

    List<String> tests = new ArrayList<String>();
   
    // Put five chk blocks
    for(int i=0;i<5;i++) {
      String test = "test" + i;
      ClientCHKBlock block = encodeBlockCHK(test);
      store.put(block.getBlock(), false);
      // Check that it's in the cache, *not* the underlying store.
      assertEquals(saltStore.fetch(block.getKey().getRoutingKey(), block.getKey().getFullKey(), false, false, false, false, null), null);
      tests.add(test);
      chkBlocks.add(block);
    }
   
    try {
      Thread.sleep(2*delay);
    } catch (InterruptedException e) {
      // Ignore
    }
   
    //Fetch five chk blocks
    for(int i=0; i<5; i++){
      String test = tests.remove(0); //get the first element
      ClientCHKBlock block = chkBlocks.remove(0); //get the first element
      ClientCHK key = block.getClientKey();
      CHKBlock verify = store.fetch(key.getNodeCHK(), false, false, null);
      String data = decodeBlockCHK(verify, key);
      assertEquals(test, data);
      // Check that it's in the underlying store now.
      assertNotNull(saltStore.fetch(block.getKey().getRoutingKey(), block.getKey().getFullKey(), false, false, false, false, null));
    }
   
    cachingStore.close();
  }
View Full Code Here

   
    cachingStore.close();
  }

  private String decodeBlockCHK(CHKBlock verify, ClientCHK key) throws CHKVerifyException, CHKDecodeException, IOException {
    ClientCHKBlock cb = new ClientCHKBlock(verify, key);
    Bucket output = cb.decode(new ArrayBucketFactory(), 32768, false);
    byte[] buf = BucketTools.toByteArray(output);
    return new String(buf, "UTF-8");
  }
View Full Code Here

   
    int falsePositives = 0;

    for(int i=0;i<testCount;i++) {
      String test = "test" + i;
      ClientCHKBlock block = encodeBlockCHK(test);
      ClientCHK key = block.getClientKey();
      byte[] routingKey = key.getRoutingKey();
      if(saltStore.probablyInStore(routingKey))
        falsePositives++;
      store.put(block.getBlock(), false);
      assertTrue(saltStore.probablyInStore(routingKey));
      CHKBlock verify = store.fetch(key.getNodeCHK(), false, false, null);
      String data = decodeBlockCHK(verify, key);
      assertEquals(test, data);
    }
   
    assertTrue(falsePositives <= acceptableFalsePositives);
   
    for(int i=0;i<testCount;i++) {
      String test = "test" + i;
      ClientCHKBlock block = encodeBlockCHK(test);
      ClientCHK key = block.getClientKey();
      byte[] routingKey = key.getRoutingKey();
      assertTrue(saltStore.probablyInStore(routingKey));
      CHKBlock verify = store.fetch(key.getNodeCHK(), false, false, null);
      String data = decodeBlockCHK(verify, key);
      assertEquals(test, data);
View Full Code Here

   
    int falsePositives = 0;

    for(int i=0;i<TEST_COUNT;i++) {
      String test = "test" + i;
      ClientCHKBlock block = encodeBlockCHK(test);
      ClientCHK key = block.getClientKey();
      byte[] routingKey = key.getRoutingKey();
      if(saltStore.probablyInStore(routingKey))
        falsePositives++;
      store.put(block.getBlock(), false);
      assertTrue(saltStore.probablyInStore(routingKey));
      CHKBlock verify = store.fetch(key.getNodeCHK(), false, false, null);
      String data = decodeBlockCHK(verify, key);
      assertEquals(test, data);
    }
   
    assertTrue(falsePositives <= ACCEPTABLE_FALSE_POSITIVES);
   
    saltStore.close();
    store = new CHKStore();
    saltStore = SaltedHashFreenetStore.construct(f, "testCachingFreenetStoreCHK", store, weakPRNG, STORE_SIZE, true, SemiOrderedShutdownHook.get(), true, true, ticker, null);
    saltStore.start(null, true);
   
    for(int i=0;i<TEST_COUNT;i++) {
      String test = "test" + i;
      ClientCHKBlock block = encodeBlockCHK(test);
      ClientCHK key = block.getClientKey();
      byte[] routingKey = key.getRoutingKey();
      assertTrue(saltStore.probablyInStore(routingKey));
      CHKBlock verify = store.fetch(key.getNodeCHK(), false, false, null);
      String data = decodeBlockCHK(verify, key);
      assertEquals(test, data);
View Full Code Here

   
    int falsePositives = 0;

    for(int i=0;i<TEST_COUNT;i++) {
      String test = "test" + i;
      ClientCHKBlock block = encodeBlockCHK(test);
      ClientCHK key = block.getClientKey();
      byte[] routingKey = key.getRoutingKey();
      if(saltStore.probablyInStore(routingKey))
        falsePositives++;
      store.put(block.getBlock(), false);
      assertTrue(saltStore.probablyInStore(routingKey));
      CHKBlock verify = store.fetch(key.getNodeCHK(), false, false, null);
      String data = decodeBlockCHK(verify, key);
      assertEquals(test, data);
    }
   
    assertTrue(falsePositives <= ACCEPTABLE_FALSE_POSITIVES);
   
    try {
      Thread.sleep(2*delay);
    } catch (InterruptedException e) {
      // Ignore
    }

    // Abrupt abort. The slots should have been written by now.
    saltStore.close(true);
    store = new CHKStore();
    saltStore = SaltedHashFreenetStore.construct(f, "testCachingFreenetStoreCHK", store, weakPRNG, STORE_SIZE, true, SemiOrderedShutdownHook.get(), true, true, ticker, null);
    saltStore.start(null, true);
   
    for(int i=0;i<TEST_COUNT;i++) {
      String test = "test" + i;
      ClientCHKBlock block = encodeBlockCHK(test);
      ClientCHK key = block.getClientKey();
      byte[] routingKey = key.getRoutingKey();
      assertTrue(saltStore.probablyInStore(routingKey));
      CHKBlock verify = store.fetch(key.getNodeCHK(), false, false, null);
      String data = decodeBlockCHK(verify, key);
      assertEquals(test, data);
View Full Code Here

TOP

Related Classes of freenet.keys.ClientCHKBlock

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.