/** Return true if this is the same block as the other ClientSSKBlock, *and* it is the same key */ @Override public boolean equals(Object o) { if(!(o instanceof ClientSSKBlock)) return false; ClientSSKBlock block = (ClientSSKBlock) o; if(!key.equals(block.key)) return false; return this.block.equals(block.block); }
@Override public Key getKey() { return block.getKey(); }
public static ClientSSKBlock construct(SSKBlock block, ClientSSK key) throws SSKVerifyException { // Constructor expects clientkey to have the pubkey. // In the case of binary blobs, the block may have it instead. if(key.getPubKey() == null) key.setPublicKey(block.getPubKey()); return new ClientSSKBlock(block.data, block.headers, key, false); }
public void put(SSKBlock b, boolean overwrite, boolean isOldBlock) throws IOException, KeyCollisionException { store.put(b, b.getRawData(), b.getRawHeaders(), overwrite, isOldBlock); }
SSKInsertSender(SSKBlock block, long uid, InsertTag tag, short htl, PeerNode source, Node node, boolean fromStore, boolean canWriteClientCache, boolean forkOnCacheable, boolean preferInsert, boolean ignoreLowBackoff, boolean realTimeFlag) { super(block.getKey(), realTimeFlag, source, node, htl, uid); this.fromStore = fromStore; this.origUID = uid; this.origTag = tag; myKey = block.getKey(); data = block.getRawData(); headers = block.getRawHeaders(); pubKey = myKey.getPubKey(); if(pubKey == null) throw new IllegalArgumentException("Must have pubkey to insert data!!"); // pubKey.fingerprint() is not the same as hash(pubKey.asBytes())). FIXME it should be! byte[] pubKeyAsBytes = pubKey.asBytes(); pubKeyHash = SHA256.digest(pubKeyAsBytes); this.block = block; startTime = System.currentTimeMillis(); this.forkOnCacheable = forkOnCacheable; this.preferInsert = preferInsert; this.ignoreLowBackoff = ignoreLowBackoff; this.realTimeFlag = realTimeFlag; }
ClientSSKBlock block = ik.encode(bucket, false, false, (short)-1, bucket.size(), random, Compressor.DEFAULT_COMPRESSORDESCRIPTOR, false); SSKBlock sskBlock = (SSKBlock) block.getBlock(); pubkeyCache.cacheKey(sskBlock.getKey().getPubKeyHash(), sskBlock.getPubKey(), false, false, false, false, false); try { store.put(sskBlock, false, false); block = ik2.encode(bucket, false, false, (short)-1, bucket.size(), random, Compressor.DEFAULT_COMPRESSORDESCRIPTOR, false); SSKBlock sskBlock2 = (SSKBlock) block.getBlock(); pubkeyCache.cacheKey(sskBlock2.getKey().getPubKeyHash(), sskBlock2.getPubKey(), false, false, false, false, false); assertTrue(store.fetch(sskBlock.getKey(), false, false, false, false, null).equals(sskBlock)); assertTrue(store.fetch(sskBlock2.getKey(), false, false, false, false, null).equals(sskBlock2));
block = new SSKBlock(data, headers, key, false); } catch (SSKVerifyException e1) { Logger.error(this, "Invalid SSK from "+source, e1); if((storedBlock != null) && !storedBlock.equals(block)) { try { RequestHandler.sendSSK(storedBlock.getRawHeaders(), storedBlock.getRawData(), false, pubKey, source, uid, this, realTimeFlag); } catch (NotConnectedException e1) { if(logMINOR) Logger.minor(this, "Lost connection to source on "+uid); collided = true; try { block = new SSKBlock(data, headers, key, true); } catch (SSKVerifyException e1) {
final Message data = DMT.createFNPSSKDataFoundData(uid, block.getRawData(), realTimeFlag); Message headers = DMT.createFNPSSKDataFoundHeaders(uid, block.getRawHeaders(), realTimeFlag); final int dataLength = block.getRawData().length; Message pk = DMT.createFNPSSKPubKey(uid, block.getPubKey(), realTimeFlag); source.sendAsync(pk, null, senderCounter);
long startTime = System.currentTimeMillis(); SSKBlock altBlock = node.fetch(block.getKey(), false, true, canWriteClientCache, false, false, null); if(altBlock != null && !altBlock.equals(block)) throw new LowLevelPutException(altBlock); is = node.makeInsertSender(block, requestStarters.requestCompleted(true, true, block.getKey(), realTimeFlag); requestStarters.getThrottle(true, true, realTimeFlag).successfulCompletion(rtt); boolean deep = node.shouldStoreDeep(block.getKey(), null, is == null ? new PeerNode[0] : is.getRoutedTo()); } 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) {
ClientSSKBlock block = ik.encode(bucket, false, false, (short)-1, bucket.size(), random, Compressor.DEFAULT_COMPRESSORDESCRIPTOR, false); SSKBlock sskBlock = (SSKBlock) block.getBlock(); pubkeyCache.cacheKey(sskBlock.getKey().getPubKeyHash(), sskBlock.getPubKey(), false, false, false, false, false); try { store.put(sskBlock, false, false);
block = new SSKBlock(sskData, headers, (NodeSSK)key, false); node.storeShallow(block, canWriteClientCache, canWriteDatastore, false); if(node.random.nextInt(RANDOM_REINSERT_INTERVAL) == 0) block = node.fetch((NodeSSK)key, false, canWriteClientCache, canWriteClientCache, canWriteDatastore, false, null); if(block != null) { headers = block.getRawHeaders(); sskData = block.getRawData();
public ClientSSKBlock(byte[] data, byte[] headers, ClientSSK key, boolean dontVerify) throws SSKVerifyException { block = new SSKBlock(data, headers, (NodeSSK) key.getNodeKey(true), dontVerify); this.key = key; }
@Override public int hashCode() { return block.hashCode() ^ key.hashCode(); }
ClientSSKBlock block = ik.encode(bucket, false, false, (short)-1, bucket.size(), random, Compressor.DEFAULT_COMPRESSORDESCRIPTOR, false); SSKBlock sskBlock = (SSKBlock) block.getBlock(); pubkeyCache.cacheKey(sskBlock.getKey().getPubKeyHash(), sskBlock.getPubKey(), false, false, false, false, false); try { store.put(sskBlock, false, false); NodeSSK key = sskBlock.getKey(); assertTrue(saltStore.fetch(key.getRoutingKey(), key.getFullKey(), false, false, false, false, null).equals(sskBlock)); assertTrue(store.fetch(key, false, false, false, false, null).equals(sskBlock2)); assertTrue(store.fetch(key, false, false, false, false, null).equals(sskBlock2));
public static KeyBlock createBlock(short keyType, byte[] keyBytes, byte[] headersBytes, byte[] dataBytes, byte[] pubkeyBytes) throws KeyVerifyException { byte type = (byte)(keyType >> 8); byte subtype = (byte)(keyType & 0xFF); if(type == NodeCHK.BASE_TYPE) { // For CHKs, the subtype is the crypto algorithm. return CHKBlock.construct(dataBytes, headersBytes, subtype); } else if(type == NodeSSK.BASE_TYPE) { DSAPublicKey pubKey; try { pubKey = new DSAPublicKey(pubkeyBytes); } catch (IOException e) { throw new KeyVerifyException("Failed to construct pubkey: "+e, e); } catch (CryptFormatException e) { throw new KeyVerifyException("Failed to construct pubkey: "+e, e); } NodeSSK key = new NodeSSK(pubKey.asBytesHash(), keyBytes, pubKey, subtype); return new SSKBlock(dataBytes, headersBytes, key, false); } else { throw new KeyVerifyException("No such key type "+Integer.toHexString(type)); } }
@Override public byte[] getFullKey() { return getKey().getFullKey(); }
T oldBlock = oldEntry.getStorableBlock(routingKey, fullKey, false, false, null, (block instanceof SSKBlock) ? ((SSKBlock)block).getPubKey() : null); if (block.equals(oldBlock)) { if(logDEBUG) Logger.debug(this, "Block already stored");
@Override public SSKBlock construct(byte[] data, byte[] headers, byte[] routingKey, byte[] fullKey, boolean canReadClientCache, boolean canReadSlashdotCache, BlockMetadata meta, DSAPublicKey knownPublicKey) throws SSKVerifyException { if(data == null || headers == null) throw new SSKVerifyException("Need data and headers"); if(fullKey == null) throw new SSKVerifyException("Need full key to reconstruct an SSK"); NodeSSK key; key = NodeSSK.construct(fullKey); if(knownPublicKey != null) key.setPubKey(knownPublicKey); else if(!key.grabPubkey(pubkeyCache, canReadClientCache, canReadSlashdotCache, meta)) throw new SSKVerifyException("No pubkey found"); SSKBlock block = new SSKBlock(data, headers, key, false); return block; }
@Override public byte[] getRoutingKey() { return getKey().getRoutingKey(); }