/** * 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(); }
public USK getUSK() throws MalformedURLException { return USK.create(key); }
public final USK copy() { // We need our own constructor to make sure we copy pubKeyHash. // So clone() doesn't work for this. // FIXME when we are sure we don't need to copy the byte[]'s we might be able to switch back to clone(). return new USK(this); }
@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; USK usk = USK.create(furi); if(usk.equals(key, false)) { if(logMINOR) Logger.minor(this, "Updating bookmark for "+furi+" to edition "+edition); matched = true;
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; synchronized(this) { final USK usk = origUSK.copy(number); for(final USKCallback callback : callbacks) context.mainExecutor.execute(new Runnable() {
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 && context.uskManager.getFetcher(usk.copy(usk.suggestedEdition), ctx, false, requester.persistent(), realTimeFlag, new MyUSKFetcherCallback(requester, cb, usk, metaStrings, ctx, actx, realTimeFlag, maxRetries, recursionLevel, dontTellClientGet, l, requester.persistent(), true), false, context, true); if(isEssential) 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); return sf; cb.onFailure(new FetchException(FetchExceptionMode.PERMANENT_REDIRECT, usk.copy(edition).getURI().addMetaStrings(metaStrings)), null, context); return null; context.uskManager.getFetcher(usk.copy(-usk.suggestedEdition), ctx, false, requester.persistent(), realTimeFlag, new MyUSKFetcherCallback(requester, cb, usk, metaStrings, ctx, actx, realTimeFlag, maxRetries, recursionLevel, dontTellClientGet, l, requester.persistent(), false), false, context, false); if(isEssential)
@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); } }
private boolean wantUSK(USK u, BookmarkItem ignore) { List<BookmarkItem> items = MAIN_CATEGORY.getAllItems(); for(BookmarkItem item : items) { if(item == ignore) continue; if(!"USK".equals(item.getKeyType())) continue; try { FreenetURI furi = new FreenetURI(item.getKey()); USK usk = USK.create(furi); if(usk.equals(u, false)) return true; } catch(MalformedURLException mue) { } } return false; }
ark = new USK(ssk, arkNo); } else if(forDiffNodeRef && arkPubKey == null && myARK != null && arkNo > -1) { ark = myARK.copy(arkNo); } else if(forDiffNodeRef && arkPubKey != null && myARK != null && arkNo <= -1) { if((myARK == null) || ((myARK != ark) && !myARK.equals(ark))) { myARK = ark; return true;
public USK clearCopy() { return copy(0); }
/** * Look up the latest known working version of the given USK. * @return The latest known edition number, or -1. */ public synchronized long lookupKnownGood(USK usk) { Long l = latestKnownGoodByClearUSK.get(usk.clearCopy()); if(l != null) return l.longValue(); else return -1; }
goodEd = lookupKnownGood(origUSK); synchronized(this) { USK clear = origUSK.clearCopy(); USKCallback[] callbacks = subscribersByClearUSK.get(clear); if(callbacks == null) { cb.onFoundEdition(goodEd, origUSK.copy(curEd), context, false, (short)-1, null, true, curEd > ed); else if(curEd > ed) cb.onFoundEdition(curEd, origUSK.copy(curEd), context, false, (short)-1, null, false, false); final USKFetcher fetcher = sched; if(fetcher != null) {
@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 int compare(USK o1, USK o2) { if(o1.hashCode > o2.hashCode) return 1; else if(o1.hashCode < o2.hashCode) return -1; return o1.compareTo(o2); }
@Override public boolean equals(Object o) { if(o == null || !(o instanceof USK)) return false; return equals(o, true); }
/** * Export the peer's noderef as a SimpleFieldSet */ public synchronized SimpleFieldSet exportFieldSet() { SimpleFieldSet fs = new SimpleFieldSet(true); if(getLastGoodVersion() != null) fs.putSingle("lastGoodVersion", lastGoodVersion); for(int i = 0; i < nominalPeer.size(); i++) fs.putAppend("physical.udp", nominalPeer.get(i).toString()); fs.put("auth.negTypes", negTypes); fs.putSingle("identity", getIdentityString()); fs.put("location", getLocation()); fs.put("testnet", testnetEnabled); fs.putSingle("version", version); fs.put("ecdsa", ECDSA.Curves.P256.getSFS(peerECDSAPubKey)); if(myARK != null) { // Decrement it because we keep the number we would like to fetch, not the last one fetched. fs.put("ark.number", myARK.suggestedEdition - 1); fs.putSingle("ark.pubURI", myARK.getBaseSSK().toString(false, false)); } fs.put("opennet", isOpennetForNoderef()); fs.put("seed", isSeed()); fs.put("totalInput", getTotalInputBytes()); fs.put("totalOutput", getTotalOutputBytes()); 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); }
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; boolean newSlot = false; final USK usk = origUSK.copy(number); final boolean newSlotToo = newSlot; for(final USKCallback callback : callbacks)