/** * If this bookmark is marked as updated, registers a {@link UserAlert} which notifies the user. * You usually only need to call this function after having loaded a bookmark from disk using * {@link #BookmarkItem(SimpleFieldSet, BookmarkManager, UserAlertManager)}. */ synchronized void registerUserAlert() { if (key.isUSK() && updated) alerts.register(alert); }
public synchronized void update(FreenetURI uri, boolean hasAnActivelink, String description, String shortDescription) { this.key = uri; this.desc = description; this.shortDescription = shortDescription; this.hasAnActivelink = hasAnActivelink; if(!key.isUSK()) disableBookmark(); }
private synchronized void enableBookmark() { if (updated) { return; } assert(key.isUSK()); updated = true; alerts.register(alert); }
/** Called when the insert succeeds. */ @Override public void onSuccess(ClientPutState state, ClientContext context) { synchronized(this) { finished = true; currentState = null; } if(super.failedBlocks > 0 || super.fatallyFailedBlocks > 0 || super.successfulBlocks < super.totalBlocks) { // USK auxiliary inserts are allowed to fail. // If only generating the key, splitfile may not have reported the blocks as inserted. if (!uri.isUSK() && !ctx.getCHKOnly) Logger.error(this, "Failed blocks: "+failedBlocks+", Fatally failed blocks: "+fatallyFailedBlocks+ ", Successful blocks: "+successfulBlocks+", Total blocks: "+totalBlocks+" but success?! on "+this+" from "+state, new Exception("debug")); } client.onSuccess(this); }
OfficialPluginDescription(String name, String group, boolean essential, long minVer, long recVer, boolean alwaysFetchLatestVersion, boolean usesXML, FreenetURI uri, boolean deprecated, boolean experimental, boolean advanced, boolean unsupported) { this.name = name; this.group = group; this.essential = essential; this.minimumVersion = minVer; this.recommendedVersion = recVer; this.alwaysFetchLatestVersion = alwaysFetchLatestVersion; this.usesXML = usesXML; this.deprecated = deprecated; this.experimental = experimental; this.advanced = advanced; this.unsupported = unsupported; if (alwaysFetchLatestVersion && uri != null) { assert(uri.isUSK()) : "Non-USK URIs do not support updates!"; // Force fetching the latest edition by setting a negative USK edition. long edition = uri.getSuggestedEdition(); if (edition >= 0) { edition = Math.min(-1, -edition); } uri = uri.setSuggestedEdition(edition); } this.uri = uri; }
if (tempURI.isUSK()) { if (errors != null) { tempURI = tempURI.sskForUSK();
/** If the key is a USK and a) we are requested to do an exhaustive search, or b) * there is a later version, then we can't use the download queue as a cache. * @return True if we can't use the download queue, false if we can. */ private boolean bogusUSK(ClientContext context) { if(!uri.isUSK()) return false; long edition = uri.getSuggestedEdition(); if(edition < 0) return true; // Need to do the fetch. USK usk; try { usk = USK.create(uri); } catch (MalformedURLException e) { return false; // Will fail later. } long ret = context.uskManager.lookupKnownGood(usk); if(ret == -1) return false; return ret > edition; }
public static USK create(FreenetURI uri) throws MalformedURLException { if(!uri.isUSK()) throw new MalformedURLException("Not a USK"); return new USK(uri.getRoutingKey(), uri.getCryptoKey(), uri.getExtra(), uri.getDocName(), uri.getSuggestedEdition()); }
} else if(originalURI.isSSK() || originalURI.isUSK()) { FreenetURI newURI = originalURI; if(originalURI.isUSK()) newURI = newURI.sskForUSK(); InsertableClientSSK issk = InsertableClientSSK.create(newURI); newURI = issk.getURI(); if(originalURI.isUSK()) { newURI = newURI.uskForSSK(); newURI = newURI.setSuggestedEdition(originalURI.getSuggestedEdition());
public static boolean randomiseSplitfileKeys(FreenetURI targetURI, InsertContext ctx, boolean persistent) { // If the top level key is an SSK, all CHK blocks and particularly splitfiles below it should have // randomised keys. This substantially improves security by making it impossible to identify blocks // even if you know the content. In the user interface, we will offer the option of inserting as a // random SSK to take advantage of this. boolean randomiseSplitfileKeys = targetURI.isSSK() || targetURI.isKSK() || targetURI.isUSK(); if(randomiseSplitfileKeys) { CompatibilityMode cmode = ctx.getCompatibilityMode(); if(!(cmode == CompatibilityMode.COMPAT_CURRENT || cmode.ordinal() >= CompatibilityMode.COMPAT_1255.ordinal())) randomiseSplitfileKeys = false; } return randomiseSplitfileKeys; }
@Override public void set(String val) throws InvalidConfigValueException { FreenetURI uri; try { uri = new FreenetURI(val); } catch (MalformedURLException e) { throw new InvalidConfigValueException(l10n( "invalidUpdateURI", "error", e.getLocalizedMessage())); } if(updateURI.hasMetaStrings()) throw new InvalidConfigValueException(l10n("updateURIMustHaveNoMetaStrings")); if(!updateURI.isUSK()) throw new InvalidConfigValueException(l10n("updateURIMustBeAUSK")); setURI(uri); } }
public void checkUSK(FreenetURI uri, boolean persistent, boolean isMetadata) { try { FreenetURI uu; if(uri.isSSK() && uri.isSSKForUSK()) { uu = uri.setMetaString(null).uskForSSK(); } else if(uri.isUSK()) { uu = uri; } else { return; } USK usk = USK.create(uu); if(!isMetadata) context.uskManager.updateKnownGood(usk, uu.getSuggestedEdition(), context); else // We don't know whether the metadata is fetchable. // FIXME add a callback so if the rest of the request completes we updateKnownGood(). context.uskManager.updateSlot(usk, uu.getSuggestedEdition(), context); } catch (MalformedURLException e) { Logger.error(this, "Caught "+e, e); } catch (Throwable t) { // Don't let the USK hint cause us to not succeed on the block. Logger.error(this, "Caught "+t, t); } } }
if(uri.isUSK()) uri = uri.sskForUSK(); if(logMINOR) Logger.minor(this, "Doing hint fetch for "+uri); final ClientGetter get = new ClientGetter(new ClientGetCallback() {
if(updateURI.hasMetaStrings()) throw new InvalidConfigValueException(l10n("updateURIMustHaveNoMetaStrings")); if(!updateURI.isUSK()) throw new InvalidConfigValueException(l10n("updateURIMustBeAUSK"));
if(fr.hasData()) { if(fr.getFetchCount() > 1 && !fr.hasWaited() && fr.getFetchCount() > 1 && key.isUSK() && context.uskManager.lookupKnownGood(USK.create(key)) > key.getSuggestedEdition()) { Logger.normal(this, "Loading later edition..."); fetch.progress.requestImmediateCancel();