public ClientKey getSSK() { return getSSK(suggestedEdition); }
/** Return the URL's to fetch hint data from */ public ClientSSK[] getRequestURIs(USK key) { ClientSSK[] uris = new ClientSSK[Type.values.length]; int x = 0; for(Type t : Type.values) uris[x++] = key.getSSK(key.siteName+PREFIX+get(t)); return uris; }
public ClientSSK getSSK(long ver) { return getSSK(getName(ver)); }
public synchronized void getRandomEditions(List<Lookup> toFetch, long lookedUp, List<Lookup> alreadyRunning, Random random, int allowed) { // Then add a couple of random editions for catch-up. long baseEdition = lookedUp + origMinFailures; for(int i=0;i<allowed;i++) { while(true) { // Geometric distribution. // 20% chance of mean 100, 80% chance of mean 10. Thanks evanbd. int mean = random.nextInt(5) == 0 ? 100 : 10; long fetch = baseEdition + (long)Math.floor(Math.log(random.nextFloat()) / Math.log(1.0 - 1.0/mean)); if(fetch < baseEdition) continue; Lookup l = new Lookup(); l.val = fetch; if(toFetch.contains(l)) continue; if(alreadyRunning.contains(l)) continue; l.key = origUSK.getSSK(fetch); l.ignoreStore = !(fetch - lookedUp >= WATCH_KEYS); toFetch.add(l); if(logMINOR) Logger.minor(this, "Trying random future edition "+fetch+" for "+origUSK+" current edition "+lookedUp); break; } } }
/** Append a series of E(H(docname))'s to the array. * @param baseEdition The edition to start from. * @param keys The number of keys to add. */ private void generate(long baseEdition, int keys, RemoveRangeArrayList<byte[]> ehDocnames) { if(logMINOR) Logger.minor(this, "generate() from "+baseEdition+" for "+origUSK); assert(baseEdition >= 0); for(int i=0;i<keys;i++) { long ed = baseEdition + i; ehDocnames.add(origUSK.getSSK(ed).ehDocname); } }
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); }
key = origUSK.getSSK(ed); l.key = key; l.ignoreStore = true;
@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); } }
@Override public synchronized void onSuccess(ClientPutState state, ClientContext context) { USK newEdition = pubUSK.copy(edition); finished = true; sbi = null; FreenetURI targetURI = pubUSK.getSSK(edition).getURI(); FreenetURI realURI = ((SingleBlockInserter)state).getURI(context); if(!targetURI.equals(realURI)) Logger.error(this, "URI should be "+targetURI+" actually is "+realURI); else { if(logMINOR) Logger.minor(this, "URI should be "+targetURI+" actually is "+realURI); context.uskManager.updateKnownGood(pubUSK, edition, context); } if(freeData) { data.free(); data = null; } cb.onEncode(newEdition, this, context); insertSucceeded(context, edition); // FINISHED!!!! Yay!!! }
@Override public void onFoundEdition(long l, USK key, ClientContext context, boolean metadata, short codec, byte[] data, boolean newKnownGood, boolean newSlotToo) { if(l < 0) { Logger.error(this, "Found negative edition: "+l+" for "+key+" !!!"); return; } if(l < origUSK.suggestedEdition) { Logger.warning(this, "Found edition prior to that specified by the client: "+l+" < "+origUSK.suggestedEdition); return; } if(logMINOR) Logger.minor(this, "Found edition "+l+" for "+this+" - fetching..."); // Create a SingleFileFetcher for the key (as an SSK). // Put the edition number into its context object. // Put ourself as callback. // Fetch it. If it fails, ignore it, if it succeeds, return the data with the edition # to the client. FreenetURI uri = key.getSSK(l).getURI(); try { SingleFileFetcher getter = (SingleFileFetcher) SingleFileFetcher.create(this, this, uri, ctx, new ArchiveContext(ctx.maxTempLength, ctx.maxArchiveLevels), ctx.maxNonSplitfileRetries, 0, true, l, true, false, context, realTimeFlag, false); getter.schedule(context); } catch (MalformedURLException e) { Logger.error(this, "Impossible: "+e, e); } catch (FetchException e) { Logger.error(this, "Could not start fetcher for "+uri+" : "+e, e); } }
Logger.error(this, "Unable to insert USK date hints due to disk I/O error: "+e, e); if(!added) { cb.onFailure(new InsertException(InsertExceptionMode.BUCKET_ERROR, e, pubUSK.getSSK(edition).getURI()), this, context); return;
new SingleFileFetcher(requester, myCB, null, usk.getSSK(), metaStrings, usk.getURI().addMetaStrings(metaStrings), 0, ctx, false, realTimeFlag, actx, null, null, maxRetries, recursionLevel, dontTellClientGet, l, isEssential, isFinal, false, (short)0, context, false);