public SSKBlock fetch(NodeSSK chk, boolean dontPromote, boolean canReadClientCache, boolean canReadSlashdotCache, boolean ignoreOldBlocks, BlockMetadata meta) throws IOException { return store.fetch(chk.getRoutingKey(), chk.getFullKey(), dontPromote, canReadClientCache, canReadSlashdotCache, ignoreOldBlocks, meta); }
/** * Fetch or create an SSKInsertSender for a given key/htl. * @param key The key to be inserted. * @param htl The current HTL. We can't coalesce inserts across * HTL's. * @param uid The UID of the caller's request chain, or a new * one. This is obviously not used if there is already an * SSKInsertSender running. * @param source The node that sent the InsertRequest, or null * if it originated locally. * @param ignoreLowBackoff * @param preferInsert */ public SSKInsertSender makeInsertSender(SSKBlock block, short htl, long uid, InsertTag tag, PeerNode source, boolean fromStore, boolean canWriteClientCache, boolean canWriteDatastore, boolean forkOnCacheable, boolean preferInsert, boolean ignoreLowBackoff, boolean realTimeFlag) { NodeSSK key = block.getKey(); if(key.getPubKey() == null) { throw new IllegalArgumentException("No pub key when inserting"); } getPubKey.cacheKey(key.getPubKeyHash(), key.getPubKey(), false, canWriteClientCache, canWriteDatastore, false, writeLocalToDatastore); Logger.minor(this, "makeInsertSender("+key+ ',' +htl+ ',' +uid+ ',' +source+",...,"+fromStore); SSKInsertSender is = null; is = new SSKInsertSender(block, uid, tag, htl, source, this, fromStore, canWriteClientCache, forkOnCacheable, preferInsert, ignoreLowBackoff, realTimeFlag); is.start(); return is; }
@Override public Key cloneKey() { return new NodeSSK(this); }
@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; }
ClientSSK key = block.getClientKey(); NodeSSK ssk = (NodeSSK) key.getNodeKey(); pubkeyCache.cacheKey(ssk.getPubKeyHash(), ssk.getPubKey(), false, false, false, false, false); assertEquals(saltStore.fetch(ssk.getRoutingKey(), ssk.getFullKey(), false, false, false, false, null), null); SSKBlock verify = store.fetch(ssk, false, false, false, false, null); String data = decodeBlockSSK(verify, key);
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); 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));
} else if (key instanceof NodeSSK) { NodeSSK sskKey = (NodeSSK) key; DSAPublicKey pubKey = sskKey.getPubKey(); if (pubKey == null) { pubKey = getPubKey.getKey(sskKey.getPubKeyHash(), canReadClientCache, offersOnly, null); if (logMINOR) Logger.minor(this, "Fetched pubkey: " + pubKey); try { sskKey.setPubKey(pubKey); } catch (SSKVerifyException e) { Logger.error(this, "Error setting pubkey: " + e, e);
double loc = block.getKey().toNormalizedDouble(); getPubKey.cacheKey((block.getKey()).getPubKeyHash(), (block.getKey()).getPubKey(), deep, canWriteClientCache, canWriteDatastore, forULPR || useSlashdotCache, writeLocalToDatastore); if(canWriteClientCache) { sskClientcache.put(block, overwrite, false);
public boolean samePubKeyHash(NodeSSK k) { return Arrays.equals(k.getPubKeyHash(), pubKeyHash); } }
private void realRun() { freenet.support.Logger.OSThread.logPID(this); if(isSSK && (pubKey == null)) { pubKey = ((NodeSSK)key).getPubKey(); } // First ask any nodes that have offered the data final OfferList offers = node.failureTable.getOffers(key); if(offers != null) tryOffers(offers, null, null); else startRequests(); }
if(data.length != DATA_LENGTH) throw new SSKVerifyException("Data length wrong: "+data.length+" should be "+DATA_LENGTH); this.pubKey = nodeKey.getPubKey(); if(pubKey == null) throw new SSKVerifyException("PubKey was null from "+nodeKey); hashCode = Fields.hashCode(data) ^ Fields.hashCode(headers) ^ nodeKey.hashCode() ^ pubKey.hashCode() ^ hashIdentifier;
@Override public byte[] getFullKey() { return getKey().getFullKey(); }
@Override public byte[] getRoutingKey() { return getKey().getRoutingKey(); }
/** Do the actual match, using the current firstSlot, and a specified offset and length within the array. */ private long innerMatch(NodeSSK key, RemoveRangeArrayList<byte[]> ehDocnames, int offset, int size, long firstSlot) { byte[] data = key.getKeyBytes(); for(int i=offset;i<(offset+size);i++) { if(Arrays.equals(data, ehDocnames.get(i))) { if(logMINOR) Logger.minor(this, "Found edition "+(firstSlot+i)+" for "+origUSK); return firstSlot+i; } } return -1; }
@Override public byte[] getFullKey() { byte[] buf = new byte[FULL_KEY_LENGTH]; short type = getType(); buf[0] = (byte) (type >> 8); buf[1] = (byte) (type & 0xFF); System.arraycopy(encryptedHashedDocname, 0, buf, 2, E_H_DOCNAME_SIZE); System.arraycopy(pubKeyHash, 0, buf, 2+E_H_DOCNAME_SIZE, PUBKEY_HASH_SIZE); return buf; }
@Override public boolean equals(Object o) { if(!(o instanceof SSKBlock)) return false; SSKBlock block = (SSKBlock)o; if(!block.pubKey.equals(pubKey)) return false; if(!block.nodeKey.equals(nodeKey)) return false; if(block.headersOffset != headersOffset) return false; if(block.hashIdentifier != hashIdentifier) return false; if(block.symCipherIdentifier != symCipherIdentifier) return false; // only compare some of the headers (see top) for (int i = 0; i < HEADER_COMPARE_TO; i++) { if (block.headers[i] != headers[i]) return false; } //if(!Arrays.equals(block.headers, headers)) return false; if(!Arrays.equals(block.data, data)) return false; return true; }
SSKInsertHandler(NodeSSK key, byte[] data, byte[] headers, short htl, PeerNode source, long id, Node node, long startTime, InsertTag tag, boolean canWriteDatastore, boolean forkOnCacheable, boolean preferInsert, boolean ignoreLowBackoff, boolean realTimeFlag) { this.node = node; this.uid = id; this.source = source; this.startTime = startTime; this.key = key; this.htl = htl; this.data = data; this.headers = headers; this.tag = tag; this.canWriteDatastore = canWriteDatastore; byte[] pubKeyHash = key.getPubKeyHash(); pubKey = node.getPubKey.getKey(pubKeyHash, false, false, null); canCommit = false; logMINOR = Logger.shouldLog(LogLevel.MINOR, this); this.forkOnCacheable = forkOnCacheable; this.preferInsert = preferInsert; this.ignoreLowBackoff = ignoreLowBackoff; this.realTimeFlag = realTimeFlag; }
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; }
public ClientSSKBlock decode(SSKBlock block, long edition) throws SSKVerifyException { ClientSSK csk = origUSK.getSSK(edition); assert(Arrays.equals(csk.ehDocname, block.getKey().getKeyBytes())); return ClientSSKBlock.construct(block, csk); }
@Override public void write(DataOutput _index) throws IOException { _index.writeShort(getType()); _index.write(encryptedHashedDocname); _index.write(pubKeyHash); }