public static InsertableUSK createInsertable(FreenetURI uri, boolean persistent) throws MalformedURLException { if(!uri.getKeyType().equalsIgnoreCase("USK")) throw new MalformedURLException(); InsertableClientSSK ssk = InsertableClientSSK.create(uri.setKeyType("SSK")); return new InsertableUSK(ssk.docName, ssk.pubKeyHash, ssk.cryptoKey, ssk.privKey, uri.getSuggestedEdition(), ssk.cryptoAlgorithm); }
private FreenetURI setupFreenetUri() { FreenetURI sskKey = mock(FreenetURI.class); FreenetURI keyWithDocName = mock(FreenetURI.class); FreenetURI keyWithMetaStrings = mock(FreenetURI.class); when(keyWithDocName.setMetaString(eq(new String[] { "sone.xml" }))).thenReturn(keyWithMetaStrings); when(sskKey.setDocName(eq("Sone-" + CURRENT_EDITION))).thenReturn(keyWithDocName); when(sone.getRequestUri().setKeyType(eq("SSK"))).thenReturn(sskKey); return keyWithMetaStrings; }
/** * Returns the request URI of this Sone. * * @return The request URI of this Sone */ @Nonnull public FreenetURI getRequestUri() { try { return new FreenetURI(getIdentity().getRequestUri()) .setKeyType("USK") .setDocName("Sone") .setMetaString(new String[0]) .setSuggestedEdition(latestEdition); } catch (MalformedURLException e) { throw new IllegalStateException( format("Identity %s's request URI is incorrect.", getIdentity()), e); } }
/** * {@inheritDoc} */ @Override protected void serviceRun() { while (!shouldStop()) { while (!shouldStop() && !fetching) { sleep(); } if (fetching) { core.lockSone(sone); FreenetURI soneUri = sone.getRequestUri().setKeyType("SSK").setDocName("Sone-" + currentEdition).setMetaString(new String[] { "sone.xml" }); System.out.println("URI: " + soneUri); Sone fetchedSone = soneDownloader.fetchSone(sone, soneUri, true); System.out.println("Sone: " + fetchedSone); lastFetchSuccessful = (fetchedSone != null); if (lastFetchSuccessful) { core.updateSone(fetchedSone, true); } fetching = false; } } }
private void setupSone(Sone sone, Class<? extends Identity> identityClass) { Identity identity = mock(identityClass); InsertableClientSSK clientSSK = createRandom(new DummyRandomSource(), "WoT"); when(identity.getRequestUri()).thenReturn(clientSSK.getURI().toString()); when(identity.getId()).thenReturn("identity"); when(sone.getId()).thenReturn("identity"); when(sone.getIdentity()).thenReturn(identity); requestUri = clientSSK.getURI().setKeyType("USK").setDocName("Sone"); when(sone.getRequestUri()).thenAnswer(new Answer<FreenetURI>() { @Override public FreenetURI answer(InvocationOnMock invocation) throws Throwable { return requestUri; } }); when(sone.getTime()) .thenReturn(currentTimeMillis() - DAYS.toMillis(1)); }
@Before public void setupSone() { Sone sone = SoneDownloaderTest.this.sone; Identity identity = mock(Identity.class); InsertableClientSSK clientSSK = createRandom(new DummyRandomSource(), "WoT"); when(identity.getRequestUri()).thenReturn(clientSSK.getURI().toString()); when(identity.getId()).thenReturn("identity"); when(sone.getId()).thenReturn("identity"); when(sone.getIdentity()).thenReturn(identity); requestUri = clientSSK.getURI().setKeyType("USK").setDocName("Sone"); when(sone.getRequestUri()).thenAnswer(new Answer<FreenetURI>() { @Override public FreenetURI answer(InvocationOnMock invocation) throws Throwable { return requestUri; } }); when(sone.getTime()).thenReturn(currentTimeMillis() - DAYS.toMillis(1)); }
FreenetURI uri = ark.getInsertURI().setKeyType("USK").setSuggestedEdition(number);