@Override public Key[] listKeys() { synchronized(this) { if(cancelled || finished) return new Key[0]; } return new Key[] { key.getNodeKey(true) }; }
@Override public String toString() { return "USKChecker for "+key.getURI()+" for "+cb; }
block = ClientCHKBlock.encode(buf, false, false, (short)-1, buf.length, COMPRESSOR_TYPE.DEFAULT_COMPRESSORDESCRIPTOR, false); insertKey = fetchKey = block.getClientKey(); testKey = insertKey.getURI(); System.err.println("Created random test key "+testKey+" = "+fetchKey.getNodeKey(false)); System.err.println(); Logger.normal(RealNodeRequestInsertTest.class,"Insert Key: "+insertKey.getURI()); Logger.normal(RealNodeRequestInsertTest.class,"Fetch Key: "+fetchKey.getURI()); try { insertAttempts++;
super(persistent ? fetcher.key.cloneKey() : fetcher.key, fetcher.maxRetries, ctx2, fetcher.parent, callback, false, true, fetcher.token, context, deleteFetchContext, fetcher.realTimeFlag); if(logMINOR) Logger.minor(this, "Creating SingleFileFetcher for "+fetcher.key+" meta="+fetcher.metaStrings.toString(), new Exception("debug"));
block = ClientCHKBlock.encode(buf, false, false, (short)-1, buf.length, COMPRESSOR_TYPE.DEFAULT_COMPRESSORDESCRIPTOR, false); insertKey = fetchKey = block.getClientKey(); testKey = insertKey.getURI(); final Key nodeKey = fetchKey.getNodeKey(false); int count = 0; for(Node node: nodes) { if(node.hasKey(fetchKey.getNodeKey(false), true, true)) count++; System.err.print("Nodes that do have the data: "); for(int i=0;i<nodes.length;i++) if(nodes[i].hasKey(fetchKey.getNodeKey(false), true, true)) { System.err.print(i+" ");
public Key getNodeKey() { return getNodeKey(true); }
public synchronized FreenetURI getURINoEncode() { return resultingKey == null ? null : resultingKey.getURI(); }
@Override public Key getNodeKey(SendableRequestItem token) { ClientKey key = getKey(token); if(key == null) return null; return key.getNodeKey(true); }
@Override public ClientKeyBlock get(ClientKey key) { KeyBlock block = get(key.getNodeKey(false)); if(block == null) return null; try { return Key.createKeyBlock(key, block); } catch (KeyVerifyException e) { Logger.error(this, "Caught decoding block with "+key+" : "+e, e); return null; } }
thisKey = FreenetURI.EMPTY_CHK_URI; else thisKey = key.getURI(); if(origURI == null) throw new NullPointerException(); this.uri = persistent ? origURI.clone() : origURI;
@Override public KeyListener makeKeyListener(ClientContext context, boolean onStartup) { synchronized(this) { if(finished) return null; if(cancelled) return null; } if(key == null) { Logger.error(this, "Key is null - left over BSSF? on "+this+" in makeKeyListener()", new Exception("error")); return null; } Key newKey = key.getNodeKey(true); if(parent == null) { Logger.error(this, "Parent is null on "+this+" persistent="+persistent+" key="+key+" ctx="+ctx); return null; } short prio = parent.getPriorityClass(); KeyListener ret = new SingleKeyListener(newKey, this, prio, persistent); return ret; }
return; if(logMINOR) Logger.minor(this, "Found DBR hint edition "+hint+" for "+this.fetcher.getKey(null).getURI()+" for "+USKFetcher.this); processDBRHint(hint, context, this);
@Override public SendableRequestItem chooseKey(KeysFetchingLocally fetching, ClientContext context) { Key k = key.getNodeKey(false); if(fetching.hasKey(k, this)) return null; long l = fetching.checkRecentlyFailed(k, realTimeFlag); long now = System.currentTimeMillis(); if(l > 0 && l > now) { if(maxRetries == -1 || (maxRetries >= RequestScheduler.COOLDOWN_RETRIES)) { // FIXME synchronization!!! if(logMINOR) Logger.minor(this, "RecentlyFailed -> cooldown until "+TimeUtil.formatTime(l-now)+" on "+this); cooldownWakeupTime = Math.max(cooldownWakeupTime, l); return null; } else { this.onFailure(new LowLevelGetException(LowLevelGetException.RECENTLY_FAILED), null, context); return null; } } return keys[0]; }
protected ClientKeyBlock encode(ClientContext context, boolean calledByCB) throws InsertException { ClientKeyBlock block; boolean shouldSend; synchronized(this) { if(finished) return null; if(sourceData == null) { Logger.error(this, "Source data is null on "+this+" but not finished!"); return null; } block = innerEncode(context.random); shouldSend = (resultingKey == null); resultingKey = block.getClientKey(); } if(logMINOR) Logger.minor(this, "Encoded "+resultingKey.getURI()+" for "+this+" shouldSend="+shouldSend+" dontSendEncoded="+dontSendEncoded); if(shouldSend && !dontSendEncoded) cb.onEncode(block.getClientKey(), this, context); return block; }
public void onGotKey(Key key, KeyBlock block, ClientContext context) { synchronized(this) { if(finished) { if(logMINOR) Logger.minor(this, "onGotKey() called twice on "+this, new Exception("debug")); return; } finished = true; if(isCancelled()) return; if(key == null) throw new NullPointerException(); if(this.key == null) throw new NullPointerException("Key is null on "+this); if(!key.equals(this.key.getNodeKey(false))) { Logger.normal(this, "Got sent key "+key+" but want "+this.key+" for "+this); return; } } unregister(context, getPriorityClass()); // Key has already been removed from pendingKeys onSuccess(block, false, null, context); }
/** * Add a block to the binary blob. */ protected void addKeyToBinaryBlob(ClientKeyBlock block, ClientContext context) { if(binaryBlobWriter == null) return; synchronized(this) { if(finished) { if(logMINOR) Logger.minor(this, "Add key to binary blob for "+this+" but already finished"); return; } } if(logMINOR) Logger.minor(this, "Adding key "+block.getClientKey().getURI()+" to "+this, new Exception("debug")); try { binaryBlobWriter.addKey(block, context); } catch (IOException e) { Logger.error(this, "Failed to write key to binary blob stream: "+e, e); onFailure(new FetchException(FetchExceptionMode.BUCKET_ERROR, "Failed to write key to binary blob stream: "+e), null, context); } catch (BinaryBlobAlreadyClosedException e) { Logger.error(this, "Failed to write key to binary blob stream (already closed??): "+e, e); onFailure(new FetchException(FetchExceptionMode.BUCKET_ERROR, "Failed to write key to binary blob stream (already closed??): "+e), null, context); } }
final Key k = key.getNodeKey(); core.asyncGet(k, false, new RequestCompletionListener() {
@Override public void onSuccess(ClientKeyBlock block, boolean fromStore, Object reqTokenIgnored, ClientContext context) { if(parent instanceof ClientGetter) ((ClientGetter)parent).addKeyToBinaryBlob(block, context); Bucket data = extract(block, context); if(data == null) return; // failed context.uskManager.checkUSK(key.getURI(), fromStore, block.isMetadata()); if(!block.isMetadata()) { onSuccess(new FetchResult(new ClientMetadata(null), data), context); } else { onFailure(new FetchException(FetchExceptionMode.INVALID_METADATA, "Metadata where expected data"), false, context); } }
} catch (KeyCollisionException e) { LowLevelPutException failed = new LowLevelPutException(LowLevelPutException.COLLISION); KeyBlock collided = core.node.fetch(k.getNodeKey(), true, req.canWriteClientCache, false, false, null); if(collided == null) { Logger.error(this, "Collided but no key?!");