Skip to content

Commit 43fd840

Browse files
committed
refactor(fcp): Complete insert runtime handoff
Move PUT, manifest, and USK execution wiring behind adapter-owned seams. Keep concrete insert runtime bindings in bridge-fcp-runtime. Preserve persistent request compatibility and cover the handoff with targeted tests.
1 parent 6ef02c1 commit 43fd840

28 files changed

Lines changed: 1995 additions & 621 deletions

adapter-fcp/src/main/java/network/crypta/clients/fcp/ClientPut.java

Lines changed: 167 additions & 75 deletions
Large diffs are not rendered by default.

adapter-fcp/src/main/java/network/crypta/clients/fcp/ClientPutBase.java

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import network.crypta.client.InsertException.InsertExceptionMode;
1414
import network.crypta.client.InsertException;
1515
import network.crypta.client.async.BaseClientPutter;
16-
import network.crypta.client.async.ClientContext;
1716
import network.crypta.client.async.ClientPutCallback;
1817
import network.crypta.client.events.ClientEvent;
1918
import network.crypta.client.events.ClientEventDispatchContext;
@@ -23,7 +22,6 @@
2322
import network.crypta.client.events.SplitfileProgressEvent;
2423
import network.crypta.client.events.StartedCompressionEvent;
2524
import network.crypta.keys.FreenetURI;
26-
import network.crypta.keys.InsertableClientSSK;
2725
import network.crypta.support.api.Bucket;
2826
import org.slf4j.Logger;
2927
import org.slf4j.LoggerFactory;
@@ -34,10 +32,11 @@
3432
* <p>The class centralizes common state tracking for {@link ClientPut} and {@link ClientPutDir},
3533
* wiring FCP-facing identifiers, scheduling metadata, persistence constraints, and node callbacks
3634
* into a single state machine. Instances travel through connection-bound and forever-persistent
37-
* modes, reattaching to {@link ClientContext}s after deserialization, driving {@link
38-
* BaseClientPutter} progress, and translating internal events into client-visible FCP messages. It
39-
* is designed to be thread-aware: mutations happen under synchronization, while outbound messages
40-
* are dispatched via handler abstractions to avoid deadlocks.
35+
* modes, reattaching to {@link network.crypta.client.async.ClientContext ClientContext}s after
36+
* deserialization, driving {@link BaseClientPutter} progress, and translating internal events into
37+
* client-visible FCP messages. It is designed to be thread-aware: mutations happen under
38+
* synchronization, while outbound messages are dispatched via handler abstractions to avoid
39+
* deadlocks.
4140
*
4241
* <p>Typical usage involves subclassing to provide data-specific logic (single file or directory
4342
* tree) while relying on {@code ClientPutBase} to manage retries, metadata capture, and reporting.
@@ -63,7 +62,8 @@ public abstract class ClientPutBase extends ClientRequest
6362
/**
6463
* Per-request insert context seeded from the node defaults. It carries retry rules, redundancy
6564
* knobs, and compatibility flags and therefore must be explicitly cleaned up in {@link
66-
* #requestWasRemoved(ClientContext)} to avoid leaking stale listeners.
65+
* #requestWasRemoved(network.crypta.client.async.ClientContext) requestWasRemoved(ClientContext)}
66+
* to avoid leaking stale listeners.
6767
*/
6868
final InsertContext ctx;
6969

@@ -236,19 +236,13 @@ protected ClientPutBase() {
236236
*
237237
* @param uri candidate URI that may lack routing data; callers must not pass {@code null}
238238
* @param filename optional document name; when missing the method chooses {@code "key"}
239-
* @param context client context providing the randomness source used to mint new keys
239+
* @param runtimeSupport insert runtime support that owns placeholder-SSK normalization
240240
* @return original URI when already complete or a freshly derived insert URI with the filename
241241
* applied; the result is never {@code null}
242242
*/
243-
static FreenetURI checkEmptySSK(FreenetURI uri, String filename, ClientContext context) {
244-
if ("SSK".equals(uri.getKeyType()) && uri.getDocName() == null && uri.getRoutingKey() == null) {
245-
if (filename == null || filename.isEmpty()) filename = "key";
246-
// SSK@ = use a random SSK.
247-
InsertableClientSSK key = InsertableClientSSK.createRandom(context.random, "");
248-
return key.getInsertURI().setDocName(filename);
249-
} else {
250-
return uri;
251-
}
243+
static FreenetURI checkEmptySSK(
244+
FreenetURI uri, String filename, FcpInsertRuntimeSupport runtimeSupport) {
245+
return runtimeSupport.normalizeInsertUri(uri, filename);
252246
}
253247

254248
/**
@@ -313,16 +307,16 @@ protected static FreenetURI derivePublicURI(FreenetURI insertUri) throws Malform
313307
* leaving persistent ones untouched so they can resume later without extra chatter.
314308
*
315309
* <p>The method keeps side effects intentionally small. It does not throw nor block; instead it
316-
* simply triggers {@link #cancel(ClientContext)} for requests that were declared {@link
317-
* Persistence#CONNECTION}. Persistent and forever requests ignore the event because they expect
318-
* to be resumed through {@link network.crypta.client.async.ClientRequester} after
319-
* deserialization.
310+
* simply triggers {@link #cancel(network.crypta.client.async.ClientContext)
311+
* cancel(ClientContext)} for requests that were declared {@link Persistence#CONNECTION}.
312+
* Persistent and forever requests ignore the event because they expect to be resumed through
313+
* {@link network.crypta.client.async.ClientRequester} after deserialization.
320314
*
321315
* @param context client context that supplies cancellation helpers and resource pools; the value
322316
* may be reused across many requests and must not be {@code null}
323317
*/
324318
@Override
325-
public void onLostConnection(ClientContext context) {
319+
public void onLostConnection(network.crypta.client.async.ClientContext context) {
326320
if (persistence == Persistence.CONNECTION) cancel(context);
327321
// otherwise ignore
328322
}
@@ -496,7 +490,7 @@ public void onGeneratedMetadata(Bucket metadata, BaseClientPutter state) {
496490
* @param context client context through which cleanup helpers and factories can be reached
497491
*/
498492
@Override
499-
public void requestWasRemoved(ClientContext context) {
493+
public void requestWasRemoved(network.crypta.client.async.ClientContext context) {
500494
// if the request is still running, send a PutFailed with code=canceled
501495
if (!finished) {
502496
synchronized (this) {
@@ -960,7 +954,8 @@ private void writeObject(ObjectOutputStream out) throws IOException {
960954

961955
/**
962956
* Restores persistent fields during deserialization. Subclasses are expected to rebuild transient
963-
* collaborators during {@link #innerResume(ClientContext)} rather than in this hook.
957+
* collaborators during {@link #innerResume(network.crypta.client.async.ClientContext)
958+
* innerResume(ClientContext)} rather than in this hook.
964959
*
965960
* @param in source stream containing a previously serialized form of the object
966961
* @throws IOException when reading fails

0 commit comments

Comments
 (0)