/** * Get the original USK URI which was passed when creating the retriever - not the latest known URI! */ @Override public FreenetURI getURI() { // FIXME: Toad: Why did getURI() return null? Does it break anything that I made it return the URI? return origUSK.getURI(); }
@Override public FreenetURI getURI() { return usk.getURI(); }
@Override public String toString() { return "USKAttempt for "+number+" for "+origUSK.getURI()+" for "+USKFetcher.this+(forever?" (forever)" : ""); }
public FreenetURI getURI() { return origUSK.getURI(); }
@Override public String toString() { return super.toString()+ ':' +getURI(); }
@Override public void onFoundEdition(long edition, USK key, ClientContext clientContext, boolean metadata, short codec, byte[] data, boolean newKnownGood, boolean newSlotToo) { callback.editionFound(key.getURI(), edition, newKnownGood, newSlotToo); }
/** * Add a USKAttempt for another edition number. * Caller is responsible for calling .schedule(). */ private synchronized USKAttempt add(Lookup l, boolean forever) { long i = l.val; if(l.val < 0) throw new IllegalArgumentException("Can't check <0 for "+l.val+" on "+this+" for "+origUSK); if(cancelled) return null; if(checkStoreOnly) return null; if(logMINOR) Logger.minor(this, "Adding USKAttempt for "+i+" for "+origUSK.getURI()); if(forever) { if(pollingAttempts.containsKey(i)) { if(logMINOR) Logger.minor(this, "Already polling edition: "+i+" for "+this); return null; } } else { if(runningAttempts.containsKey(i)) { if(logMINOR) Logger.minor(this, "Returning because already running for "+origUSK.getURI()); return null; } } USKAttempt a = new USKAttempt(l, forever); if(forever) pollingAttempts.put(i, a); else { runningAttempts.put(i, a); } if(logMINOR) Logger.minor(this, "Added "+a+" for "+origUSK); return a; }
this.uskManager.hintUpdate(this.origUSK.copy(hint).getURI(), context, prio); if(toCancel != null) { for(DBRAttempt a : toCancel)
void updateSlot(final USK origUSK, final long number, final ClientContext context) { if(logMINOR) Logger.minor(this, "Updating (slot) "+origUSK.getURI()+" : "+number); USK clear = origUSK.clearCopy(); final USKCallback[] callbacks;
@Override public SimpleFieldSet getFieldSet() { SimpleFieldSet fs = new SimpleFieldSet(true); fs.putSingle("URI", key.getURI().toString()); fs.put("DontPoll", dontPoll); return fs; }
void updateKnownGood(final USK origUSK, final long number, final ClientContext context) { if(logMINOR) Logger.minor(this, "Updating (known good) "+origUSK.getURI()+" : "+number); USK clear = origUSK.clearCopy(); final USKCallback[] callbacks;
@Override public SimpleFieldSet getFieldSet() { SimpleFieldSet sfs = new SimpleFieldSet(true); sfs.putSingle("Identifier", message.identifier); sfs.putSingle("URI", message.key.getURI().toString()); sfs.put("DontPoll", message.dontPoll); return sfs; }
@Test public void callbackForNormalUskForwardsImportantParameters() throws MalformedURLException { Callback callback = mock(Callback.class); FreenetURI uri = createRandom(randomSource, "test-0").getURI().uskForSSK(); freenetInterface.registerUsk(uri, callback); USK key = mock(USK.class); when(key.getURI()).thenReturn(uri); callbackCaptor.getValue().onFoundEdition(3, key, null, false, (short) 0, null, true, true); verify(callback).editionFound(eq(uri), eq(3L), eq(true), eq(true)); }
@Override public void onFoundEdition(long edition, USK key, ClientContext context, boolean wasMetadata, short codec, byte[] data, boolean newKnownGood, boolean newSlotToo) { if(!newKnownGood) { FreenetURI uri = key.copy(edition).getURI(); node.makeClient(PRIORITY_PROGRESS, false, false).prefetch(uri, MINUTES.toMillis(60), FProxyToadlet.MAX_LENGTH_WITH_PROGRESS, null, PRIORITY_PROGRESS); return;
@Override public SimpleFieldSet getFieldSet() { SimpleFieldSet fs = new SimpleFieldSet(true); fs.putSingle("Identifier", identifier); fs.put("Edition", edition); fs.putSingle("URI", key.getURI().toString()); fs.put("NewKnownGood", newKnownGood); fs.put("NewSlotToo", newSlotToo); return fs; }
/** * Schedule a Fetcher to find us the latest inserted key of the USK. * The Fetcher must be insert-mode, in other words, it must know that we want the latest edition, * including author errors and so on. */ private void scheduleFetcher(ClientContext context) { synchronized(this) { if(logMINOR) Logger.minor(this, "scheduling fetcher for "+pubUSK.getURI()); if(finished) return; fetcher = context.uskManager.getFetcherForInsertDontSchedule(persistent ? pubUSK.copy() : pubUSK, parent.priorityClass, this, parent.getClient(), context, persistent, ctx.ignoreUSKDatehints); if(logMINOR) Logger.minor(this, "scheduled: "+fetcher); } fetcher.schedule(context); }
private void scheduleInsert(ClientContext context) { long edNo = Math.max(edition, context.uskManager.lookupLatestSlot(pubUSK)+1); synchronized(this) { if(finished) return; edition = edNo; if(logMINOR) Logger.minor(this, "scheduling insert for "+pubUSK.getURI()+ ' ' +edition); sbi = new SingleBlockInserter(parent, data, compressionCodec, privUSK.getInsertableSSK(edition).getInsertURI(), ctx, realTimeFlag, this, isMetadata, sourceLength, token, false, true /* we don't use it */, tokenObject, context, persistent, false, extraInserts, cryptoAlgorithm, forceCryptoKey); } try { sbi.schedule(context); } catch (InsertException e) { synchronized(this) { finished = true; } if(freeData) { data.free(); synchronized(this) { data = null; } } cb.onFailure(e, this, context); } }
@Override public void onFoundEdition(long l, USK newUSK, ClientContext context, boolean metadata, short codec, byte[] data, boolean newKnownGood, boolean newSlotToo) { if(l < usk.suggestedEdition && datastoreOnly) l = usk.suggestedEdition; ClientSSK key = usk.getSSK(l); try { if(l == usk.suggestedEdition) { SingleFileFetcher sf = new SingleFileFetcher(parent, cb, null, key, metaStrings, key.getURI().addMetaStrings(metaStrings), 0, ctx, false, realTimeFlag, actx, null, null, maxRetries, recursionLevel+1, dontTellClientGet, token, false, true, false, (short)0, context, false); if(tag != null) { cb.onTransition(tag, sf, context); } sf.schedule(context); } else { cb.onFailure(new FetchException(FetchExceptionMode.PERMANENT_REDIRECT, newUSK.getURI().addMetaStrings(metaStrings)), null, context); } } catch (FetchException e) { cb.onFailure(e, null, context); } }
/** * A non-authoritative hint that a specific edition *might* exist. At the moment, * we just fetch the block. We do not fetch the contents, and it is possible that * USKFetcher's are also fetching the block. FIXME would it be more efficient to * pass it along to a USKFetcher? * @param usk * @param edition * @param context */ public void hintUpdate(USK usk, long edition, ClientContext context) { if(edition < lookupLatestSlot(usk)) return; FreenetURI uri = usk.copy(edition).getURI().sskForUSK(); final ClientGetter get = new ClientGetter(new NullClientCallback(rcBulk), uri, new FetchContext(backgroundFetchContext, FetchContext.IDENTICAL_MASK), RequestStarter.UPDATE_PRIORITY_CLASS, new NullBucket(), null, null); try { get.start(context); } catch (FetchException e) { // Ignore } }
if(edition > usk.suggestedEdition) { if(logMINOR) Logger.minor(SingleFileFetcher.class, "Redirecting to edition "+edition); cb.onFailure(new FetchException(FetchExceptionMode.PERMANENT_REDIRECT, usk.copy(edition).getURI().addMetaStrings(metaStrings)), null, context); return null; } else if(edition == -1 && usk.getURI().addMetaStrings(metaStrings), 0, ctx, false, realTimeFlag, actx, null, null, maxRetries, recursionLevel, dontTellClientGet, l, isEssential, isFinal, false, (short)0, context, false); return sf; cb.onFailure(new FetchException(FetchExceptionMode.PERMANENT_REDIRECT, usk.copy(edition).getURI().addMetaStrings(metaStrings)), null, context); return null;