Package freenet.keys

Examples of freenet.keys.ClientSSKBlock


    saltStore.start(null, true);
    RandomSource random = new DummyRandomSource(12345);

    for(int i=0;i<5;i++) {
      String test = "test" + i;
      ClientSSKBlock block = encodeBlockSSK(test, random);
      SSKBlock sskBlock = (SSKBlock) block.getBlock();
      store.put(sskBlock, false, false);
      ClientSSK key = block.getClientKey();
      NodeSSK ssk = (NodeSSK) key.getNodeKey();
      pubkeyCache.cacheKey(ssk.getPubKeyHash(), ssk.getPubKey(), false, false, false, false, false);
      SSKBlock verify = store.fetch(ssk, false, false, false, false, null);
      String data = decodeBlockSSK(verify, key);
      assertEquals(test, data);
View Full Code Here


    String docName = "myDOC";
    InsertableClientSSK ik = new InsertableClientSSK(docName, pkHash, pubKey, privKey, ckey, Key.ALGO_AES_PCFB_256_SHA256);
   
    String test = "test";
    SimpleReadOnlyArrayBucket bucket = new SimpleReadOnlyArrayBucket(test.getBytes("UTF-8"));
    ClientSSKBlock block = ik.encode(bucket, false, false, (short)-1, bucket.size(), random, Compressor.DEFAULT_COMPRESSORDESCRIPTOR, false);
    SSKBlock sskBlock = (SSKBlock) block.getBlock();
    store.put(sskBlock, false, false);
   
    //If the block is the same then there should not be a collision
    try {
      store.put(sskBlock, false, false);
      assertTrue(true);
    } catch (KeyCollisionException e) {
      assertTrue(false);
     
    }
   
    String test1 = "test1";
    SimpleReadOnlyArrayBucket bucket1 = new SimpleReadOnlyArrayBucket(test1.getBytes("UTF-8"));
    ClientSSKBlock block1 = ik.encode(bucket1, false, false, (short)-1, bucket1.size(), random, Compressor.DEFAULT_COMPRESSORDESCRIPTOR, false);
    SSKBlock sskBlock1 = (SSKBlock) block1.getBlock();
   
    //if it's different (e.g. different content, same key), there should be a KCE thrown
    try {
      store.put(sskBlock1, false, false);
      assertTrue(false);
    } catch (KeyCollisionException e) {
      assertTrue(true);
    }
   
    // if overwrite is set, then no collision should be thrown
    try {
      store.put(sskBlock1, true, false);
      assertTrue(true);
    } catch (KeyCollisionException e) {
      assertTrue(false);
     
    }
   
    ClientSSK key = block1.getClientKey();
    pubkeyCache.cacheKey(sskBlock.getKey().getPubKeyHash(), sskBlock.getKey().getPubKey(), false, false, false, false, false);
    // Check that it's in the cache, *not* the underlying store.
    NodeSSK ssk = (NodeSSK) key.getNodeKey();
    SSKBlock verify = store.fetch(ssk, false, false, false, false, null);
    String data = decodeBlockSSK(verify, key);
View Full Code Here

   
    saltStore.close();
  }
 
  private String decodeBlockSSK(SSKBlock verify, ClientSSK key) throws SSKVerifyException, KeyDecodeException, IOException {
    ClientSSKBlock cb = ClientSSKBlock.construct(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

    cachingStore.start(null, true);
    RandomSource random = new DummyRandomSource(12345);

    for(int i=0;i<5;i++) {
      String test = "test" + i;
      ClientSSKBlock block = encodeBlockSSK(test, random);
      SSKBlock sskBlock = (SSKBlock) block.getBlock();
      store.put(sskBlock, false, false);
      ClientSSK key = block.getClientKey();
      NodeSSK ssk = (NodeSSK) key.getNodeKey();
      pubkeyCache.cacheKey(ssk.getPubKeyHash(), ssk.getPubKey(), false, false, false, false, false);
      // Check that it's in the cache, *not* the underlying store.
      assertEquals(saltStore.fetch(ssk.getRoutingKey(), ssk.getFullKey(), false, false, false, false, null), null);
      SSKBlock verify = store.fetch(ssk, false, false, false, false, null);
View Full Code Here

    List<ClientSSKBlock> sskBlocks = new ArrayList<ClientSSKBlock>();
    List<String> tests = new ArrayList<String>();

    for(int i=0;i<5;i++) {
      String test = "test" + i;
      ClientSSKBlock block = encodeBlockSSK(test, random);
      SSKBlock sskBlock = (SSKBlock) block.getBlock();
      store.put(sskBlock, false, false);
      pubkeyCache.cacheKey(sskBlock.getKey().getPubKeyHash(), sskBlock.getKey().getPubKey(), false, false, false, false, false);
      tests.add(test);
      sskBlocks.add(block);
    }
   
    cachingStore.close();
   
    SaltedHashFreenetStore<SSKBlock> saltStore2 = SaltedHashFreenetStore.construct(f, "testCachingFreenetStoreOnCloseSSK", store, weakPRNG, 10, false, SemiOrderedShutdownHook.get(), true, true, ticker, null);
    cachingStore = new CachingFreenetStore<SSKBlock>(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
      ClientSSKBlock block = sskBlocks.remove(0); //get the first element
      ClientSSK key = block.getClientKey();
      NodeSSK ssk = (NodeSSK) key.getNodeKey();
      SSKBlock verify = store.fetch(ssk, false, false, false, false, null);
      String data = decodeBlockSSK(verify, key);
      assertEquals(test, data);
    }
View Full Code Here

    List<ClientSSKBlock> sskBlocks = new ArrayList<ClientSSKBlock>();
    List<String> tests = new ArrayList<String>();

    for(int i=0;i<5;i++) {
      String test = "test" + i;
      ClientSSKBlock block = encodeBlockSSK(test, random);
      SSKBlock sskBlock = (SSKBlock) block.getBlock();
      store.put(sskBlock, false, false);
      pubkeyCache.cacheKey(sskBlock.getKey().getPubKeyHash(), sskBlock.getKey().getPubKey(), false, false, false, false, false);
      tests.add(test);
      sskBlocks.add(block);
    }
   
    try {
      Thread.sleep(2*delay);
    } catch (InterruptedException e) {
      // Ignore
    }
   
    for(int i=0;i<5;i++) {
      String test = tests.remove(0); //get the first element
      ClientSSKBlock block = sskBlocks.remove(0); //get the first element
      ClientSSK key = block.getClientKey();
      NodeSSK ssk = (NodeSSK) key.getNodeKey();
      SSKBlock verify = store.fetch(ssk, false, false, false, false, null);
      String data = decodeBlockSSK(verify, key);
      assertEquals(test, data);
    }
View Full Code Here

    String docName = "myDOC";
    InsertableClientSSK ik = new InsertableClientSSK(docName, pkHash, pubKey, privKey, ckey, Key.ALGO_AES_PCFB_256_SHA256);
   
    String test = "test";
    SimpleReadOnlyArrayBucket bucket = new SimpleReadOnlyArrayBucket(test.getBytes("UTF-8"));
    ClientSSKBlock block = ik.encode(bucket, false, false, (short)-1, bucket.size(), random, Compressor.DEFAULT_COMPRESSORDESCRIPTOR, false);
    SSKBlock sskBlock = (SSKBlock) block.getBlock();
    store.put(sskBlock, false, false);
   
    //If the block is the same then there should not be a collision
    try {
      store.put(sskBlock, false, false);
      assertTrue(true);
    } catch (KeyCollisionException e) {
      assertTrue(false);
     
    }
   
    String test1 = "test1";
    SimpleReadOnlyArrayBucket bucket1 = new SimpleReadOnlyArrayBucket(test1.getBytes("UTF-8"));
    ClientSSKBlock block1 = ik.encode(bucket1, false, false, (short)-1, bucket1.size(), random, Compressor.DEFAULT_COMPRESSORDESCRIPTOR, false);
    SSKBlock sskBlock1 = (SSKBlock) block1.getBlock();
   
    //if it's different (e.g. different content, same key), there should be a KCE thrown
    try {
      store.put(sskBlock1, false, false);
      assertTrue(false);
    } catch (KeyCollisionException e) {
      assertTrue(true);
    }
   
    // if overwrite is set, then no collision should be thrown
    try {
      store.put(sskBlock1, true, false);
      assertTrue(true);
    } catch (KeyCollisionException e) {
      assertTrue(false);
     
    }
   
    ClientSSK key = block1.getClientKey();
    pubkeyCache.cacheKey(sskBlock.getKey().getPubKeyHash(), sskBlock.getKey().getPubKey(), false, false, false, false, false);
    // Check that it's in the cache, *not* the underlying store.
    NodeSSK ssk = (NodeSSK) key.getNodeKey();
    SSKBlock verify = store.fetch(ssk, false, false, false, false, null);
    String data = decodeBlockSSK(verify, key);
View Full Code Here

   
    cachingStore.close();
  }
 
  private String decodeBlockSSK(SSKBlock verify, ClientSSK key) throws SSKVerifyException, KeyDecodeException, IOException {
    ClientSSKBlock cb = ClientSSKBlock.construct(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

    long lastSlot = uskManager.lookupLatestSlot(origUSK) + 1;
    long edition = watchingKeys.match((NodeSSK)key, lastSlot);
    if(edition == -1) return false;
    if(logMINOR) Logger.minor(this, "Matched edition "+edition+" for "+origUSK);
   
    ClientSSKBlock data;
    try {
      data = watchingKeys.decode((SSKBlock)found, edition);
    } catch (SSKVerifyException e) {
      data = null;
    }
View Full Code Here

      } 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

Related Classes of freenet.keys.ClientSSKBlock

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.