diff --git a/AGENTS.md b/AGENTS.md index 760926b..790f582 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -34,9 +34,9 @@ the evaluator that plans and interprets campaigns lives in `malt-evaluation`. ## Package Ownership -- `transport/capability` owns URL-free, route-free, trust-free semantic ports - and untrusted dataset/mutation results shared by Gateway, local, peer, and - hybrid implementations. `transport/capabilitytest` owns the reusable adapter +- `nodeapi` owns URL-free, route-free, trust-free semantic ports + and untrusted authentication/dataset results shared by Gateway, local, peer, and + hybrid implementations. `nodeapi/nodetest` owns the reusable adapter contract, `transport/local` owns the bounded durable local CAS, and `transport/hybrid` owns Gateway-primary/read-through-CAS policy. Hybrid `Has` remains primary-authoritative and every cache body is CID-verified. Local diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 18e4dbb..9bedd25 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -12,7 +12,7 @@ It owns: - the `malt` CLI and local daemon lifecycle; - trusted/candidate root state and explicit acceptance; - managed-Bucket base/remote/stash state and stash-before-fetch synchronization; -- semantic remote capabilities with a current Gateway HTTP implementation; +- public `nodeapi` service capabilities shared with Gateway and its HTTP adapter; - UnixFS path, manifest, fixed-list payload, import, and range-body semantics; - IPFS-compatible Merkle DAG UnixFS import as an alternative runtime target; - local replay verification for gateway Merkle DAG compatibility reads; @@ -36,6 +36,12 @@ or a permanent prerequisite. The local and hybrid CAS implementations already use the same semantic boundary; future peer and local MALT executors must do so without changing application, trust, sync, or filesystem layers. +`nodeapi` owns the transport-independent contract above Core. Gateway implements +it in process and routes HTTP through its managed node services; local/hybrid +CAS and `transport.Client` implement the same interfaces. Authentication +semantics remain Core-owned. See [Public Node API](docs/node-api.md) for the +capability matrix, managed-policy boundary and shared conformance suites. + ## Data flow ```text @@ -44,9 +50,9 @@ UnixFS path / local files v MALT local runtime application adapter | - | canonical segments, generic resolve/read/mutation/CAS requests + | Core query/candidate/batch values and node CAS/dataset requests v - semantic transport capability + public nodeapi capability | v Gateway HTTP / Local CAS / Hybrid / future Peer @@ -117,7 +123,7 @@ unixfs -> MALT core verifier + narrow transport ports merkledag -> CID/link replay + fixed profile transport trust -> accepted/candidate root persistence transport -> Gateway/local/hybrid adapters; never imports unixfs, merkledag, or trust -bucketsync -> transport + independent durable synchronization metadata +bucketsync -> nodeapi.DatasetBranch + independent durable synchronization metadata tools/evaluation/cmd -> internal/evaluation + public runtime capabilities ``` @@ -138,7 +144,7 @@ read-through cache, and primary bytes are independently CID-verified before return. Cache presence can never satisfy primary `Has`. The default runtime configuration remains `gateway`; `local` currently supports local-only Merkle-DAG import, and managed native MALT operations reject it until a local -authentication materializer exists. `transport/capabilitytest` runs the same CAS +authentication materializer exists. `nodeapi/nodetest` runs the same CAS contract against mock, Gateway HTTP, local, hybrid, and a peer-loopback adapter; the loopback proves the port boundary without declaring a P2P wire profile. @@ -297,7 +303,7 @@ profile; it does not change MALT Core or the existing plaintext semantics of concrete transport. - `transport`: untrusted Gateway HTTP adapter and narrow capability interfaces; `transport/local` provides durable local CAS, `transport/hybrid` owns - Gateway-primary/read-through policy, and `transport/capabilitytest` provides + Gateway-primary/read-through policy, and `nodeapi/nodetest` provides adapter conformance. - `bucketsync`: durable Bucket base/remote/stash state and push orchestration. - `trust`: observed, candidate, and accepted root policy plus durable local diff --git a/README.md b/README.md index 2d5614f..f9baca4 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,11 @@ not update an accepted root automatically: remote heads are observations, while locally computed or strictly verified writes are candidates. Each has a separate explicit acceptance path. +The [public Node API](docs/node-api.md) defines transport-independent CAS, +authentication and dataset-branch capabilities. Gateway services and HTTP, +local and hybrid adapters implement the same contracts; synchronization consumes +them without acquiring root-acceptance authority. + ## Status This is an experimental, pre-v1 local runtime. It currently provides the @@ -468,7 +473,7 @@ persists base, observed remote head, and local stashes under a cross-process lock and implements stash-before-fetch push ordering. It deliberately does not import or mutate package `trust`. -`transport/capability` also defines public single and ordered-batch CAS +`nodeapi` also defines public single and ordered-batch CAS contracts plus stable not-found/corruption classification. `transport/local` stores bounded immutable blocks atomically in an owner-private directory and pins the opened store boundary with no-follow platform handles, rejects diff --git a/bucketsync/remote_test.go b/bucketsync/remote_test.go index 61e4968..0aa0a7a 100644 --- a/bucketsync/remote_test.go +++ b/bucketsync/remote_test.go @@ -5,29 +5,29 @@ import ( "testing" "time" - transportcap "github.com/dewebprotocol/malt-client/transport/capability" + "github.com/dewebprotocol/malt-client/nodeapi" cid "github.com/ipfs/go-cid" ) type capabilityRemote struct { - binding transportcap.DatasetBinding - head transportcap.ObservedHead + binding nodeapi.DatasetBinding + head nodeapi.ObservedHead calls int - apply func(transportcap.ApplyRequest) transportcap.ApplyResult - last transportcap.ApplyRequest + apply func(nodeapi.ApplyRequest) nodeapi.ApplyResult + last nodeapi.ApplyRequest } -func (r *capabilityRemote) DatasetBinding() transportcap.DatasetBinding { +func (r *capabilityRemote) DatasetBinding() nodeapi.DatasetBinding { return r.binding } -func (r *capabilityRemote) ObserveHead(context.Context) (*transportcap.ObservedHead, error) { +func (r *capabilityRemote) ObserveHead(context.Context) (*nodeapi.ObservedHead, error) { r.calls++ value := r.head return &value, nil } -func (r *capabilityRemote) ApplyCandidate(_ context.Context, request transportcap.ApplyRequest) (*transportcap.ApplyResult, error) { +func (r *capabilityRemote) ApplyCandidate(_ context.Context, request nodeapi.ApplyRequest) (*nodeapi.ApplyResult, error) { r.calls++ r.last = request value := r.apply(request) @@ -35,7 +35,7 @@ func (r *capabilityRemote) ApplyCandidate(_ context.Context, request transportca } func TestOpenRemoteBranchRejectsMisbindingBeforeIO(t *testing.T) { - remote := &capabilityRemote{binding: transportcap.DatasetBinding{DatasetID: "another", Branch: "main"}} + remote := &capabilityRemote{binding: nodeapi.DatasetBinding{DatasetID: "another", Branch: "main"}} if _, err := OpenRemote(t.TempDir()+"/workspace.json", remote, "dataset-one"); err == nil { t.Fatal("OpenRemote accepted a capability bound to another dataset") } @@ -49,21 +49,21 @@ func TestRemoteCapabilityRunsPullAndVerifiedApplyWithoutGatewayDTOs(t *testing.T candidate := testCID(t, "capability-candidate") now := time.Date(2026, time.August, 17, 1, 2, 3, 0, time.UTC) remote := &capabilityRemote{ - binding: transportcap.DatasetBinding{DatasetID: "dataset-one", Branch: "main"}, - head: transportcap.ObservedHead{ + binding: nodeapi.DatasetBinding{DatasetID: "dataset-one", Branch: "main"}, + head: nodeapi.ObservedHead{ DatasetID: "dataset-one", Name: "main", Kind: "main", State: "open", CommitID: "commit-base", Root: base.String(), Revision: 1, CreatedAt: now, UpdatedAt: now, }, } - remote.apply = func(request transportcap.ApplyRequest) transportcap.ApplyResult { - commit := transportcap.Commit{ + remote.apply = func(request nodeapi.ApplyRequest) nodeapi.ApplyResult { + commit := nodeapi.Commit{ ID: "commit-candidate", DatasetID: "dataset-one", Root: request.CandidateRoot, Parents: []string{request.BaseCommit}, BaseRoot: request.BaseRoot, Author: "device-one", Message: request.Message, CreatedAt: now, } - return transportcap.ApplyResult{ + return nodeapi.ApplyResult{ Status: "fast_forward", - Head: transportcap.ObservedHead{ + Head: nodeapi.ObservedHead{ DatasetID: "dataset-one", Name: "main", Kind: "main", State: "open", CommitID: commit.ID, Root: commit.Root, Revision: 2, CreatedAt: now, UpdatedAt: now, }, diff --git a/bucketsync/service.go b/bucketsync/service.go index 846fd2f..6dbca11 100644 --- a/bucketsync/service.go +++ b/bucketsync/service.go @@ -21,7 +21,7 @@ import ( "github.com/dewebprotocol/malt-client/internal/filelock" "github.com/dewebprotocol/malt-client/internal/securefile" "github.com/dewebprotocol/malt-client/internal/strictjson" - transportcap "github.com/dewebprotocol/malt-client/transport/capability" + "github.com/dewebprotocol/malt-client/nodeapi" cid "github.com/ipfs/go-cid" ) @@ -32,7 +32,7 @@ var ( const bucketWorkspaceVersion = 3 -type Remote = transportcap.DatasetBranch +type Remote = nodeapi.DatasetBranch type Head struct { CommitID string `json:"commit_id,omitempty"` @@ -73,8 +73,8 @@ type Workspace struct { } type PushOutcome struct { - Result transportcap.ApplyResult `json:"result"` - Workspace Workspace `json:"workspace"` + Result nodeapi.ApplyResult `json:"result"` + Workspace Workspace `json:"workspace"` } type persistedState struct { @@ -108,7 +108,7 @@ func OpenRemoteBranch(path string, remote Remote, bucketID, branch string) (*Ser if path == "" || remote == nil || bucketID == "" { return nil, fmt.Errorf("Bucket sync path, remote dataset capability, Bucket ID, and branch are required") } - if err := transportcap.ValidateBinding(bucketID, branch, remote.DatasetBinding()); err != nil { + if err := nodeapi.ValidateBinding(bucketID, branch, remote.DatasetBinding()); err != nil { return nil, err } service := &Service{ @@ -131,7 +131,7 @@ func (s *Service) Pull(ctx context.Context) (Workspace, error) { if head == nil { return Workspace{}, fmt.Errorf("remote returned an empty dataset head response") } - if err := transportcap.ValidateObservedHead(s.bucketID, s.branch, *head); err != nil { + if err := nodeapi.ValidateObservedHead(s.bucketID, s.branch, *head); err != nil { return Workspace{}, err } remote, err := headFromRef(*head) @@ -351,12 +351,12 @@ func (s *Service) Push(ctx context.Context, candidateRoot cid.Cid, changeSet cid if _, err := s.Pull(ctx); err != nil { return PushOutcome{}, err } - request := transportcap.ApplyRequest{ + request := nodeapi.ApplyRequest{ OperationID: stash.PushID, Branch: s.branch, BaseCommit: stash.Base.CommitID, BaseRoot: stash.Base.Root, CandidateRoot: stash.CandidateRoot, BaseRevision: stash.Base.Revision, ChangeSetCID: stash.ChangeSetCID, Message: stash.Message, } - request, err := transportcap.NormalizeApplyRequest(s.branch, request) + request, err := nodeapi.NormalizeApplyRequest(s.branch, request) if err != nil { return PushOutcome{}, err } @@ -367,7 +367,7 @@ func (s *Service) Push(ctx context.Context, candidateRoot cid.Cid, changeSet cid if result == nil { return PushOutcome{}, fmt.Errorf("remote returned an empty dataset apply response") } - if err := transportcap.ValidateApplyResult(s.bucketID, request, *result); err != nil { + if err := nodeapi.ValidateApplyResult(s.bucketID, request, *result); err != nil { return PushOutcome{}, err } var workspace Workspace @@ -628,7 +628,7 @@ func (s *Service) write() error { return nil } -func headFromRef(value transportcap.ObservedHead) (Head, error) { +func headFromRef(value nodeapi.ObservedHead) (Head, error) { head := Head{CommitID: value.CommitID, Root: value.Root, Revision: value.Revision} return head, validateHead(head) } @@ -671,7 +671,7 @@ func hasPending(values []Stash) bool { return false } -func conflictsFromRemote(values []transportcap.Conflict) []Conflict { +func conflictsFromRemote(values []nodeapi.Conflict) []Conflict { result := make([]Conflict, len(values)) for i, value := range values { result[i] = Conflict{Coordinate: value.Coordinate, Base: value.Base, Local: value.Local, Remote: value.Remote} diff --git a/bucketsync/service_test.go b/bucketsync/service_test.go index 7758aa3..984c40d 100644 --- a/bucketsync/service_test.go +++ b/bucketsync/service_test.go @@ -12,7 +12,7 @@ import ( "time" clientcas "github.com/dewebprotocol/malt-client/internal/cas" - transport "github.com/dewebprotocol/malt-client/transport/capability" + transport "github.com/dewebprotocol/malt-client/nodeapi" cid "github.com/ipfs/go-cid" ) diff --git a/cmd/malt/backup_plans.go b/cmd/malt/backup_plans.go index f0a8f93..ba7c5fa 100644 --- a/cmd/malt/backup_plans.go +++ b/cmd/malt/backup_plans.go @@ -209,7 +209,11 @@ func resolveBucket(ctx context.Context, client *gatewayclient.Client, selector s } func ensureBucketBranch(ctx context.Context, client *gatewayclient.Client, branch string, create bool) error { - if branch == "main" { + want, err := bucketbranch.RefName(branch) + if err != nil { + return err + } + if want == "main" { _, err := client.BucketHead(ctx) return err } @@ -217,7 +221,6 @@ func ensureBucketBranch(ctx context.Context, client *gatewayclient.Client, branc if err != nil { return err } - want := "heads/" + branch for _, ref := range refs { if ref.Name == want { return nil diff --git a/cmd/malt/backup_plans_test.go b/cmd/malt/backup_plans_test.go index 66189a0..c980538 100644 --- a/cmd/malt/backup_plans_test.go +++ b/cmd/malt/backup_plans_test.go @@ -1,16 +1,44 @@ package main import ( + "encoding/json" "fmt" + "net/http" + "net/http/httptest" "path/filepath" "strings" "testing" clientbackup "github.com/dewebprotocol/malt-client/application/backup" clientconfig "github.com/dewebprotocol/malt-client/internal/config" + gatewayclient "github.com/dewebprotocol/malt-client/transport" truststore "github.com/dewebprotocol/malt-client/trust" ) +func TestEnsureBucketBranchRecognizesNestedHeadsName(t *testing.T) { + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodGet || r.URL.Path != "/v1/buckets/bkt_one/branches" { + t.Errorf("unexpected branch request: %s %s", r.Method, r.URL.Path) + http.NotFound(w, r) + return + } + _ = json.NewEncoder(w).Encode(map[string]any{"branches": []gatewayclient.BucketRef{ + {BucketID: "bkt_one", Name: "heads/heads/topic", Kind: "explicit", State: "open"}, + }}) + })) + defer server.Close() + client, err := gatewayclient.New(gatewayclient.Options{BaseURL: server.URL, BucketID: "bkt_one", TenantBearerToken: "test"}) + if err != nil { + t.Fatal(err) + } + if err := ensureBucketBranch(t.Context(), client, "heads/heads/topic", true); err != nil { + t.Fatalf("existing nested branch was not recognized: %v", err) + } + if err := ensureBucketBranch(t.Context(), client, "topic", false); err == nil { + t.Fatal("nested branch was mistaken for its sibling") + } +} + func TestResolveBackupBindingSourcePreservesWhitespace(t *testing.T) { parent := t.TempDir() spaced := filepath.Join(parent, "notes ") diff --git a/docs/go-api.md b/docs/go-api.md index 5f1f3e3..61f0488 100644 --- a/docs/go-api.md +++ b/docs/go-api.md @@ -8,32 +8,38 @@ This module is intentionally untagged after historical runtime `v0.0.1` while the [runtime namespace decision](runtime-module-namespace.md) is deferred; pin current integrations to an exact reviewed commit. -## Public gateway transport +## Public Node API -Transport-neutral ports live in -`github.com/dewebprotocol/malt-client/transport/capability`. They identify a -logical dataset and branch without a URL and return explicitly untrusted typed -values: +The transport-independent service contract lives in +`github.com/dewebprotocol/malt-client/nodeapi`. Gateway in-process services, +the HTTP client, local/hybrid CAS and synchronization consume these same narrow +capabilities. See [Public Node API](node-api.md) for ownership, adapter rules, +conformance tests and implementation limits. ```go -var native capability.Native = remote -var blocks capability.CAS = remote -var mutations capability.Mutations = remote -var dataset capability.DatasetBranch = remote +var queries nodeapi.Authentication = remote +var writer nodeapi.AuthenticationWriter = remote +var batches nodeapi.AuthenticationBatch = remote +var blocks nodeapi.CAS = remote +var dataset nodeapi.DatasetBranch = remote -binding := dataset.DatasetBinding() observed, err := dataset.ObserveHead(ctx) -result, err := dataset.ApplyCandidate(ctx, capability.ApplyRequest{ +if err != nil { return err } +result, err := dataset.ApplyCandidate(ctx, nodeapi.ApplyRequest{ OperationID: "device-operation-id", BaseCommit: observed.CommitID, BaseRoot: observed.Root, BaseRevision: observed.Revision, CandidateRoot: candidate.String(), + MergePolicy: "preserve", }) ``` -These interfaces contain no HTTP route, URL, account DTO, or trust-store -method. `MutationResult`, `ObservedHead`, and `ApplyResult` cannot promote an -accepted root. `ValidateBinding`, `NormalizeApplyRequest`, and -`ValidateApplyResult` fail closed before or after an untrusted implementation. +These interfaces have no URL, HTTP request, daemon control, account DTO, or +trust-store method. Core owns the authentication request/candidate/receipt +values. Successful materialization acknowledges persistence at the chosen +service; publication and accepted-root promotion are separate operations. +`ObservedHead` and `ApplyResult` remain untrusted observations. + +## Gateway HTTP adapter The root `transport` package is currently the managed Gateway HTTP adapter. @@ -105,13 +111,13 @@ application dependency: blocks, err := local.Open(local.Options{ Directory: "/home/user/.malt-client/local-cas", }) -var cas capability.CAS = blocks +var cas nodeapi.CAS = blocks ``` Files are installed atomically below an owner-private store boundary. `Get` and `Has` read a bounded regular file and recompute the requested CID; local file presence alone is never accepted as block identity. `PutBatch` and -`HasBatch` implement the optional `capability.BatchCAS` extension. The store +`HasBatch` implement the optional `nodeapi.BatchCAS` extension. The store holds platform directory handles so post-open path replacement cannot redirect I/O, never follows a shard/block symlink or reparse point, and rejects FIFO, socket, unreadable block, hard-link, wrong-owner, and non-private metadata. @@ -173,7 +179,7 @@ The generated runtime configuration contains `transport.cas_policy` with fields default to `gateway`. Local-only mode currently supports `malt add --target merkle-dag`; managed native MALT backup, mount, and write-back require Gateway or hybrid because a local authentication materializer is not yet claimed. -The reusable `transport/capabilitytest.RunCAS` suite is run against mock, +The reusable `nodeapi/nodetest.RunCAS` suite is run against mock, Gateway HTTP, local, hybrid, and peer-loopback implementations. The peer fixture defines no network codec, discovery rule, or wire identifier. @@ -195,7 +201,7 @@ No exported signature contains a type from `internal/`. Package `bucketsync` provides the durable runtime workflow used by the CLI. New code constructs it with `OpenRemote` or `OpenRemoteBranch` and a -`capability.DatasetBranch`. The former `Open`/`OpenBranch` Gateway-DTO adapter is removed. +`nodeapi.DatasetBranch`. The former `Open`/`OpenBranch` Gateway-DTO adapter is removed. Call `CurrentBase` before materializing local work, then `Stage` the candidate against that captured commit/root/revision. `Push` refuses unstaged candidates, calls `ObserveHead` without changing the stash, leaves it pending across network diff --git a/docs/node-api.md b/docs/node-api.md new file mode 100644 index 0000000..3082d3b --- /dev/null +++ b/docs/node-api.md @@ -0,0 +1,100 @@ +# Public Node API + +`github.com/dewebprotocol/malt-client/nodeapi` defines the transport-independent +service contract shared by the local runtime and Gateway. A consumer selects +narrow capabilities instead of depending on an HTTP client or one large Node +interface. Core remains the authority for authentication semantics and types. + +```mermaid +flowchart TD + application[Application / CLI / sync] --> api[Public nodeapi capabilities] + api --> local[Local or hybrid implementation] + api --> rpc[RPC client adapter] + rpc --> network[HTTP today / other RPC adapters later] + network --> service[Gateway node services] + embedded[In-process Gateway caller] --> service + service --> core[Core authentication engine] + service --> store[Gateway persistence and managed policy] +``` + +## Contract + +| Capability | Operations | Meaning of success | +| --- | --- | --- | +| `CAS` | `Put`, `PutWithCodec`, `Get`, `Has` | Immutable bytes and write identities are CID-bound | +| `BatchCAS` | Ordered `PutBatch`, `HasBatch` | The same CAS semantics; optional batching | +| `Authentication` | `Authenticate` | Untrusted Core evidence for the caller's exact request | +| `AuthenticationWriter` | `AuthenticationCandidate`, `MaterializeAuthentication` | Complete candidate transfer for the exact Root | +| `AuthenticationBatch` | `MaterializeAuthenticationBatch` | Core receipt for the exact dependency-ordered batch | +| `DatasetBranch` | `DatasetBinding`, `ObserveHead`, `ApplyCandidate` | Untrusted branch observations and explicit publication results | + +A successful pointer result is non-nil. Candidate schema validation and Root +identity checks happen before writes or before returning a candidate. They do +not replace cryptographic verification of exported state or query evidence. +Authentication values and receipts use Core's existing `protocol` types. + +Services honor context cancellation before effects. CAS `Get` returns +caller-owned bytes, binds them to the requested CID, and reports missing blocks +with `ErrNotFound`; corrupted bytes or write identities report +`ErrCorruptedBlock`. Batch results retain input order and validated statuses. +CAS batch failure may leave a verified subset stored, so callers retry the +complete immutable batch. A materialization receipt does not promise replication +or a transaction spanning payloads, authentication state, and publication. + +`DatasetBranch` is bound to one dataset and normalized branch. Applications use +`NormalizeApplyRequest`, `ValidateObservedHead`, and `ValidateApplyResult` to +check identity and result relationships. Base commit, root and non-zero revision +must be supplied together. Operation IDs bind retries to the same request. +Branch normalization is idempotent: `heads/topic` selects the logical branch +`topic`, while `heads/heads/topic` selects the distinct logical branch +`heads/topic` and retains its full selector through binding, transport and +validation. Adapters must not strip the namespace from a normalized selector. +`MergePolicy: "preserve"` retains a stale candidate on a conflict branch without +asking the service to compute a merged Root. A `branched` result is a successful +conflict-preservation outcome; the HTTP adapter maps it to status 409. + +## Ownership and adapters + +The contract lives above Core in the runtime module, whose current module name +remains `github.com/dewebprotocol/malt-client`. Gateway imports only `nodeapi` +from this module in production. It retains its own storage, scope lifecycle, +managed authority, quotas, and versioning implementation. No repository cycle +or Gateway dependency is introduced into the local runtime. + +Gateway's `internal/runtime` implements authentication and CAS execution. +`internal/nodeservice` applies managed Bucket authority, payload ownership, +metadata entitlement, and branch publication independently of HTTP. Its bound +capabilities receive an already authenticated principal and recheck permissions +and lifecycle on every operation; their constructors are not authentication +endpoints. HTTP retains credential decoding, origin checks, wire limits, +serialization, and status/header mapping. Operator/evaluation capabilities and +Merkle DAG compatibility stay separate from the public native Node API. + +`transport.Client` implements the same public contracts over current Gateway +HTTP routes. `transport/local` and `transport/hybrid` implement CAS, and +`bucketsync` consumes `DatasetBranch` directly. Application-specific narrow +interfaces can remain smaller than these public capabilities when appropriate. +No compatibility alias remains at `transport/capability` or +`transport/capabilitytest`; source consumers migrate to `nodeapi` and +`nodeapi/nodetest` together with the matching Gateway revision. + +The reusable `nodetest.RunCAS`, `RunAuthentication`, and `RunDataset` suites run +against real in-process Gateway services and the HTTP client. The CAS suite +also covers local and hybrid implementations. These tests check publication +separation, local proof verification, exact identities, retries, cancellation, +caller-owned results, and stale-writer conflict preservation. + +## Synchronization and local trust + +Synchronization orchestrates Node API calls. Payload upload, candidate +materialization, branch publication, observation, and local acceptance remain +separate stages. Existing `bucketsync` persists the base, pending operation and +remote observation; `trust` alone decides local acceptance. Neither an in-process +call nor a remote success is a trust shortcut. + +This refactor establishes the common service boundary. It does not add a +CouchDB-compatible protocol, WebSocket or gRPC transport, a full autonomous local +authentication store, or a new replication engine. Current local-only execution +provides CAS; native backup/mount/write-back still compose Gateway or hybrid +capabilities. New local executors and network transports can implement the same +contracts without changing Core or synchronization's authority over local roots. diff --git a/internal/architecture/dependencies_test.go b/internal/architecture/dependencies_test.go index e551dab..4a5f07b 100644 --- a/internal/architecture/dependencies_test.go +++ b/internal/architecture/dependencies_test.go @@ -18,6 +18,7 @@ func TestPackageBoundaries(t *testing.T) { path string banned []string }{ + {path: "nodeapi", banned: []string{"net/http", "github.com/dewebprotocol/malt-client/transport", "github.com/dewebprotocol/malt-client/application", "github.com/dewebprotocol/malt-client/filesystem", "github.com/dewebprotocol/malt-client/trust", "github.com/dewebprotocol/malt-client/unixfs", "github.com/dewebprotocol/gateway"}}, {path: "transport", banned: []string{"github.com/dewebprotocol/malt-client/application", "github.com/dewebprotocol/malt-client/filesystem", "github.com/dewebprotocol/malt-client/unixfs", "github.com/dewebprotocol/malt-client/merkledag", "github.com/dewebprotocol/malt-client/trust"}}, {path: "trust", banned: []string{"github.com/dewebprotocol/malt-client/application", "github.com/dewebprotocol/malt-client/filesystem", "github.com/dewebprotocol/malt-client/transport", "github.com/dewebprotocol/malt-client/unixfs", "github.com/dewebprotocol/malt-client/merkledag"}}, {path: "cache", banned: []string{"github.com/dewebprotocol/malt-client/application", "github.com/dewebprotocol/malt-client/filesystem", "github.com/dewebprotocol/malt-client/transport", "github.com/dewebprotocol/malt-client/trust", "github.com/dewebprotocol/malt-client/unixfs", "github.com/dewebprotocol/malt-core"}}, @@ -160,9 +161,9 @@ func TestBackupPlanCompositionLivesOutsideCommandHandlers(t *testing.T) { }) } -func TestSemanticTransportCapabilitiesExcludeGatewayAndTrustDependencies(t *testing.T) { +func TestNodeAPIExcludesTransportAndTrustDependencies(t *testing.T) { root := moduleRoot(t) - checkExactImports(t, filepath.Join(root, "transport", "capability"), []string{ + checkExactImports(t, filepath.Join(root, "nodeapi"), []string{ "net/http", "net/url", "github.com/dewebprotocol/malt-client/transport", diff --git a/internal/bucketbranch/branch.go b/internal/bucketbranch/branch.go index 610e121..5a12c12 100644 --- a/internal/bucketbranch/branch.go +++ b/internal/bucketbranch/branch.go @@ -8,7 +8,9 @@ import ( ) // NormalizeSelector returns main for the empty/default selector and otherwise -// returns a canonical explicit branch name without the heads/ namespace. +// returns an idempotent explicit selector. A name beginning with heads/ keeps +// its namespace prefix so passing the result through another adapter cannot +// select a different branch. func NormalizeSelector(raw string) (string, error) { raw = strings.TrimSpace(raw) if raw == "" || raw == "main" { @@ -17,8 +19,8 @@ func NormalizeSelector(raw string) (string, error) { return NormalizeExplicit(raw) } -// NormalizeExplicit validates one user-created branch and removes an optional -// public heads/ namespace prefix. +// NormalizeExplicit validates one user-created branch selector. It removes the +// optional heads/ namespace only when the remaining name is unambiguous. func NormalizeExplicit(raw string) (string, error) { raw = strings.TrimSpace(raw) raw = strings.TrimPrefix(raw, "heads/") @@ -32,9 +34,21 @@ func NormalizeExplicit(raw string) (string, error) { return "", fmt.Errorf("invalid Bucket branch %q", raw) } } + if strings.HasPrefix(raw, "heads/") { + return "heads/" + raw, nil + } return raw, nil } +// RefName returns the exact registry ref addressed by a branch selector. +func RefName(raw string) (string, error) { + selector, err := NormalizeSelector(raw) + if err != nil || selector == "main" { + return selector, err + } + return "heads/" + strings.TrimPrefix(selector, "heads/"), nil +} + func validIdentifier(value string) bool { if value == "" || len(value) > 128 { return false diff --git a/internal/bucketbranch/branch_test.go b/internal/bucketbranch/branch_test.go index e3a1419..63b1562 100644 --- a/internal/bucketbranch/branch_test.go +++ b/internal/bucketbranch/branch_test.go @@ -6,18 +6,32 @@ func TestNormalizeSelectorMatchesGatewayBranchGrammar(t *testing.T) { tests := []struct { raw string want string + ref string }{ - {raw: "", want: "main"}, - {raw: " main ", want: "main"}, - {raw: "photos", want: "photos"}, - {raw: "heads/team/photos", want: "team/photos"}, - {raw: "release/v1.2_candidate", want: "release/v1.2_candidate"}, + {raw: "", want: "main", ref: "main"}, + {raw: " main ", want: "main", ref: "main"}, + {raw: "photos", want: "photos", ref: "heads/photos"}, + {raw: "heads/team/photos", want: "team/photos", ref: "heads/team/photos"}, + {raw: "release/v1.2_candidate", want: "release/v1.2_candidate", ref: "heads/release/v1.2_candidate"}, + {raw: "heads", want: "heads", ref: "heads/heads"}, + {raw: " heads/heads/topic ", want: "heads/heads/topic", ref: "heads/heads/topic"}, + {raw: "heads/heads/heads/topic", want: "heads/heads/heads/topic", ref: "heads/heads/heads/topic"}, + {raw: "heads/heads/main", want: "heads/heads/main", ref: "heads/heads/main"}, } for _, test := range tests { - got, err := NormalizeSelector(test.raw) - if err != nil || got != test.want { - t.Errorf("NormalizeSelector(%q) = %q, %v; want %q", test.raw, got, err, test.want) - } + t.Run(test.raw, func(t *testing.T) { + selector := test.raw + for i := 0; i < 3; i++ { + got, err := NormalizeSelector(selector) + if err != nil || got != test.want { + t.Fatalf("NormalizeSelector(%q) = %q, %v; want %q", selector, got, err, test.want) + } + if ref, err := RefName(selector); err != nil || ref != test.ref { + t.Fatalf("RefName(%q) = %q, %v; want %q", selector, ref, err, test.ref) + } + selector = got + } + }) } } @@ -36,6 +50,9 @@ func TestNormalizeSelectorRejectsInvalidOrReservedBranches(t *testing.T) { if got, err := NormalizeSelector(raw); err == nil { t.Errorf("NormalizeSelector(%q) = %q, want error", raw, got) } + if got, err := RefName(raw); err == nil { + t.Errorf("RefName(%q) = %q, want error", raw, got) + } } } diff --git a/internal/cas/cas.go b/internal/cas/cas.go index 870a4b9..70de145 100644 --- a/internal/cas/cas.go +++ b/internal/cas/cas.go @@ -5,7 +5,7 @@ import ( "context" "fmt" - transportcap "github.com/dewebprotocol/malt-client/transport/capability" + "github.com/dewebprotocol/malt-client/nodeapi" cid "github.com/ipfs/go-cid" mh "github.com/multiformats/go-multihash" ) @@ -13,24 +13,24 @@ import ( // ErrNotFound reports that a requested CAS block is absent. Remote and local // implementations wrap this sentinel so higher layers can distinguish absence // from transport, cancellation, and corruption failures. -var ErrNotFound = transportcap.ErrNotFound +var ErrNotFound = nodeapi.ErrNotFound // Block is a CAS block to write. Codec 0 means cid.Raw. -type Block = transportcap.Block +type Block = nodeapi.Block // PutStatus describes how a block write was handled. -type PutStatus = transportcap.PutStatus +type PutStatus = nodeapi.PutStatus const ( - PutStatusStored = transportcap.PutStatusStored - PutStatusAlreadyPresent = transportcap.PutStatusAlreadyPresent - PutStatusDuplicate = transportcap.PutStatusDuplicate - PutStatusNewlyPersisted = transportcap.PutStatusNewlyPersisted - PutStatusDuplicateInRequest = transportcap.PutStatusDuplicateInRequest + PutStatusStored = nodeapi.PutStatusStored + PutStatusAlreadyPresent = nodeapi.PutStatusAlreadyPresent + PutStatusDuplicate = nodeapi.PutStatusDuplicate + PutStatusNewlyPersisted = nodeapi.PutStatusNewlyPersisted + PutStatusDuplicateInRequest = nodeapi.PutStatusDuplicateInRequest ) // PutResult is the ordered result for a block write. -type PutResult = transportcap.PutResult +type PutResult = nodeapi.PutResult // Reader provides read-side access to content-addressable storage. type Reader interface { diff --git a/internal/cas/verifying.go b/internal/cas/verifying.go index 92ac93d..a65ba87 100644 --- a/internal/cas/verifying.go +++ b/internal/cas/verifying.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" - transportcap "github.com/dewebprotocol/malt-client/transport/capability" + "github.com/dewebprotocol/malt-client/nodeapi" cid "github.com/ipfs/go-cid" ) @@ -14,7 +14,7 @@ import ( // untrusted execution state (see ARCHITECTURE.md, section "Trust Model"); a // reader that does not verify hashes lets a compromised CAS substitute // arbitrary content underneath ProofList header guarantees. -var ErrCorruptedBlock = transportcap.ErrCorruptedBlock +var ErrCorruptedBlock = nodeapi.ErrCorruptedBlock // VerifyingReader wraps a CAS Reader and validates immutable-byte results and // receipts before exposing them. It also validates Has identities and, if the @@ -235,7 +235,7 @@ func verifyBatchResults(blocks []Block, results []PutResult) error { if _, err := verifyPutResult(r.CID, blocks[i].Data, blocks[i].Codec); err != nil { return fmt.Errorf("batch result %d: %w", i, err) } - if !transportcap.IsValidPutStatus(r.Status) { + if !nodeapi.IsValidPutStatus(r.Status) { return fmt.Errorf("%w: batch result %d has unsupported status %q", ErrCorruptedBlock, i, r.Status) } } diff --git a/internal/runtime/transports.go b/internal/runtime/transports.go index e988215..09c325c 100644 --- a/internal/runtime/transports.go +++ b/internal/runtime/transports.go @@ -7,7 +7,7 @@ import ( "sync" clientconfig "github.com/dewebprotocol/malt-client/internal/config" - transportcap "github.com/dewebprotocol/malt-client/transport/capability" + "github.com/dewebprotocol/malt-client/nodeapi" hybridtransport "github.com/dewebprotocol/malt-client/transport/hybrid" localtransport "github.com/dewebprotocol/malt-client/transport/local" ) @@ -16,7 +16,7 @@ import ( // byte topology. Gateway-only bindings do not own the caller-supplied remote; // local and hybrid bindings close their local store exactly once. type CASBinding struct { - transportcap.CAS + nodeapi.CAS closeMu sync.Mutex closeFunc func() error closed bool @@ -46,7 +46,7 @@ func (b *CASBinding) Close() error { // gatewayRequired is true for managed-Bucket operations whose blocks must be // persisted at the Gateway. A local-only CAS is useful for local Merkle-DAG // import now and can back a future local Native/Mutations executor later. -func ComposeCAS(cfg *clientconfig.Config, gateway transportcap.CAS, gatewayRequired bool) (*CASBinding, error) { +func ComposeCAS(cfg *clientconfig.Config, gateway nodeapi.CAS, gatewayRequired bool) (*CASBinding, error) { if cfg == nil { return nil, fmt.Errorf("runtime config is nil") } diff --git a/internal/runtime/writeback.go b/internal/runtime/writeback.go index f7f295a..0f1cf9c 100644 --- a/internal/runtime/writeback.go +++ b/internal/runtime/writeback.go @@ -16,7 +16,7 @@ import ( filesystemmount "github.com/dewebprotocol/malt-client/filesystem/mount" filesystemservice "github.com/dewebprotocol/malt-client/filesystem/service" "github.com/dewebprotocol/malt-client/filesystem/staging" - transportcap "github.com/dewebprotocol/malt-client/transport/capability" + "github.com/dewebprotocol/malt-client/nodeapi" truststore "github.com/dewebprotocol/malt-client/trust" "github.com/dewebprotocol/malt-client/unixfs" unixfsplanner "github.com/dewebprotocol/malt-client/unixfs/planner" @@ -35,7 +35,7 @@ type gatewayWritableRemote interface { Put(context.Context, []byte) (cid.Cid, error) PutWithCodec(context.Context, []byte, uint64) (cid.Cid, error) AuthenticationCandidate(context.Context, cid.Cid) (*protocol.AuthenticationCandidate, error) - transportcap.AuthenticationBatch + nodeapi.AuthenticationBatch } type gatewayWritableBlocks interface { diff --git a/nodeapi/authentication.go b/nodeapi/authentication.go new file mode 100644 index 0000000..ea1a978 --- /dev/null +++ b/nodeapi/authentication.go @@ -0,0 +1,48 @@ +package nodeapi + +import ( + "fmt" + + "github.com/dewebprotocol/malt-core/maltcid" + "github.com/dewebprotocol/malt-core/protocol" + cid "github.com/ipfs/go-cid" +) + +// CandidateRoot validates the complete canonical Core candidate before a node +// or RPC adapter starts materialization. Validation does not verify a transition +// or authorize publication of the resulting Root. +func CandidateRoot(candidate protocol.AuthenticationCandidate) (cid.Cid, error) { + if err := candidate.Validate(); err != nil { + return cid.Undef, err + } + return cid.Decode(candidate.Root) +} + +// ValidateCandidateResult binds a candidate response to the selected Root. +// Consumers that use its state as a verified writer base must additionally run +// Core verification; schema and identity validation alone are not evidence. +func ValidateCandidateResult(root cid.Cid, candidate *protocol.AuthenticationCandidate) error { + if _, _, err := maltcid.ParseRoot(root); err != nil { + return err + } + if candidate == nil { + return fmt.Errorf("node returned a nil authentication candidate") + } + returned, err := CandidateRoot(*candidate) + if err != nil { + return err + } + if !returned.Equals(root) { + return fmt.Errorf("candidate view does not match selected Root") + } + return nil +} + +// ValidateMaterializedRoot binds a node's write result to the exact candidate. +// It does not turn an operational acknowledgement into a state-transition proof. +func ValidateMaterializedRoot(expected, returned cid.Cid) error { + if !expected.Defined() || !returned.Equals(expected) { + return fmt.Errorf("materialization receipt changed candidate Root") + } + return nil +} diff --git a/transport/capability/dataset.go b/nodeapi/dataset.go similarity index 92% rename from transport/capability/dataset.go rename to nodeapi/dataset.go index 1aefe41..ff5806a 100644 --- a/transport/capability/dataset.go +++ b/nodeapi/dataset.go @@ -1,4 +1,4 @@ -package capability +package nodeapi import ( "fmt" @@ -54,6 +54,9 @@ type ApplyRequest struct { BaseRevision uint64 `json:"base_revision"` ChangeSetCID string `json:"change_set_cid,omitempty"` Message string `json:"message,omitempty"` + // MergePolicy "preserve" retains a stale candidate on a conflict branch + // instead of asking the service to compute a merged Root. + MergePolicy string `json:"merge_policy,omitempty"` } type ApplyResult struct { @@ -66,6 +69,8 @@ type ApplyResult struct { Conflicts []Conflict `json:"conflicts,omitempty"` } +// NormalizeBranch returns an idempotent selector, retaining the heads/ +// namespace when the logical branch name itself begins with heads/. func NormalizeBranch(raw string) (string, error) { return bucketbranch.NormalizeSelector(raw) } @@ -79,6 +84,10 @@ func NormalizeApplyRequest(selectedBranch string, request ApplyRequest) (ApplyRe request.CandidateRoot = strings.TrimSpace(request.CandidateRoot) request.ChangeSetCID = strings.TrimSpace(request.ChangeSetCID) request.Message = strings.TrimSpace(request.Message) + request.MergePolicy = strings.TrimSpace(request.MergePolicy) + if request.MergePolicy != "" && request.MergePolicy != "preserve" { + return ApplyRequest{}, fmt.Errorf("merge policy must be empty or preserve") + } branch, err := NormalizeBranch(request.Branch) if err != nil { return ApplyRequest{}, err @@ -94,8 +103,8 @@ func NormalizeApplyRequest(selectedBranch string, request ApplyRequest) (ApplyRe if selectedBranch != "main" { request.Branch = selectedBranch } - if request.OperationID == "" { - return ApplyRequest{}, fmt.Errorf("dataset apply operation ID is empty") + if request.OperationID == "" || len(request.OperationID) > 256 { + return ApplyRequest{}, fmt.Errorf("dataset apply operation ID must contain 1..256 bytes") } candidate, err := cid.Parse(request.CandidateRoot) if err != nil { @@ -140,13 +149,13 @@ func ValidateBinding(datasetID, branch string, binding DatasetBinding) error { } func ValidateObservedHead(datasetID, branch string, value ObservedHead) error { - branch, err := NormalizeBranch(branch) + wantName, err := bucketbranch.RefName(branch) if err != nil { return err } - wantName, wantKind := "main", "main" - if branch != "main" { - wantName, wantKind = "heads/"+branch, "explicit" + wantKind := "main" + if wantName != "main" { + wantKind = "explicit" } if strings.TrimSpace(datasetID) == "" || value.DatasetID != datasetID || value.Name != wantName || value.Kind != wantKind || value.State != "open" { return fmt.Errorf("remote returned an invalid dataset %s head", branch) @@ -208,6 +217,9 @@ func ValidateApplyResult(datasetID string, request ApplyRequest, value ApplyResu return fmt.Errorf("remote returned a fast-forward head that does not point to the final commit") } case "merged": + if request.MergePolicy == "preserve" { + return fmt.Errorf("remote merged a candidate despite preserve policy") + } if value.Branch != nil || len(value.Conflicts) != 0 || value.Candidate.ID == value.Commit.ID || value.Head.CommitID == "" { return fmt.Errorf("remote returned an inconsistent merged dataset apply") } diff --git a/transport/capability/dataset_test.go b/nodeapi/dataset_test.go similarity index 73% rename from transport/capability/dataset_test.go rename to nodeapi/dataset_test.go index 539937b..b61cff5 100644 --- a/transport/capability/dataset_test.go +++ b/nodeapi/dataset_test.go @@ -1,4 +1,4 @@ -package capability +package nodeapi import ( "encoding/json" @@ -85,6 +85,38 @@ func TestValidateApplyResultBindsExactRequest(t *testing.T) { } } +func TestNestedHeadsBranchBinding(t *testing.T) { + const dataset = "dataset-one" + selectors := []string{"topic", "heads/heads/topic", "heads/heads/heads/topic"} + refs := []string{"heads/topic", "heads/heads/topic", "heads/heads/heads/topic"} + for i, selected := range selectors { + t.Run(selected, func(t *testing.T) { + binding := DatasetBinding{DatasetID: dataset, Branch: selected} + for j, branch := range selectors { + if err := ValidateBinding(dataset, branch, binding); (err == nil) != (i == j) { + t.Fatalf("binding %q to %q: %v", selected, branch, err) + } + head := ObservedHead{DatasetID: dataset, Name: refs[j], Kind: "explicit", State: "open"} + if err := ValidateObservedHead(dataset, selected, head); (err == nil) != (i == j) { + t.Fatalf("head %q for %q: %v", head.Name, selected, err) + } + request := ApplyRequest{OperationID: "publish", CandidateRoot: capabilityCID(t, "candidate").String(), Branch: branch} + if _, err := NormalizeApplyRequest(selected, request); (err == nil) != (i == j) { + t.Fatalf("request branch %q for %q: %v", branch, selected, err) + } + } + request := ApplyRequest{OperationID: "publish", CandidateRoot: capabilityCID(t, "candidate").String()} + for pass := 0; pass < 3; pass++ { + var err error + request, err = NormalizeApplyRequest(selected, request) + if err != nil || request.Branch != selected { + t.Fatalf("request branch = %q, %v; want %q", request.Branch, err, selected) + } + } + }) + } +} + func TestDatasetCapabilityJSONPreservesExistingPersistentFieldNames(t *testing.T) { value := ApplyResult{ Status: "fast_forward", diff --git a/nodeapi/doc.go b/nodeapi/doc.go new file mode 100644 index 0000000..6f8f4f1 --- /dev/null +++ b/nodeapi/doc.go @@ -0,0 +1,22 @@ +// Package nodeapi defines the public, transport-independent MALT node service +// contract. In-process services, RPC clients, applications, and synchronization +// engines consume the same narrow capabilities. +// +// Authentication requests, candidates, and receipts are canonical Core values. +// CAS and dataset operations are node services above Core. Implementations bind +// their own storage, execution scope, caller authority, and lifecycle; adapters +// map the same operations to a wire protocol without owning their semantics. +// A capability is not evidence that its implementation is trusted. +// +// Successful materialization acknowledges storage at the selected service, not +// replication to another node. Dataset publication is a separate operation; +// neither operation accepts a Root on behalf of a user. Trusted-root policy, +// key custody, local filesystem control, and hosted account administration are +// deliberately separate services. +// +// Implementations honor context cancellation and preserve exact Root, CID, +// dataset, branch, and operation identities. RPC adapters may add transport +// limits and authentication but must not change those meanings. Optional batch +// capabilities preserve ordered results and allow partial persistence on error; +// they do not imply a transaction across content, relationships, and publication. +package nodeapi diff --git a/nodeapi/nodetest/authentication.go b/nodeapi/nodetest/authentication.go new file mode 100644 index 0000000..dce4ab9 --- /dev/null +++ b/nodeapi/nodetest/authentication.go @@ -0,0 +1,141 @@ +package nodetest + +import ( + "context" + "errors" + "testing" + + "github.com/dewebprotocol/malt-client/nodeapi" + "github.com/dewebprotocol/malt-core/auth/commitment/ipa" + "github.com/dewebprotocol/malt-core/derivation" + "github.com/dewebprotocol/malt-core/engine" + "github.com/dewebprotocol/malt-core/maltcid" + "github.com/dewebprotocol/malt-core/protocol" + sdk "github.com/dewebprotocol/malt-core/sdk/authentication" + cid "github.com/ipfs/go-cid" +) + +// AuthenticationService is the combination exercised by RunAuthentication. +// Applications should continue to consume only the capabilities they need. +type AuthenticationService interface { + nodeapi.Authentication + nodeapi.AuthenticationWriter + nodeapi.AuthenticationBatch +} + +type AuthenticationFactory func(*testing.T) AuthenticationService + +// RunAuthentication exercises real Core candidates and locally verifies the +// same proof contract through an in-process service or an RPC adapter. The +// fixture must support IPA256 Prefix state and isolated batch transaction IDs. +func RunAuthentication(t *testing.T, factory AuthenticationFactory) { + t.Helper() + scheme, err := ipa.NewCommitterScheme(ipa.ProfileDirect) + if err != nil { + t.Fatal(err) + } + profiles := engine.NewRegistry() + if err := profiles.Register(scheme); err != nil { + t.Fatal(err) + } + e := engine.New(profiles) + prepare := func(t *testing.T, label string) protocol.AuthenticationCandidate { + t.Helper() + state := engine.State{Descriptor: maltcid.RootDescriptor{ + Layout: maltcid.Prefix, DerivationProfile: uint8(derivation.SHA256), Profile: maltcid.IPA256, + }, Entries: []engine.Entry{{Label: []byte(label), Target: cid.MustParse("bafkqaaa")}}} + candidate, err := sdk.Prepare(t.Context(), e, state) + if err != nil { + t.Fatal(err) + } + return candidate + } + + t.Run("materialize-export-query", func(t *testing.T) { + s := factory(t) + c := prepare(t, "node/api") + root, err := s.MaterializeAuthentication(t.Context(), c) + if err != nil || root.String() != c.Root { + t.Fatalf("materialization = %s, %v", root, err) + } + for i := 0; i < 2; i++ { + got, err := s.AuthenticationCandidate(t.Context(), root) + if err != nil { + t.Fatal(err) + } + if err := nodeapi.ValidateCandidateResult(root, got); err != nil { + t.Fatal(err) + } + recomputed, err := sdk.Prepare(t.Context(), e, got.State) + if err != nil || recomputed.Root != c.Root { + t.Fatalf("exported state does not recompute to Root: %v", err) + } + // The result belongs to this caller; mutating it must not corrupt storage. + got.State.Entries[0].Label[0] ^= 0xff + } + for _, label := range []string{"node/api", "missing"} { + bytes := []byte(label) + q := protocol.AuthenticationRequest{Profile: protocol.AuthenticationPathProfile, Root: c.Root, Operation: "binding", Label: &bytes} + result, err := s.Authenticate(t.Context(), q) + if err != nil || result == nil { + t.Fatalf("query = %v, %v", result, err) + } + ok, err := sdk.Verify(e, q, *result) + if err != nil || !ok { + t.Fatalf("local verification = %v, %v", ok, err) + } + } + }) + + t.Run("batch-receipt-and-retry", func(t *testing.T) { + s := factory(t) + base, next := prepare(t, "base"), prepare(t, "next") + if _, err := s.MaterializeAuthentication(t.Context(), base); err != nil { + t.Fatal(err) + } + next.Previous = base.Root + batch := protocol.AuthenticationBatch{Profile: protocol.AuthenticationBatchProfile, TransactionID: "node-api-batch", Base: base.Root, Root: next.Root, Candidates: []protocol.AuthenticationCandidate{next}} + first, err := s.MaterializeAuthenticationBatch(t.Context(), batch) + if err != nil { + t.Fatal(err) + } + if err := first.Validate(batch); err != nil { + t.Fatal(err) + } + retry, err := s.MaterializeAuthenticationBatch(t.Context(), batch) + if err != nil || retry != first { + t.Fatalf("idempotent receipt = %#v, %v; want %#v", retry, err, first) + } + other := prepare(t, "different") + other.Previous = base.Root + changed := batch + changed.Root, changed.Candidates = other.Root, []protocol.AuthenticationCandidate{other} + if _, err := s.MaterializeAuthenticationBatch(t.Context(), changed); err == nil { + t.Fatal("reused transaction ID accepted a different batch") + } + if _, err := s.AuthenticationCandidate(t.Context(), cid.MustParse(other.Root)); err == nil { + t.Fatal("rejected batch persisted a new candidate") + } + }) + + t.Run("invalid-and-canceled-writes-have-no-effect", func(t *testing.T) { + s := factory(t) + c := prepare(t, "unwritten") + bad := c + bad.State.Descriptor.Layout = maltcid.Positional + if _, err := s.MaterializeAuthentication(t.Context(), bad); err == nil { + t.Fatal("accepted mismatched Root/state descriptor") + } + ctx, cancel := context.WithCancel(t.Context()) + cancel() + if _, err := s.MaterializeAuthentication(ctx, c); !errors.Is(err, context.Canceled) { + t.Fatalf("canceled materialization: %v", err) + } + if _, err := s.AuthenticationCandidate(t.Context(), cid.MustParse(c.Root)); err == nil { + t.Fatal("invalid or canceled materialization stored a candidate") + } + if _, err := s.Authenticate(t.Context(), protocol.AuthenticationRequest{}); err == nil { + t.Fatal("accepted invalid query") + } + }) +} diff --git a/transport/capabilitytest/cas.go b/nodeapi/nodetest/cas.go similarity index 88% rename from transport/capabilitytest/cas.go rename to nodeapi/nodetest/cas.go index 9e84d74..53be5c8 100644 --- a/transport/capabilitytest/cas.go +++ b/nodeapi/nodetest/cas.go @@ -1,7 +1,6 @@ -// Package capabilitytest provides reusable semantic transport conformance -// suites. Gateway, local, peer, and hybrid adapters can run the same tests +// Package nodetest provides reusable Node API conformance suites. Gateway, local, peer, and hybrid adapters can run the same tests // without exposing their routes or backend DTOs to applications. -package capabilitytest +package nodetest import ( "bytes" @@ -10,12 +9,12 @@ import ( "testing" clientcas "github.com/dewebprotocol/malt-client/internal/cas" - transportcap "github.com/dewebprotocol/malt-client/transport/capability" + "github.com/dewebprotocol/malt-client/nodeapi" cid "github.com/ipfs/go-cid" ) // CASFactory returns a fresh isolated CAS for one contract case. -type CASFactory func(*testing.T) transportcap.CAS +type CASFactory func(*testing.T) nodeapi.CAS // RunCAS runs the transport-neutral immutable-byte contract. Implementations // that also expose BatchCAS receive the ordered batch extension cases. @@ -83,13 +82,13 @@ func RunCAS(t *testing.T, factory CASFactory) { if err != nil || present { t.Fatalf("missing Has = %v, %v", present, err) } - if _, err := store.Get(t.Context(), missing); !errors.Is(err, transportcap.ErrNotFound) { + if _, err := store.Get(t.Context(), missing); !errors.Is(err, nodeapi.ErrNotFound) { t.Fatalf("missing Get error = %v, want ErrNotFound", err) } - if _, err := store.Get(t.Context(), cid.Undef); !errors.Is(err, transportcap.ErrCorruptedBlock) { + if _, err := store.Get(t.Context(), cid.Undef); !errors.Is(err, nodeapi.ErrCorruptedBlock) { t.Fatalf("undefined Get error = %v, want ErrCorruptedBlock", err) } - if _, err := store.Has(t.Context(), cid.Undef); !errors.Is(err, transportcap.ErrCorruptedBlock) { + if _, err := store.Has(t.Context(), cid.Undef); !errors.Is(err, nodeapi.ErrCorruptedBlock) { t.Fatalf("undefined Has error = %v, want ErrCorruptedBlock", err) } }) @@ -113,7 +112,7 @@ func RunCAS(t *testing.T, factory CASFactory) { t.Run("ordered-batch-extension", func(t *testing.T) { store := requireCAS(t, factory) - batch, ok := store.(transportcap.BatchCAS) + batch, ok := store.(nodeapi.BatchCAS) if !ok { t.Skip("transport does not expose the optional ordered batch extension") } @@ -123,7 +122,7 @@ func RunCAS(t *testing.T, factory CASFactory) { if present, err := batch.HasBatch(t.Context(), nil); err != nil || len(present) != 0 { t.Fatalf("empty HasBatch = %#v, %v", present, err) } - blocks := []transportcap.Block{ + blocks := []nodeapi.Block{ {Data: []byte("batch-raw"), Codec: cid.Raw}, {Data: []byte{0xa1, 0x61, 0x62, 0x02}, Codec: 0x71}, {Data: []byte("batch-raw"), Codec: cid.Raw}, @@ -134,7 +133,7 @@ func RunCAS(t *testing.T, factory CASFactory) { } for index, block := range blocks { want := canonicalCID(t, block.Data, block.Codec) - if !results[index].CID.Equals(want) { + if !results[index].CID.Equals(want) || !nodeapi.IsValidPutStatus(results[index].Status) { t.Errorf("PutBatch[%d] CID = %s, want %s", index, results[index].CID, want) } } @@ -146,7 +145,7 @@ func RunCAS(t *testing.T, factory CASFactory) { }) } -func requireCAS(t *testing.T, factory CASFactory) transportcap.CAS { +func requireCAS(t *testing.T, factory CASFactory) nodeapi.CAS { t.Helper() store := factory(t) if store == nil { @@ -157,7 +156,7 @@ func requireCAS(t *testing.T, factory CASFactory) transportcap.CAS { func canonicalCID(t *testing.T, body []byte, codec uint64) cid.Cid { t.Helper() - key, err := clientcas.CIDForBlock(transportcap.Block{Data: body, Codec: codec}) + key, err := clientcas.CIDForBlock(nodeapi.Block{Data: body, Codec: codec}) if err != nil { t.Fatal(err) } diff --git a/nodeapi/nodetest/dataset.go b/nodeapi/nodetest/dataset.go new file mode 100644 index 0000000..8a293f3 --- /dev/null +++ b/nodeapi/nodetest/dataset.go @@ -0,0 +1,149 @@ +package nodetest + +import ( + "context" + "reflect" + "testing" + + "github.com/dewebprotocol/malt-client/nodeapi" + "github.com/dewebprotocol/malt-core/auth/commitment/ipa" + "github.com/dewebprotocol/malt-core/derivation" + "github.com/dewebprotocol/malt-core/engine" + "github.com/dewebprotocol/malt-core/maltcid" + sdk "github.com/dewebprotocol/malt-core/sdk/authentication" + cid "github.com/ipfs/go-cid" +) + +// DatasetFixture provides an isolated, initially empty writable branch and the +// candidate writer for the same execution scope. +type DatasetFixture struct { + Branch nodeapi.DatasetBranch + Writer nodeapi.AuthenticationWriter + CAS nodeapi.CAS +} + +type DatasetFactory func(*testing.T) DatasetFixture + +// RunDataset verifies publication, idempotency, stale-writer preservation and +// request binding through exactly the same API used by synchronization. +func RunDataset(t *testing.T, factory DatasetFactory) { + t.Helper() + scheme, err := ipa.NewCommitterScheme(ipa.ProfileDirect) + if err != nil { + t.Fatal(err) + } + profiles := engine.NewRegistry() + if err := profiles.Register(scheme); err != nil { + t.Fatal(err) + } + e := engine.New(profiles) + materialize := func(t *testing.T, fixture DatasetFixture, content string) cid.Cid { + t.Helper() + target, err := fixture.CAS.Put(t.Context(), []byte(content)) + if err != nil { + t.Fatal(err) + } + candidate, err := sdk.Prepare(t.Context(), e, engine.State{ + Descriptor: maltcid.RootDescriptor{Layout: maltcid.Prefix, DerivationProfile: uint8(derivation.SHA256), Profile: maltcid.IPA256}, + Entries: []engine.Entry{{Label: []byte("file"), Target: target}}, + }) + if err != nil { + t.Fatal(err) + } + root, err := fixture.Writer.MaterializeAuthentication(t.Context(), candidate) + if err != nil { + t.Fatal(err) + } + return root + } + + t.Run("publication-and-idempotency", func(t *testing.T) { + f := factory(t) + binding := f.Branch.DatasetBinding() + root := materialize(t, f, "first") + head, err := f.Branch.ObserveHead(t.Context()) + if err != nil || head == nil { + t.Fatalf("ObserveHead = %#v, %v", head, err) + } + if head.Root != "" || head.Revision != 0 { + t.Fatal("materialization implicitly published a head") + } + request := nodeapi.ApplyRequest{OperationID: "publish-first", CandidateRoot: root.String()} + result, err := f.Branch.ApplyCandidate(t.Context(), request) + if err != nil || result == nil { + t.Fatalf("ApplyCandidate = %#v, %v", result, err) + } + request.Branch = binding.Branch + if err := nodeapi.ValidateApplyResult(binding.DatasetID, request, *result); err != nil { + t.Fatal(err) + } + if result.Status != "fast_forward" || result.Head.Root != root.String() { + t.Fatalf("first publication = %#v", result) + } + retry, err := f.Branch.ApplyCandidate(t.Context(), request) + if err != nil || !reflect.DeepEqual(retry, result) { + t.Fatalf("retry changed result: %#v, %v", retry, err) + } + head, err = f.Branch.ObserveHead(t.Context()) + if err != nil || !reflect.DeepEqual(head, &result.Head) { + t.Fatalf("head = %#v, %v", head, err) + } + changed := request + changed.Message = "a different operation" + if _, err := f.Branch.ApplyCandidate(t.Context(), changed); err == nil { + t.Fatal("operation ID accepted different metadata") + } + }) + + t.Run("preserve-stale-candidate", func(t *testing.T) { + f := factory(t) + root := materialize(t, f, "initial") + initial, err := f.Branch.ApplyCandidate(t.Context(), nodeapi.ApplyRequest{OperationID: "initial", CandidateRoot: root.String()}) + if err != nil { + t.Fatal(err) + } + advance := func(content, operation string) *nodeapi.ApplyResult { + root := materialize(t, f, content) + result, err := f.Branch.ApplyCandidate(t.Context(), nodeapi.ApplyRequest{ + OperationID: operation, CandidateRoot: root.String(), BaseCommit: initial.Head.CommitID, + BaseRoot: initial.Head.Root, BaseRevision: initial.Head.Revision, MergePolicy: "preserve", + }) + if err != nil { + t.Fatal(err) + } + return result + } + current := advance("current", "advance") + stale := advance("stale", "preserve") + if current.Status != "fast_forward" || stale.Status != "branched" || stale.Branch == nil { + t.Fatalf("current=%#v, stale=%#v", current, stale) + } + if !reflect.DeepEqual(stale.Head, current.Head) || stale.Branch.Root != stale.Candidate.Root { + t.Fatal("conflict failed to preserve candidate and current head separately") + } + }) + + t.Run("invalid-and-canceled-publications", func(t *testing.T) { + f := factory(t) + root := materialize(t, f, "unpublished") + request := nodeapi.ApplyRequest{OperationID: "unpublished", CandidateRoot: root.String(), Branch: "other-branch"} + if _, err := f.Branch.ApplyCandidate(t.Context(), request); err == nil { + t.Fatal("accepted a write to another selected branch") + } + request.Branch = "" + request.BaseRoot = root.String() + if _, err := f.Branch.ApplyCandidate(t.Context(), request); err == nil { + t.Fatal("accepted incomplete base tuple") + } + request.BaseRoot = "" + ctx, cancel := context.WithCancel(t.Context()) + cancel() + if _, err := f.Branch.ApplyCandidate(ctx, request); err == nil { + t.Fatal("accepted canceled publication") + } + head, err := f.Branch.ObserveHead(t.Context()) + if err != nil || head == nil || head.Root != "" || head.Revision != 0 { + t.Fatalf("rejected write changed head: %#v, %v", head, err) + } + }) +} diff --git a/transport/capability/ports.go b/nodeapi/ports.go similarity index 84% rename from transport/capability/ports.go rename to nodeapi/ports.go index 2365cf1..3457531 100644 --- a/transport/capability/ports.go +++ b/nodeapi/ports.go @@ -1,8 +1,4 @@ -// Package capability defines transport-neutral, untrusted data-access -// capabilities consumed by the MALT local runtime. Implementations may use a -// Gateway, a peer, local storage, or a hybrid policy; none of these interfaces -// can mutate local trust state. -package capability +package nodeapi import ( "context" @@ -12,7 +8,7 @@ import ( cid "github.com/ipfs/go-cid" ) -// ErrNotFound reports that an immutable block is absent from a transport. +// ErrNotFound reports that an immutable block is absent from a node service. // Implementations wrap this sentinel so callers can distinguish absence from // cancellation, corruption, and backend failures without depending on a // concrete Gateway, peer, or local-store error type. @@ -22,8 +18,9 @@ var ErrNotFound = errors.New("cas: block not found") // they claim. A transport must never expose mismatched bytes to its caller. var ErrCorruptedBlock = errors.New("cas: returned block does not match requested CID") -// CAS transfers immutable bytes. Get implementations must bind returned bytes -// to the requested CID; callers still enforce application-specific bindings. +// CAS stores and retrieves immutable bytes. Implementations must bind returned +// bytes and write results to their CIDs, honor cancellation before side effects, +// and return caller-owned bytes. Callers enforce application-specific bindings. type CAS interface { Put(context.Context, []byte) (cid.Cid, error) PutWithCodec(context.Context, []byte, uint64) (cid.Cid, error) @@ -98,12 +95,17 @@ type DatasetBranch interface { } // Authentication exposes typed V=0 queries with untrusted proof results. +// Implementations validate the Core request before execution. A successful +// result is non-nil; the caller still verifies evidence against its own query +// and selected Root. No transport, publication, or trust policy is implied. type Authentication interface { Authenticate(context.Context, protocol.AuthenticationRequest) (*protocol.AuthenticationResult, error) } // AuthenticationWriter transfers complete candidate materialization. It has -// no authority to publish or accept a root. +// no authority to publish or accept a root. Candidate lookup returns a non-nil +// complete candidate for exactly the requested Root. Materialization validates +// the complete Core candidate before side effects and returns exactly its Root. type AuthenticationWriter interface { AuthenticationCandidate(context.Context, cid.Cid) (*protocol.AuthenticationCandidate, error) MaterializeAuthentication(context.Context, protocol.AuthenticationCandidate) (cid.Cid, error) diff --git a/transport/authentication.go b/transport/authentication.go index 1159293..c266821 100644 --- a/transport/authentication.go +++ b/transport/authentication.go @@ -7,6 +7,7 @@ import ( "net/http" "net/url" + "github.com/dewebprotocol/malt-client/nodeapi" "github.com/dewebprotocol/malt-core/maltcid" "github.com/dewebprotocol/malt-core/protocol" cid "github.com/ipfs/go-cid" @@ -40,23 +41,16 @@ func (c *Client) AuthenticationCandidate(ctx context.Context, root cid.Cid) (*pr if err != nil { return nil, err } - returned, err := cid.Decode(result.Root) - if err != nil || !returned.Equals(root) { - return nil, fmt.Errorf("candidate view does not match selected Root") + if err := nodeapi.ValidateCandidateResult(root, &result); err != nil { + return nil, err } return &result, nil } func (c *Client) MaterializeAuthentication(ctx context.Context, candidate protocol.AuthenticationCandidate) (cid.Cid, error) { - expected, err := cid.Decode(candidate.Root) + expected, err := nodeapi.CandidateRoot(candidate) if err != nil { return cid.Undef, err } - if _, _, err := maltcid.ParseRoot(expected); err != nil { - return cid.Undef, err - } - if candidate.Profile != protocol.AuthenticationProfile { - return cid.Undef, fmt.Errorf("unsupported authentication profile") - } var receipt struct { Profile string `json:"profile"` Root string `json:"root"` @@ -65,9 +59,12 @@ func (c *Client) MaterializeAuthentication(ctx context.Context, candidate protoc return cid.Undef, err } root, err := cid.Decode(receipt.Root) - if err != nil || receipt.Profile != protocol.AuthenticationProfile || !root.Equals(expected) { + if err != nil || receipt.Profile != protocol.AuthenticationProfile { return cid.Undef, fmt.Errorf("materialization receipt changed candidate Root") } + if err := nodeapi.ValidateMaterializedRoot(expected, root); err != nil { + return cid.Undef, err + } return root, nil } diff --git a/transport/bucket.go b/transport/bucket.go index 62d4b4f..cc6d977 100644 --- a/transport/bucket.go +++ b/transport/bucket.go @@ -11,6 +11,7 @@ import ( "time" "github.com/dewebprotocol/malt-client/internal/bucketbranch" + "github.com/dewebprotocol/malt-client/nodeapi" cid "github.com/ipfs/go-cid" ) @@ -82,6 +83,7 @@ type BucketPushRequest struct { BaseRevision uint64 `json:"base_revision"` ChangeSetCID string `json:"change_set_cid,omitempty"` Message string `json:"message,omitempty"` + MergePolicy string `json:"merge_policy,omitempty"` } type BucketPushResult struct { @@ -254,48 +256,18 @@ func (c *Client) PushBucket(ctx context.Context, request BucketPushRequest) (*Bu if err := c.requireSelectedBucket(); err != nil { return nil, err } - request.PushID = strings.TrimSpace(request.PushID) - requestBranch, err := normalizeBucketBranch(request.Branch) + normalized, err := nodeapi.NormalizeApplyRequest(c.SelectedBucketBranch(), nodeapi.ApplyRequest{ + OperationID: request.PushID, Branch: request.Branch, BaseCommit: request.BaseCommit, + BaseRoot: request.BaseRoot, CandidateRoot: request.CandidateRoot, BaseRevision: request.BaseRevision, + ChangeSetCID: request.ChangeSetCID, Message: request.Message, MergePolicy: request.MergePolicy, + }) if err != nil { return nil, err } - selectedBranch := c.SelectedBucketBranch() - if request.Branch != "" && requestBranch != selectedBranch { - return nil, fmt.Errorf("Bucket push branch %q does not match selected branch %q", requestBranch, selectedBranch) - } - request.Branch = "" - if selectedBranch != "main" { - request.Branch = selectedBranch - } - request.BaseCommit = strings.TrimSpace(request.BaseCommit) - request.BaseRoot = strings.TrimSpace(request.BaseRoot) - request.CandidateRoot = strings.TrimSpace(request.CandidateRoot) - request.ChangeSetCID = strings.TrimSpace(request.ChangeSetCID) - request.Message = strings.TrimSpace(request.Message) - if request.PushID == "" { - return nil, fmt.Errorf("Bucket push ID is empty") - } - candidateRoot, err := cid.Parse(request.CandidateRoot) - if err != nil { - return nil, fmt.Errorf("invalid candidate root: %w", err) - } - request.CandidateRoot = candidateRoot.String() - if (request.BaseCommit == "") != (request.BaseRoot == "") || (request.BaseCommit == "") != (request.BaseRevision == 0) { - return nil, fmt.Errorf("Bucket base commit, root, and non-zero revision must be supplied together") - } - if request.BaseRoot != "" { - baseRoot, err := cid.Parse(request.BaseRoot) - if err != nil { - return nil, fmt.Errorf("invalid base root: %w", err) - } - request.BaseRoot = baseRoot.String() - } - if request.ChangeSetCID != "" { - changeSet, err := cid.Parse(request.ChangeSetCID) - if err != nil { - return nil, fmt.Errorf("invalid change-set CID: %w", err) - } - request.ChangeSetCID = changeSet.String() + request = BucketPushRequest{ + PushID: normalized.OperationID, Branch: normalized.Branch, BaseCommit: normalized.BaseCommit, + BaseRoot: normalized.BaseRoot, CandidateRoot: normalized.CandidateRoot, BaseRevision: normalized.BaseRevision, + ChangeSetCID: normalized.ChangeSetCID, Message: normalized.Message, MergePolicy: normalized.MergePolicy, } data, err := json.Marshal(request) if err != nil { @@ -381,13 +353,13 @@ func ValidateBucketHead(bucketID string, value BucketRef) error { // ValidateBucketHeadForBranch verifies the selected writable ref. Explicit // branches are represented by the Gateway as heads/. func ValidateBucketHeadForBranch(bucketID, branch string, value BucketRef) error { - branch, err := normalizeBucketBranch(branch) + wantName, err := bucketbranch.RefName(branch) if err != nil { return err } - wantName, wantKind := "main", "main" - if branch != "main" { - wantName, wantKind = "heads/"+branch, "explicit" + wantKind := "main" + if wantName != "main" { + wantKind = "explicit" } if strings.TrimSpace(bucketID) == "" || value.BucketID != bucketID || value.Name != wantName || value.Kind != wantKind || value.State != "open" { return fmt.Errorf("gateway returned an invalid Bucket %s head", branch) @@ -408,6 +380,9 @@ func ValidateBucketHeadForBranch(bucketID, branch string, value BucketRef) error } func (c *Client) validatePushResult(request BucketPushRequest, value BucketPushResult, statusCode int) error { + if request.MergePolicy == "preserve" && value.Status == "merged" { + return fmt.Errorf("gateway merged a candidate despite preserve policy") + } switch value.Status { case "fast_forward", "merged": if statusCode != http.StatusCreated || value.Branch != nil { diff --git a/transport/bucket_test.go b/transport/bucket_test.go index 7ef3edb..7f54e0b 100644 --- a/transport/bucket_test.go +++ b/transport/bucket_test.go @@ -10,8 +10,8 @@ import ( "testing" "time" + "github.com/dewebprotocol/malt-client/nodeapi" client "github.com/dewebprotocol/malt-client/transport" - transportcap "github.com/dewebprotocol/malt-client/transport/capability" "github.com/dewebprotocol/malt-core/engine" "github.com/dewebprotocol/malt-core/protocol" "github.com/dewebprotocol/malt-core/traversal" @@ -96,7 +96,7 @@ func TestBucketClientScopesNativeRoutesAndAcceptsConflictResult(t *testing.T) { if head, err := transport.BucketHead(t.Context()); err != nil || head.Revision != 2 { t.Fatalf("head=%#v err=%v", head, err) } - if binding := transport.DatasetBinding(); binding != (transportcap.DatasetBinding{DatasetID: "bkt_one", Branch: "main"}) { + if binding := transport.DatasetBinding(); binding != (nodeapi.DatasetBinding{DatasetID: "bkt_one", Branch: "main"}) { t.Fatalf("dataset binding = %#v", binding) } if head, err := transport.ObserveHead(t.Context()); err != nil || head.DatasetID != "bkt_one" || head.Revision != 2 { @@ -120,7 +120,7 @@ func TestBucketClientScopesNativeRoutesAndAcceptsConflictResult(t *testing.T) { if receivedPush.BaseRevision != 2 || receivedPush.BaseRoot != root.String() || receivedPush.CandidateRoot != target.String() { t.Fatalf("push request was not canonicalized: %#v", receivedPush) } - capabilityResult, err := transport.ApplyCandidate(t.Context(), transportcap.ApplyRequest{ + capabilityResult, err := transport.ApplyCandidate(t.Context(), nodeapi.ApplyRequest{ OperationID: "capability-push", BaseCommit: "cmt_one", BaseRoot: baseText, CandidateRoot: candidateText, BaseRevision: 2, }) @@ -247,95 +247,111 @@ func TestBucketHeadRejectsNonMainRef(t *testing.T) { } func TestBucketClientBindsHeadAndPushToExplicitBranch(t *testing.T) { - candidateRoot := mustBlockCID(t, []byte("candidate")) - now := time.Now().UTC() - var request client.BucketPushRequest - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case "/v1/buckets/bkt_one/head": - if r.URL.Query().Get("branch") != "team/photos" { - t.Fatalf("branch query = %q", r.URL.RawQuery) - } - _ = json.NewEncoder(w).Encode(client.BucketRef{ - BucketID: "bkt_one", Name: "heads/team/photos", Kind: "explicit", State: "open", - Revision: 0, CreatedAt: now, UpdatedAt: now, + for _, branch := range []struct{ selector, canonical, ref string }{ + {"heads/team/photos", "team/photos", "heads/team/photos"}, + {"heads/heads/topic", "heads/heads/topic", "heads/heads/topic"}, + {"heads/heads/heads/topic", "heads/heads/heads/topic", "heads/heads/heads/topic"}, + } { + t.Run(branch.selector, func(t *testing.T) { + candidateRoot := mustBlockCID(t, []byte("candidate")) + now := time.Now().UTC() + var request client.BucketPushRequest + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case "/v1/buckets/bkt_one/head": + if r.URL.Query().Get("branch") != branch.canonical { + t.Fatalf("branch query = %q", r.URL.RawQuery) + } + _ = json.NewEncoder(w).Encode(client.BucketRef{ + BucketID: "bkt_one", Name: branch.ref, Kind: "explicit", State: "open", + Revision: 0, CreatedAt: now, UpdatedAt: now, + }) + case "/v1/buckets/bkt_one/push": + if err := json.NewDecoder(r.Body).Decode(&request); err != nil { + t.Fatal(err) + } + w.WriteHeader(http.StatusCreated) + candidate := client.BucketCommit{ + ID: "opaque-candidate", BucketID: "bkt_one", Root: candidateRoot.String(), + Author: "alice", CreatedAt: now, + } + _ = json.NewEncoder(w).Encode(client.BucketPushResult{ + Status: "fast_forward", + Head: client.BucketRef{ + BucketID: "bkt_one", Name: branch.ref, Kind: "explicit", State: "open", + CommitID: candidate.ID, Root: candidate.Root, Revision: 1, CreatedAt: now, UpdatedAt: now, + }, + Candidate: candidate, Commit: candidate, + }) + default: + http.NotFound(w, r) + } + })) + defer server.Close() + transport, err := client.New(client.Options{ + BaseURL: server.URL, TenantBearerToken: "tenant-secret", + BucketID: "bkt_one", BucketBranch: branch.selector, }) - case "/v1/buckets/bkt_one/push": - if err := json.NewDecoder(r.Body).Decode(&request); err != nil { + if err != nil { t.Fatal(err) } - w.WriteHeader(http.StatusCreated) - candidate := client.BucketCommit{ - ID: "opaque-candidate", BucketID: "bkt_one", Root: candidateRoot.String(), - Author: "alice", CreatedAt: now, + if head, err := transport.BucketHead(t.Context()); err != nil || head.Name != branch.ref { + t.Fatalf("branch head=%#v err=%v", head, err) } - _ = json.NewEncoder(w).Encode(client.BucketPushResult{ - Status: "fast_forward", - Head: client.BucketRef{ - BucketID: "bkt_one", Name: "heads/team/photos", Kind: "explicit", State: "open", - CommitID: candidate.ID, Root: candidate.Root, Revision: 1, CreatedAt: now, UpdatedAt: now, - }, - Candidate: candidate, Commit: candidate, + result, err := transport.PushBucket(t.Context(), client.BucketPushRequest{ + PushID: "branch-push", CandidateRoot: candidateRoot.String(), }) - default: - http.NotFound(w, r) - } - })) - defer server.Close() - transport, err := client.New(client.Options{ - BaseURL: server.URL, TenantBearerToken: "tenant-secret", - BucketID: "bkt_one", BucketBranch: "heads/team/photos", - }) - if err != nil { - t.Fatal(err) - } - if head, err := transport.BucketHead(t.Context()); err != nil || head.Name != "heads/team/photos" { - t.Fatalf("branch head=%#v err=%v", head, err) - } - result, err := transport.PushBucket(t.Context(), client.BucketPushRequest{ - PushID: "branch-push", CandidateRoot: candidateRoot.String(), - }) - if err != nil || result.Head.Name != "heads/team/photos" { - t.Fatalf("branch push=%#v err=%v", result, err) - } - if request.Branch != "team/photos" { - t.Fatalf("push branch = %q", request.Branch) + if err != nil || result.Head.Name != branch.ref { + t.Fatalf("branch push=%#v err=%v", result, err) + } + if request.Branch != branch.canonical { + t.Fatalf("push branch = %q", request.Branch) + } + }) } } func TestCreateBucketBranchCanonicalizesHierarchicalName(t *testing.T) { - now := time.Now().UTC() - var request struct { - Name string `json:"name"` - } - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path != "/v1/buckets/bkt_one/branches" || r.Method != http.MethodPost { - http.NotFound(w, r) - return - } - if err := json.NewDecoder(r.Body).Decode(&request); err != nil { - t.Fatal(err) - } - w.WriteHeader(http.StatusCreated) - _ = json.NewEncoder(w).Encode(client.BucketRef{ - BucketID: "bkt_one", Name: "heads/team/photos", Kind: "explicit", State: "open", - CreatedAt: now, UpdatedAt: now, - }) - })) - defer server.Close() + for _, branch := range []struct{ selector, canonical, ref string }{ + {" heads/team/photos ", "team/photos", "heads/team/photos"}, + {"heads/heads/topic", "heads/heads/topic", "heads/heads/topic"}, + {"heads/heads/heads/topic", "heads/heads/heads/topic", "heads/heads/heads/topic"}, + } { + t.Run(branch.selector, func(t *testing.T) { + now := time.Now().UTC() + var request struct { + Name string `json:"name"` + } + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path != "/v1/buckets/bkt_one/branches" || r.Method != http.MethodPost { + http.NotFound(w, r) + return + } + if err := json.NewDecoder(r.Body).Decode(&request); err != nil { + t.Fatal(err) + } + w.WriteHeader(http.StatusCreated) + _ = json.NewEncoder(w).Encode(client.BucketRef{ + BucketID: "bkt_one", Name: branch.ref, Kind: "explicit", State: "open", + CreatedAt: now, UpdatedAt: now, + }) + })) + defer server.Close() - transport, err := client.New(client.Options{ - BaseURL: server.URL, TenantBearerToken: "tenant-secret", BucketID: "bkt_one", - }) - if err != nil { - t.Fatal(err) - } - value, err := transport.CreateBucketBranch(t.Context(), " heads/team/photos ", "") - if err != nil { - t.Fatal(err) - } - if request.Name != "team/photos" || value.Name != "heads/team/photos" { - t.Fatalf("request=%#v branch=%#v", request, value) + transport, err := client.New(client.Options{ + BaseURL: server.URL, TenantBearerToken: "tenant-secret", BucketID: "bkt_one", + }) + if err != nil { + t.Fatal(err) + } + value, err := transport.CreateBucketBranch(t.Context(), branch.selector, "") + if err != nil { + t.Fatal(err) + } + if request.Name != branch.canonical || value.Name != branch.ref { + t.Fatalf("request=%#v branch=%#v", request, value) + } + }) } } diff --git a/transport/capabilities.go b/transport/capabilities.go index 61b37aa..aa2161e 100644 --- a/transport/capabilities.go +++ b/transport/capabilities.go @@ -4,20 +4,20 @@ import ( "context" "fmt" - transportcap "github.com/dewebprotocol/malt-client/transport/capability" + "github.com/dewebprotocol/malt-client/nodeapi" ) // DatasetBinding identifies the logical dataset selected by this Gateway HTTP // adapter without exposing its URL or routes to application code. -func (c *Client) DatasetBinding() transportcap.DatasetBinding { +func (c *Client) DatasetBinding() nodeapi.DatasetBinding { if c == nil { - return transportcap.DatasetBinding{} + return nodeapi.DatasetBinding{} } - return transportcap.DatasetBinding{DatasetID: c.SelectedBucket(), Branch: c.SelectedBucketBranch()} + return nodeapi.DatasetBinding{DatasetID: c.SelectedBucket(), Branch: c.SelectedBucketBranch()} } // ObserveHead implements the transport-neutral dataset capability. -func (c *Client) ObserveHead(ctx context.Context) (*transportcap.ObservedHead, error) { +func (c *Client) ObserveHead(ctx context.Context) (*nodeapi.ObservedHead, error) { value, err := c.BucketHead(ctx) if err != nil { return nil, err @@ -31,8 +31,8 @@ func (c *Client) ObserveHead(ctx context.Context) (*transportcap.ObservedHead, e // ApplyCandidate implements the transport-neutral dataset capability. The // Bucket-specific fields remain inside the HTTP adapter. -func (c *Client) ApplyCandidate(ctx context.Context, request transportcap.ApplyRequest) (*transportcap.ApplyResult, error) { - request, err := transportcap.NormalizeApplyRequest(c.SelectedBucketBranch(), request) +func (c *Client) ApplyCandidate(ctx context.Context, request nodeapi.ApplyRequest) (*nodeapi.ApplyResult, error) { + request, err := nodeapi.NormalizeApplyRequest(c.SelectedBucketBranch(), request) if err != nil { return nil, err } @@ -40,7 +40,7 @@ func (c *Client) ApplyCandidate(ctx context.Context, request transportcap.ApplyR PushID: request.OperationID, Branch: request.Branch, BaseCommit: request.BaseCommit, BaseRoot: request.BaseRoot, CandidateRoot: request.CandidateRoot, BaseRevision: request.BaseRevision, - ChangeSetCID: request.ChangeSetCID, Message: request.Message, + ChangeSetCID: request.ChangeSetCID, Message: request.Message, MergePolicy: request.MergePolicy, }) if err != nil { return nil, err @@ -49,22 +49,22 @@ func (c *Client) ApplyCandidate(ctx context.Context, request transportcap.ApplyR return nil, fmt.Errorf("gateway returned a nil Bucket apply result") } result := applyResultFromBucketPush(*value) - if err := transportcap.ValidateApplyResult(c.SelectedBucket(), request, result); err != nil { + if err := nodeapi.ValidateApplyResult(c.SelectedBucket(), request, result); err != nil { return nil, err } return &result, nil } -func observedHeadFromBucketRef(value BucketRef) transportcap.ObservedHead { - return transportcap.ObservedHead{ +func observedHeadFromBucketRef(value BucketRef) nodeapi.ObservedHead { + return nodeapi.ObservedHead{ DatasetID: value.BucketID, Name: value.Name, Kind: value.Kind, State: value.State, CommitID: value.CommitID, Root: value.Root, Revision: value.Revision, CreatedBy: value.CreatedBy, CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt, } } -func commitFromBucketCommit(value BucketCommit) transportcap.Commit { - return transportcap.Commit{ +func commitFromBucketCommit(value BucketCommit) nodeapi.Commit { + return nodeapi.Commit{ ID: value.ID, DatasetID: value.BucketID, Root: value.Root, Parents: append([]string(nil), value.Parents...), BaseRoot: value.BaseRoot, Author: value.Author, Credential: value.Credential, @@ -72,24 +72,24 @@ func commitFromBucketCommit(value BucketCommit) transportcap.Commit { } } -func applyResultFromBucketPush(value BucketPushResult) transportcap.ApplyResult { - result := transportcap.ApplyResult{ +func applyResultFromBucketPush(value BucketPushResult) nodeapi.ApplyResult { + result := nodeapi.ApplyResult{ Status: value.Status, Head: observedHeadFromBucketRef(value.Head), Candidate: commitFromBucketCommit(value.Candidate), Commit: commitFromBucketCommit(value.Commit), MergeBase: value.MergeBase, - Conflicts: make([]transportcap.Conflict, len(value.Conflicts)), + Conflicts: make([]nodeapi.Conflict, len(value.Conflicts)), } if value.Branch != nil { branch := observedHeadFromBucketRef(*value.Branch) result.Branch = &branch } for index, conflict := range value.Conflicts { - result.Conflicts[index] = transportcap.Conflict{ + result.Conflicts[index] = nodeapi.Conflict{ Coordinate: conflict.Coordinate, Base: conflict.Base, Local: conflict.Local, Remote: conflict.Remote, } } return result } -var _ transportcap.CAS = (*Client)(nil) -var _ transportcap.DatasetBranch = (*Client)(nil) +var _ nodeapi.CAS = (*Client)(nil) +var _ nodeapi.DatasetBranch = (*Client)(nil) diff --git a/transport/capabilities_test.go b/transport/capabilities_test.go index 9ca5c0c..20c6ae9 100644 --- a/transport/capabilities_test.go +++ b/transport/capabilities_test.go @@ -5,8 +5,8 @@ import ( "net/http/httptest" "testing" + "github.com/dewebprotocol/malt-client/nodeapi" client "github.com/dewebprotocol/malt-client/transport" - transportcap "github.com/dewebprotocol/malt-client/transport/capability" ) func TestGatewayHTTPAdapterRejectsInvalidSemanticApplyBeforeRequest(t *testing.T) { @@ -22,7 +22,7 @@ func TestGatewayHTTPAdapterRejectsInvalidSemanticApplyBeforeRequest(t *testing.T if err != nil { t.Fatal(err) } - if _, err := remote.ApplyCandidate(t.Context(), transportcap.ApplyRequest{}); err == nil { + if _, err := remote.ApplyCandidate(t.Context(), nodeapi.ApplyRequest{}); err == nil { t.Fatal("ApplyCandidate accepted an incomplete semantic request") } if calls != 0 { diff --git a/transport/capability_contract_test.go b/transport/capability_contract_test.go index 43d7e9b..d05907f 100644 --- a/transport/capability_contract_test.go +++ b/transport/capability_contract_test.go @@ -14,9 +14,9 @@ import ( clientcas "github.com/dewebprotocol/malt-client/internal/cas" casmemory "github.com/dewebprotocol/malt-client/internal/cas/memory" + "github.com/dewebprotocol/malt-client/nodeapi" + "github.com/dewebprotocol/malt-client/nodeapi/nodetest" client "github.com/dewebprotocol/malt-client/transport" - transportcap "github.com/dewebprotocol/malt-client/transport/capability" - "github.com/dewebprotocol/malt-client/transport/capabilitytest" "github.com/dewebprotocol/malt-client/transport/hybrid" localtransport "github.com/dewebprotocol/malt-client/transport/local" cid "github.com/ipfs/go-cid" @@ -24,13 +24,13 @@ import ( func TestCASCapabilityContractAcrossTransports(t *testing.T) { t.Run("mock", func(t *testing.T) { - capabilitytest.RunCAS(t, func(*testing.T) transportcap.CAS { return casmemory.New() }) + nodetest.RunCAS(t, func(*testing.T) nodeapi.CAS { return casmemory.New() }) }) t.Run("gateway-http", func(t *testing.T) { - capabilitytest.RunCAS(t, newContractGateway) + nodetest.RunCAS(t, newContractGateway) }) t.Run("local", func(t *testing.T) { - capabilitytest.RunCAS(t, func(t *testing.T) transportcap.CAS { + nodetest.RunCAS(t, func(t *testing.T) nodeapi.CAS { store, err := localtransport.Open(localtransport.Options{Directory: t.TempDir()}) if err != nil { t.Fatal(err) @@ -40,7 +40,7 @@ func TestCASCapabilityContractAcrossTransports(t *testing.T) { }) }) t.Run("hybrid", func(t *testing.T) { - capabilitytest.RunCAS(t, func(t *testing.T) transportcap.CAS { + nodetest.RunCAS(t, func(t *testing.T) nodeapi.CAS { cache, err := localtransport.Open(localtransport.Options{Directory: t.TempDir()}) if err != nil { t.Fatal(err) @@ -54,7 +54,7 @@ func TestCASCapabilityContractAcrossTransports(t *testing.T) { }) }) t.Run("peer-ready-loopback", func(t *testing.T) { - capabilitytest.RunCAS(t, func(t *testing.T) transportcap.CAS { + nodetest.RunCAS(t, func(t *testing.T) nodeapi.CAS { store, err := localtransport.Open(localtransport.Options{Directory: t.TempDir()}) if err != nil { t.Fatal(err) @@ -68,7 +68,7 @@ func TestCASCapabilityContractAcrossTransports(t *testing.T) { }) } -type peerCASLoopback struct{ remote transportcap.BatchCAS } +type peerCASLoopback struct{ remote nodeapi.BatchCAS } func (p peerCASLoopback) Put(ctx context.Context, body []byte) (cid.Cid, error) { return p.remote.Put(ctx, append([]byte(nil), body...)) @@ -87,10 +87,10 @@ func (p peerCASLoopback) Has(ctx context.Context, key cid.Cid) (bool, error) { return p.remote.Has(ctx, key) } -func (p peerCASLoopback) PutBatch(ctx context.Context, blocks []transportcap.Block) ([]transportcap.PutResult, error) { - cloned := make([]transportcap.Block, len(blocks)) +func (p peerCASLoopback) PutBatch(ctx context.Context, blocks []nodeapi.Block) ([]nodeapi.PutResult, error) { + cloned := make([]nodeapi.Block, len(blocks)) for index, block := range blocks { - cloned[index] = transportcap.Block{Data: append([]byte(nil), block.Data...), Codec: block.Codec} + cloned[index] = nodeapi.Block{Data: append([]byte(nil), block.Data...), Codec: block.Codec} } return p.remote.PutBatch(ctx, cloned) } @@ -104,7 +104,7 @@ type contractGatewayStore struct { blocks map[string][]byte } -func newContractGateway(t *testing.T) transportcap.CAS { +func newContractGateway(t *testing.T) nodeapi.CAS { t.Helper() store := &contractGatewayStore{blocks: make(map[string][]byte)} server := httptest.NewServer(http.HandlerFunc(store.serveHTTP)) @@ -136,7 +136,7 @@ func (s *contractGatewayStore) serveHTTP(response http.ResponseWriter, request * http.Error(response, "invalid codec", http.StatusBadRequest) return } - key, err := clientcas.CIDForBlock(transportcap.Block{Data: body, Codec: codec}) + key, err := clientcas.CIDForBlock(nodeapi.Block{Data: body, Codec: codec}) if err != nil { http.Error(response, err.Error(), http.StatusBadRequest) return @@ -146,8 +146,8 @@ func (s *contractGatewayStore) serveHTTP(response http.ResponseWriter, request * _ = json.NewEncoder(response).Encode(map[string]string{"cid": key.String()}) case request.Method == http.MethodPost && request.URL.Path == base+"/batch": var payload struct { - Profile string `json:"profile"` - Blocks []transportcap.Block `json:"blocks"` + Profile string `json:"profile"` + Blocks []nodeapi.Block `json:"blocks"` } if err := json.NewDecoder(request.Body).Decode(&payload); err != nil || payload.Profile != client.CASPutBatchProfile { http.Error(response, "invalid batch", http.StatusBadRequest) @@ -161,11 +161,11 @@ func (s *contractGatewayStore) serveHTTP(response http.ResponseWriter, request * http.Error(response, err.Error(), http.StatusBadRequest) return } - status := string(transportcap.PutStatusStored) + status := string(nodeapi.PutStatusStored) if _, duplicate := seen[key.String()]; duplicate { - status = string(transportcap.PutStatusDuplicateInRequest) + status = string(nodeapi.PutStatusDuplicateInRequest) } else if s.has(key) { - status = string(transportcap.PutStatusAlreadyPresent) + status = string(nodeapi.PutStatusAlreadyPresent) } seen[key.String()] = struct{}{} s.put(key, block.Data) @@ -236,4 +236,4 @@ func (s *contractGatewayStore) has(key cid.Cid) bool { return ok } -var _ transportcap.BatchCAS = peerCASLoopback{} +var _ nodeapi.BatchCAS = peerCASLoopback{} diff --git a/transport/cas.go b/transport/cas.go index 6fccd27..f2df4c6 100644 --- a/transport/cas.go +++ b/transport/cas.go @@ -9,7 +9,7 @@ import ( "time" clientcas "github.com/dewebprotocol/malt-client/internal/cas" - transportcap "github.com/dewebprotocol/malt-client/transport/capability" + "github.com/dewebprotocol/malt-client/nodeapi" cid "github.com/ipfs/go-cid" ) @@ -20,8 +20,8 @@ const ( MaxCASBatchBytes = 64 << 20 ) -type Block = transportcap.Block -type PutBatchResult = transportcap.PutResult +type Block = nodeapi.Block +type PutBatchResult = nodeapi.PutResult // PutBatchMeasurement is the exact HTTP-message boundary for one CAS batch. // RequestWireBytes and ResponseWireBytes are kept directionally separate; @@ -134,7 +134,7 @@ func (c *Client) PutBatchMeasured(ctx context.Context, blocks []Block) (PutBatch return PutBatchMeasurement{}, fmt.Errorf("%w: CAS batch result %d returned CID %s, want %s", clientcas.ErrCorruptedBlock, i, got, want) } status := clientcas.PutStatus(raw.Status) - if !transportcap.IsValidPutStatus(status) { + if !nodeapi.IsValidPutStatus(status) { return PutBatchMeasurement{}, fmt.Errorf("%w: CAS batch result %d has unsupported status %q", clientcas.ErrCorruptedBlock, i, raw.Status) } results[i] = clientcas.PutResult{CID: got, Status: status} diff --git a/transport/client.go b/transport/client.go index aad4d70..22a75a6 100644 --- a/transport/client.go +++ b/transport/client.go @@ -39,7 +39,8 @@ type Options struct { DeviceAuthorizer DeviceAuthorizer BucketID string // BucketBranch selects the writable Bucket ref used by head and push - // operations. Empty means main. Explicit names never include heads/. + // operations. Empty means main. The optional heads/ namespace is retained + // when the logical branch name itself starts with heads/. BucketBranch string // OperatorBearerToken is sent only by MetricsWithStorage. Non-loopback HTTP // base URLs are rejected when it is configured, and credentialed redirects diff --git a/transport/hybrid/cas.go b/transport/hybrid/cas.go index 174263e..b42ff59 100644 --- a/transport/hybrid/cas.go +++ b/transport/hybrid/cas.go @@ -10,7 +10,7 @@ import ( "reflect" clientcas "github.com/dewebprotocol/malt-client/internal/cas" - transportcap "github.com/dewebprotocol/malt-client/transport/capability" + "github.com/dewebprotocol/malt-client/nodeapi" cid "github.com/ipfs/go-cid" ) @@ -23,16 +23,16 @@ type CASErrorObserver func(error) // alone decides Has and must persist every successful write; Cache is only an // availability/performance optimization. type CASOptions struct { - Primary transportcap.CAS - Cache transportcap.CAS + Primary nodeapi.CAS + Cache nodeapi.CAS OnCacheError CASErrorObserver } // CAS composes an authoritative transport with a non-authoritative verified // cache. It is topology policy, not application policy. type CAS struct { - primary transportcap.CAS - cache transportcap.CAS + primary nodeapi.CAS + cache nodeapi.CAS onCacheError CASErrorObserver } @@ -54,7 +54,7 @@ func (c *CAS) PutWithCodec(ctx context.Context, data []byte, codec uint64) (cid. if err := c.ready(); err != nil { return cid.Undef, err } - want, err := clientcas.CIDForBlock(transportcap.Block{Data: data, Codec: codec}) + want, err := clientcas.CIDForBlock(nodeapi.Block{Data: data, Codec: codec}) if err != nil { return cid.Undef, err } @@ -63,7 +63,7 @@ func (c *CAS) PutWithCodec(ctx context.Context, data []byte, codec uint64) (cid. return cid.Undef, err } if !got.Equals(want) { - return cid.Undef, fmt.Errorf("%w: hybrid primary returned %s, want %s", transportcap.ErrCorruptedBlock, got, want) + return cid.Undef, fmt.Errorf("%w: hybrid primary returned %s, want %s", nodeapi.ErrCorruptedBlock, got, want) } c.fill(ctx, want, data, codec) return want, nil @@ -74,12 +74,12 @@ func (c *CAS) Get(ctx context.Context, key cid.Cid) ([]byte, error) { return nil, err } if !key.Defined() { - return nil, fmt.Errorf("%w: hybrid CAS key is undefined", transportcap.ErrCorruptedBlock) + return nil, fmt.Errorf("%w: hybrid CAS key is undefined", nodeapi.ErrCorruptedBlock) } if data, err := verifiedGet(ctx, c.cache, key); err == nil { return data, nil } else { - if !errors.Is(err, transportcap.ErrNotFound) { + if !errors.Is(err, nodeapi.ErrNotFound) { c.observeCacheError(err) } if err := ctx.Err(); err != nil { @@ -101,25 +101,25 @@ func (c *CAS) Has(ctx context.Context, key cid.Cid) (bool, error) { return false, err } if !key.Defined() { - return false, fmt.Errorf("%w: hybrid CAS key is undefined", transportcap.ErrCorruptedBlock) + return false, fmt.Errorf("%w: hybrid CAS key is undefined", nodeapi.ErrCorruptedBlock) } return c.primary.Has(ctx, key) } -func (c *CAS) PutBatch(ctx context.Context, blocks []transportcap.Block) ([]transportcap.PutResult, error) { +func (c *CAS) PutBatch(ctx context.Context, blocks []nodeapi.Block) ([]nodeapi.PutResult, error) { if err := c.ready(); err != nil { return nil, err } if len(blocks) == 0 { - return []transportcap.PutResult{}, nil + return []nodeapi.PutResult{}, nil } results, err := clientcas.NewVerifyingReader(c.primary).PutBatch(ctx, blocks) if err != nil { return nil, err } for index, result := range results { - if !transportcap.IsValidPutStatus(result.Status) { - return nil, fmt.Errorf("%w: hybrid primary batch result %d has unsupported status %q", transportcap.ErrCorruptedBlock, index, result.Status) + if !nodeapi.IsValidPutStatus(result.Status) { + return nil, fmt.Errorf("%w: hybrid primary batch result %d has unsupported status %q", nodeapi.ErrCorruptedBlock, index, result.Status) } c.fill(ctx, result.CID, blocks[index].Data, blocks[index].Codec) } @@ -136,7 +136,7 @@ func (c *CAS) HasBatch(ctx context.Context, keys []cid.Cid) ([]bool, error) { } for index, key := range keys { if !key.Defined() { - return nil, fmt.Errorf("%w: hybrid CAS batch CID %d is undefined", transportcap.ErrCorruptedBlock, index) + return nil, fmt.Errorf("%w: hybrid CAS batch CID %d is undefined", nodeapi.ErrCorruptedBlock, index) } } if batch, ok := c.primary.(interface { @@ -147,7 +147,7 @@ func (c *CAS) HasBatch(ctx context.Context, keys []cid.Cid) ([]bool, error) { return nil, err } if len(result) != len(keys) { - return nil, fmt.Errorf("%w: hybrid primary returned %d has results for %d CIDs", transportcap.ErrCorruptedBlock, len(result), len(keys)) + return nil, fmt.Errorf("%w: hybrid primary returned %d has results for %d CIDs", nodeapi.ErrCorruptedBlock, len(result), len(keys)) } return result, nil } @@ -168,7 +168,7 @@ func (c *CAS) fill(ctx context.Context, want cid.Cid, data []byte, codec uint64) } got, err := c.cache.PutWithCodec(ctx, data, codec) if err == nil && !got.Equals(want) { - err = fmt.Errorf("%w: hybrid cache returned %s, want %s", transportcap.ErrCorruptedBlock, got, want) + err = fmt.Errorf("%w: hybrid cache returned %s, want %s", nodeapi.ErrCorruptedBlock, got, want) } if err != nil { c.observeCacheError(err) @@ -188,14 +188,14 @@ func (c *CAS) ready() error { return nil } -func verifiedGet(ctx context.Context, source transportcap.CAS, key cid.Cid) ([]byte, error) { +func verifiedGet(ctx context.Context, source nodeapi.CAS, key cid.Cid) ([]byte, error) { data, err := source.Get(ctx, key) if err != nil { return nil, err } got, err := key.Prefix().Sum(data) if err != nil || !got.Equals(key) { - return nil, fmt.Errorf("%w: hybrid source body does not match %s", transportcap.ErrCorruptedBlock, key) + return nil, fmt.Errorf("%w: hybrid source body does not match %s", nodeapi.ErrCorruptedBlock, key) } return data, nil } @@ -213,4 +213,4 @@ func nilInterface(value any) bool { } } -var _ transportcap.BatchCAS = (*CAS)(nil) +var _ nodeapi.BatchCAS = (*CAS)(nil) diff --git a/transport/hybrid/cas_test.go b/transport/hybrid/cas_test.go index 4d1667b..80a6fe0 100644 --- a/transport/hybrid/cas_test.go +++ b/transport/hybrid/cas_test.go @@ -8,12 +8,12 @@ import ( clientcas "github.com/dewebprotocol/malt-client/internal/cas" casmemory "github.com/dewebprotocol/malt-client/internal/cas/memory" - transportcap "github.com/dewebprotocol/malt-client/transport/capability" + "github.com/dewebprotocol/malt-client/nodeapi" cid "github.com/ipfs/go-cid" ) type recordingCAS struct { - transportcap.CAS + nodeapi.CAS gets int has int puts int @@ -68,7 +68,7 @@ func TestCASUsesVerifiedCacheButPrimaryAuthority(t *testing.T) { func TestCASFallsBackFromCorruptCacheAndRepairsIt(t *testing.T) { body := []byte("verified primary payload") - key, err := clientcas.CIDForBlock(transportcap.Block{Data: body}) + key, err := clientcas.CIDForBlock(nodeapi.Block{Data: body}) if err != nil { t.Fatal(err) } @@ -88,7 +88,7 @@ func TestCASFallsBackFromCorruptCacheAndRepairsIt(t *testing.T) { if err != nil || !bytes.Equal(got, body) { t.Fatalf("Get = %q, %v", got, err) } - if len(observed) != 1 || !errors.Is(observed[0], transportcap.ErrCorruptedBlock) { + if len(observed) != 1 || !errors.Is(observed[0], nodeapi.ErrCorruptedBlock) { t.Fatalf("cache observations = %v", observed) } cache.getBody = nil @@ -100,7 +100,7 @@ func TestCASFallsBackFromCorruptCacheAndRepairsIt(t *testing.T) { func TestCASRejectsSubstitutedPrimaryAndIgnoresCacheWriteFailure(t *testing.T) { wantBody := []byte("expected primary") - want, err := clientcas.CIDForBlock(transportcap.Block{Data: wantBody}) + want, err := clientcas.CIDForBlock(nodeapi.Block{Data: wantBody}) if err != nil { t.Fatal(err) } @@ -109,7 +109,7 @@ func TestCASRejectsSubstitutedPrimaryAndIgnoresCacheWriteFailure(t *testing.T) { if err != nil { t.Fatal(err) } - if _, err := store.Get(t.Context(), want); !errors.Is(err, transportcap.ErrCorruptedBlock) { + if _, err := store.Get(t.Context(), want); !errors.Is(err, nodeapi.ErrCorruptedBlock) { t.Fatalf("substituted primary error = %v, want ErrCorruptedBlock", err) } @@ -146,7 +146,7 @@ func TestCASRejectsTypedNilCapabilities(t *testing.T) { func TestCASClassifiesMalformedPrimaryBatchResultsAsCorruption(t *testing.T) { body := []byte("batch-body") - key, err := clientcas.CIDForBlock(transportcap.Block{Data: body}) + key, err := clientcas.CIDForBlock(nodeapi.Block{Data: body}) if err != nil { t.Fatal(err) } @@ -156,16 +156,16 @@ func TestCASClassifiesMalformedPrimaryBatchResultsAsCorruption(t *testing.T) { call func(*CAS) error }{ { - name: "put result length", primary: &malformedBatchCAS{CAS: casmemory.New(), putResults: []transportcap.PutResult{}}, + name: "put result length", primary: &malformedBatchCAS{CAS: casmemory.New(), putResults: []nodeapi.PutResult{}}, call: func(store *CAS) error { - _, err := store.PutBatch(t.Context(), []transportcap.Block{{Data: body}}) + _, err := store.PutBatch(t.Context(), []nodeapi.Block{{Data: body}}) return err }, }, { - name: "put status", primary: &malformedBatchCAS{CAS: casmemory.New(), putResults: []transportcap.PutResult{{CID: key, Status: "invented"}}}, + name: "put status", primary: &malformedBatchCAS{CAS: casmemory.New(), putResults: []nodeapi.PutResult{{CID: key, Status: "invented"}}}, call: func(store *CAS) error { - _, err := store.PutBatch(t.Context(), []transportcap.Block{{Data: body}}) + _, err := store.PutBatch(t.Context(), []nodeapi.Block{{Data: body}}) return err }, }, @@ -179,7 +179,7 @@ func TestCASClassifiesMalformedPrimaryBatchResultsAsCorruption(t *testing.T) { if err != nil { t.Fatal(err) } - if err := test.call(store); !errors.Is(err, transportcap.ErrCorruptedBlock) { + if err := test.call(store); !errors.Is(err, nodeapi.ErrCorruptedBlock) { t.Fatalf("error = %v, want ErrCorruptedBlock", err) } }) @@ -187,7 +187,7 @@ func TestCASClassifiesMalformedPrimaryBatchResultsAsCorruption(t *testing.T) { } type substitutingCAS struct { - transportcap.CAS + nodeapi.CAS getBody []byte } @@ -199,18 +199,18 @@ func (c *substitutingCAS) Get(ctx context.Context, key cid.Cid) ([]byte, error) } type failingPutCAS struct { - transportcap.CAS + nodeapi.CAS err error } type malformedBatchCAS struct { - transportcap.CAS - putResults []transportcap.PutResult + nodeapi.CAS + putResults []nodeapi.PutResult hasResults []bool } -func (c *malformedBatchCAS) PutBatch(context.Context, []transportcap.Block) ([]transportcap.PutResult, error) { - return append([]transportcap.PutResult(nil), c.putResults...), nil +func (c *malformedBatchCAS) PutBatch(context.Context, []nodeapi.Block) ([]nodeapi.PutResult, error) { + return append([]nodeapi.PutResult(nil), c.putResults...), nil } func (c *malformedBatchCAS) HasBatch(context.Context, []cid.Cid) ([]bool, error) { diff --git a/transport/local/cas.go b/transport/local/cas.go index 3098a73..3299f30 100644 --- a/transport/local/cas.go +++ b/transport/local/cas.go @@ -13,7 +13,7 @@ import ( "sync/atomic" clientcas "github.com/dewebprotocol/malt-client/internal/cas" - transportcap "github.com/dewebprotocol/malt-client/transport/capability" + "github.com/dewebprotocol/malt-client/nodeapi" cid "github.com/ipfs/go-cid" mh "github.com/multiformats/go-multihash" ) @@ -145,7 +145,7 @@ func (s *CAS) PutWithCodec(ctx context.Context, data []byte, codec uint64) (cid. if int64(len(data)) > s.maxBlockBytes { return cid.Undef, fmt.Errorf("local CAS block exceeds %d bytes", s.maxBlockBytes) } - key, err := clientcas.CIDForBlock(transportcap.Block{Data: data, Codec: codec}) + key, err := clientcas.CIDForBlock(nodeapi.Block{Data: data, Codec: codec}) if err != nil { return cid.Undef, fmt.Errorf("compute local CAS CID: %w", err) } @@ -170,7 +170,7 @@ func (s *CAS) Has(ctx context.Context, key cid.Cid) (bool, error) { return false, err } _, err := s.readBlock(ctx, key) - if errors.Is(err, transportcap.ErrNotFound) { + if errors.Is(err, nodeapi.ErrNotFound) { return false, nil } if err != nil { @@ -179,7 +179,7 @@ func (s *CAS) Has(ctx context.Context, key cid.Cid) (bool, error) { return true, nil } -func (s *CAS) PutBatch(ctx context.Context, blocks []transportcap.Block) ([]transportcap.PutResult, error) { +func (s *CAS) PutBatch(ctx context.Context, blocks []nodeapi.Block) ([]nodeapi.PutResult, error) { if err := s.ready(); err != nil { return nil, err } @@ -187,7 +187,7 @@ func (s *CAS) PutBatch(ctx context.Context, blocks []transportcap.Block) ([]tran return nil, err } if len(blocks) == 0 { - return []transportcap.PutResult{}, nil + return []nodeapi.PutResult{}, nil } if len(blocks) > s.maxBatchBlocks { return nil, fmt.Errorf("local CAS batch exceeds %d blocks", s.maxBatchBlocks) @@ -208,7 +208,7 @@ func (s *CAS) PutBatch(ctx context.Context, blocks []transportcap.Block) ([]tran s.mu.Lock() defer s.mu.Unlock() - results := make([]transportcap.PutResult, len(blocks)) + results := make([]nodeapi.PutResult, len(blocks)) seen := make(map[string]struct{}, len(blocks)) for index, block := range blocks { if err := ctx.Err(); err != nil { @@ -216,7 +216,7 @@ func (s *CAS) PutBatch(ctx context.Context, blocks []transportcap.Block) ([]tran } key := keys[index] if _, duplicate := seen[key.String()]; duplicate { - results[index] = transportcap.PutResult{CID: key, Status: transportcap.PutStatusDuplicateInRequest} + results[index] = nodeapi.PutResult{CID: key, Status: nodeapi.PutStatusDuplicateInRequest} continue } seen[key.String()] = struct{}{} @@ -224,7 +224,7 @@ func (s *CAS) PutBatch(ctx context.Context, blocks []transportcap.Block) ([]tran if err != nil { return nil, fmt.Errorf("store local CAS batch block %d: %w", index, err) } - results[index] = transportcap.PutResult{CID: key, Status: status} + results[index] = nodeapi.PutResult{CID: key, Status: status} } return results, nil } @@ -244,7 +244,7 @@ func (s *CAS) HasBatch(ctx context.Context, keys []cid.Cid) ([]bool, error) { } for index, key := range keys { if !key.Defined() { - return nil, fmt.Errorf("%w: local CAS batch CID %d is undefined", transportcap.ErrCorruptedBlock, index) + return nil, fmt.Errorf("%w: local CAS batch CID %d is undefined", nodeapi.ErrCorruptedBlock, index) } } result := make([]bool, len(keys)) @@ -258,14 +258,14 @@ func (s *CAS) HasBatch(ctx context.Context, keys []cid.Cid) ([]bool, error) { return result, nil } -func (s *CAS) putLocked(ctx context.Context, key cid.Cid, data []byte) (transportcap.PutStatus, error) { +func (s *CAS) putLocked(ctx context.Context, key cid.Cid, data []byte) (nodeapi.PutStatus, error) { shard, name := blockIdentity(key) if _, err := s.readBlock(ctx, key); err == nil { if err := s.platform.ensureDurable(ctx, shard); err != nil { return "", fmt.Errorf("confirm existing local CAS block durability: %w", err) } - return transportcap.PutStatusAlreadyPresent, nil - } else if !errors.Is(err, transportcap.ErrNotFound) && !errors.Is(err, transportcap.ErrCorruptedBlock) { + return nodeapi.PutStatusAlreadyPresent, nil + } else if !errors.Is(err, nodeapi.ErrNotFound) && !errors.Is(err, nodeapi.ErrCorruptedBlock) { return "", err } @@ -278,7 +278,7 @@ func (s *CAS) putLocked(ctx context.Context, key cid.Cid, data []byte) (transpor if err := s.platform.ensureDurable(ctx, shard); err != nil { return "", fmt.Errorf("confirm installed local CAS block durability: %w", err) } - return transportcap.PutStatusStored, nil + return nodeapi.PutStatusStored, nil } func (s *CAS) readBlock(ctx context.Context, key cid.Cid) ([]byte, error) { @@ -286,7 +286,7 @@ func (s *CAS) readBlock(ctx context.Context, key cid.Cid) ([]byte, error) { return nil, err } if !key.Defined() { - return nil, fmt.Errorf("%w: local CAS key is undefined", transportcap.ErrCorruptedBlock) + return nil, fmt.Errorf("%w: local CAS key is undefined", nodeapi.ErrCorruptedBlock) } shard, name := blockIdentity(key) data, err := s.platform.readBlock(ctx, shard, name, s.maxBlockBytes) @@ -298,7 +298,7 @@ func (s *CAS) readBlock(ctx context.Context, key cid.Cid) ([]byte, error) { } got, err := key.Prefix().Sum(data) if err != nil || !got.Equals(key) { - return nil, fmt.Errorf("%w: local CAS body does not match %s", transportcap.ErrCorruptedBlock, key) + return nil, fmt.Errorf("%w: local CAS body does not match %s", nodeapi.ErrCorruptedBlock, key) } return data, nil } @@ -335,7 +335,7 @@ func (s *CAS) ready() error { return nil } -var _ transportcap.BatchCAS = (*CAS)(nil) +var _ nodeapi.BatchCAS = (*CAS)(nil) type blockStore interface { readBlock(context.Context, string, string, int64) ([]byte, error) diff --git a/transport/local/cas_test.go b/transport/local/cas_test.go index 7d0b215..ac07b87 100644 --- a/transport/local/cas_test.go +++ b/transport/local/cas_test.go @@ -13,13 +13,13 @@ import ( "testing" clientcas "github.com/dewebprotocol/malt-client/internal/cas" - transportcap "github.com/dewebprotocol/malt-client/transport/capability" + "github.com/dewebprotocol/malt-client/nodeapi" cid "github.com/ipfs/go-cid" ) func TestBlockIdentityShardsByDigestByte(t *testing.T) { for _, body := range [][]byte{[]byte("a"), []byte("b")} { - key, err := clientcas.CIDForBlock(transportcap.Block{Data: body, Codec: cid.Raw}) + key, err := clientcas.CIDForBlock(nodeapi.Block{Data: body, Codec: cid.Raw}) if err != nil { t.Fatal(err) } @@ -74,10 +74,10 @@ func TestCASRejectsCorruptionAndPutRepairsExactBlock(t *testing.T) { if err := os.WriteFile(store.blockPath(key), []byte("substituted"), 0o600); err != nil { t.Fatal(err) } - if _, err := store.Get(t.Context(), key); !errors.Is(err, transportcap.ErrCorruptedBlock) { + if _, err := store.Get(t.Context(), key); !errors.Is(err, nodeapi.ErrCorruptedBlock) { t.Fatalf("corrupt Get error = %v, want ErrCorruptedBlock", err) } - if _, err := store.Has(t.Context(), key); !errors.Is(err, transportcap.ErrCorruptedBlock) { + if _, err := store.Has(t.Context(), key); !errors.Is(err, nodeapi.ErrCorruptedBlock) { t.Fatalf("corrupt Has error = %v, want ErrCorruptedBlock", err) } repaired, err := store.Put(t.Context(), body) @@ -92,10 +92,10 @@ func TestCASRejectsCorruptionAndPutRepairsExactBlock(t *testing.T) { func TestCASBatchPreflightAndDuplicateIdentity(t *testing.T) { store := openTestCAS(t, Options{Directory: t.TempDir(), MaxBlockBytes: 8, MaxBatchBytes: 8, MaxBatchBlocks: 3}) - if _, err := store.PutBatch(t.Context(), []transportcap.Block{{Data: []byte("small")}, {Data: []byte("too-large")}}); err == nil { + if _, err := store.PutBatch(t.Context(), []nodeapi.Block{{Data: []byte("small")}, {Data: []byte("too-large")}}); err == nil { t.Fatal("oversized batch succeeded") } - small, err := clientcas.CIDForBlock(transportcap.Block{Data: []byte("small")}) + small, err := clientcas.CIDForBlock(nodeapi.Block{Data: []byte("small")}) if err != nil { t.Fatal(err) } @@ -103,11 +103,11 @@ func TestCASBatchPreflightAndDuplicateIdentity(t *testing.T) { if err != nil || present { t.Fatalf("preflight wrote first block: present=%v err=%v", present, err) } - results, err := store.PutBatch(t.Context(), []transportcap.Block{{Data: []byte("same")}, {Data: []byte("same")}}) + results, err := store.PutBatch(t.Context(), []nodeapi.Block{{Data: []byte("same")}, {Data: []byte("same")}}) if err != nil { t.Fatal(err) } - if len(results) != 2 || !results[0].CID.Equals(results[1].CID) || results[1].Status != transportcap.PutStatusDuplicateInRequest { + if len(results) != 2 || !results[0].CID.Equals(results[1].CID) || results[1].Status != nodeapi.PutStatusDuplicateInRequest { t.Fatalf("duplicate results = %#v", results) } } @@ -116,7 +116,7 @@ func TestCASBatchErrorMayLeaveVerifiedSubsetAndWholeBatchRetryIsSafe(t *testing. store := openTestCAS(t, Options{Directory: t.TempDir()}) ctx, cancel := context.WithCancel(t.Context()) store.platform = &cancelAfterWriteStore{inner: store.platform, cancel: cancel} - blocks := []transportcap.Block{{Data: []byte("persisted-before-cancel")}, {Data: []byte("not-yet-persisted")}} + blocks := []nodeapi.Block{{Data: []byte("persisted-before-cancel")}, {Data: []byte("not-yet-persisted")}} results, err := store.PutBatch(ctx, blocks) if !errors.Is(err, context.Canceled) || results != nil { t.Fatalf("canceled PutBatch = %#v, %v; want nil, context.Canceled", results, err) @@ -144,7 +144,7 @@ func TestCASConcurrentImmutableWrites(t *testing.T) { first := openTestCAS(t, Options{Directory: directory}) second := openTestCAS(t, Options{Directory: directory}) body := bytes.Repeat([]byte("concurrent"), 1024) - want, err := clientcas.CIDForBlock(transportcap.Block{Data: body, Codec: cid.Raw}) + want, err := clientcas.CIDForBlock(nodeapi.Block{Data: body, Codec: cid.Raw}) if err != nil { t.Fatal(err) } diff --git a/transport/local/cas_unix_test.go b/transport/local/cas_unix_test.go index 0ca1c1e..c4ecfda 100644 --- a/transport/local/cas_unix_test.go +++ b/transport/local/cas_unix_test.go @@ -14,14 +14,14 @@ import ( "time" clientcas "github.com/dewebprotocol/malt-client/internal/cas" - transportcap "github.com/dewebprotocol/malt-client/transport/capability" + "github.com/dewebprotocol/malt-client/nodeapi" "golang.org/x/sys/unix" ) func TestCASRejectsFIFOWithoutBlockingAndPutRepairs(t *testing.T) { store := openTestCAS(t, Options{Directory: t.TempDir()}) body := []byte("fifo-repair") - key, err := clientcas.CIDForBlock(transportcap.Block{Data: body}) + key, err := clientcas.CIDForBlock(nodeapi.Block{Data: body}) if err != nil { t.Fatal(err) } @@ -37,14 +37,14 @@ func TestCASRejectsFIFOWithoutBlockingAndPutRepairs(t *testing.T) { _, err := store.Get(t.Context(), key) return err }) - if !errors.Is(getErr, transportcap.ErrCorruptedBlock) { + if !errors.Is(getErr, nodeapi.ErrCorruptedBlock) { t.Fatalf("Get FIFO error = %v, want ErrCorruptedBlock", getErr) } hasErr := callLocalCASWithin(t, func() error { _, err := store.Has(t.Context(), key) return err }) - if !errors.Is(hasErr, transportcap.ErrCorruptedBlock) { + if !errors.Is(hasErr, nodeapi.ErrCorruptedBlock) { t.Fatalf("Has FIFO error = %v, want ErrCorruptedBlock", hasErr) } putErr := callLocalCASWithin(t, func() error { @@ -70,7 +70,7 @@ func TestCASRepairsUnreadableOrNonRegularTargets(t *testing.T) { t.Cleanup(func() { _ = os.RemoveAll(base) }) store := openTestCAS(t, Options{Directory: base}) body := []byte("repair-unreadable-" + object) - key, err := clientcas.CIDForBlock(transportcap.Block{Data: body}) + key, err := clientcas.CIDForBlock(nodeapi.Block{Data: body}) if err != nil { t.Fatal(err) } @@ -102,7 +102,7 @@ func TestCASRepairsUnreadableOrNonRegularTargets(t *testing.T) { _, err := store.Get(t.Context(), key) return err }) - if !errors.Is(getErr, transportcap.ErrCorruptedBlock) { + if !errors.Is(getErr, nodeapi.ErrCorruptedBlock) { t.Fatalf("Get unsafe target error = %v, want ErrCorruptedBlock", getErr) } if _, err := store.Put(t.Context(), body); err != nil { @@ -132,7 +132,7 @@ func TestCASPutRetriesUnconfirmedDirectoryDurability(t *testing.T) { t.Run(test.name, func(t *testing.T) { store := openTestCAS(t, Options{Directory: t.TempDir()}) body := []byte("durability-retry-" + test.name) - key, err := clientcas.CIDForBlock(transportcap.Block{Data: body}) + key, err := clientcas.CIDForBlock(nodeapi.Block{Data: body}) if err != nil { t.Fatal(err) } @@ -197,7 +197,7 @@ func TestCASCloseRetriesOnlyUnconfirmedPlatformComponents(t *testing.T) { if store.platform == nil || platform.blocks != nil || platform.root != nil { t.Fatalf("failed Close ownership = store:%T blocks:%v root:%v", store.platform, platform.blocks, platform.root) } - key, err := clientcas.CIDForBlock(transportcap.Block{Data: []byte("closed")}) + key, err := clientcas.CIDForBlock(nodeapi.Block{Data: []byte("closed")}) if err != nil { t.Fatal(err) } @@ -390,7 +390,7 @@ func TestCASOpenHandleContainsPostOpenBoundaryReplacement(t *testing.T) { func TestCASRejectsShardSymlinkWithoutWritingOutsideBoundary(t *testing.T) { store := openTestCAS(t, Options{Directory: t.TempDir()}) body := []byte("shard-symlink-attack") - key, err := clientcas.CIDForBlock(transportcap.Block{Data: body}) + key, err := clientcas.CIDForBlock(nodeapi.Block{Data: body}) if err != nil { t.Fatal(err) } @@ -399,7 +399,7 @@ func TestCASRejectsShardSymlinkWithoutWritingOutsideBoundary(t *testing.T) { if err := os.Symlink(external, filepath.Join(store.blocks, shard)); err != nil { t.Fatal(err) } - if _, err := store.Put(t.Context(), body); !errors.Is(err, transportcap.ErrCorruptedBlock) { + if _, err := store.Put(t.Context(), body); !errors.Is(err, nodeapi.ErrCorruptedBlock) { t.Fatalf("Put through shard symlink error = %v, want ErrCorruptedBlock", err) } if _, err := os.Stat(filepath.Join(external, name)); !errors.Is(err, os.ErrNotExist) { @@ -412,7 +412,7 @@ func TestCASReplacesUnsafeTargetWithoutChangingExternalInode(t *testing.T) { t.Run(attack, func(t *testing.T) { store := openTestCAS(t, Options{Directory: t.TempDir()}) body := []byte("safe-target-replacement-" + attack) - key, err := clientcas.CIDForBlock(transportcap.Block{Data: body}) + key, err := clientcas.CIDForBlock(nodeapi.Block{Data: body}) if err != nil { t.Fatal(err) } @@ -468,10 +468,10 @@ func TestCASVerifiedReadRejectsAndPutRepairsUnsafeBlockPermissions(t *testing.T) if err := os.Chmod(store.blockPath(key), 0o644); err != nil { t.Fatal(err) } - if _, err := store.Get(t.Context(), key); !errors.Is(err, transportcap.ErrCorruptedBlock) { + if _, err := store.Get(t.Context(), key); !errors.Is(err, nodeapi.ErrCorruptedBlock) { t.Fatalf("Get unsafe block error = %v, want ErrCorruptedBlock", err) } - if _, err := store.Has(t.Context(), key); !errors.Is(err, transportcap.ErrCorruptedBlock) { + if _, err := store.Has(t.Context(), key); !errors.Is(err, nodeapi.ErrCorruptedBlock) { t.Fatalf("Has unsafe block error = %v, want ErrCorruptedBlock", err) } if _, err := store.Put(t.Context(), []byte("permission-restoration")); err != nil { @@ -497,7 +497,7 @@ func TestCASVerifiedReadDoesNotMutateUnsafeShardPermissions(t *testing.T) { if err := os.Chmod(shard, 0o755); err != nil { t.Fatal(err) } - if _, err := store.Get(t.Context(), key); !errors.Is(err, transportcap.ErrCorruptedBlock) { + if _, err := store.Get(t.Context(), key); !errors.Is(err, nodeapi.ErrCorruptedBlock) { t.Fatalf("Get unsafe shard error = %v, want ErrCorruptedBlock", err) } info, err := os.Stat(shard) @@ -530,7 +530,7 @@ func TestCASUnreadableShardRequiresExplicitOfflineRepair(t *testing.T) { if err := os.Chmod(shard, 0); err != nil { t.Fatal(err) } - if _, err := store.Get(t.Context(), key); !errors.Is(err, transportcap.ErrCorruptedBlock) { + if _, err := store.Get(t.Context(), key); !errors.Is(err, nodeapi.ErrCorruptedBlock) { t.Fatalf("Get unreadable shard error = %v, want ErrCorruptedBlock", err) } info, err := os.Stat(shard) @@ -540,7 +540,7 @@ func TestCASUnreadableShardRequiresExplicitOfflineRepair(t *testing.T) { if got := info.Mode().Perm(); got != 0 { t.Fatalf("verified read mutated unreadable shard permissions to %#o", got) } - if _, err := store.Put(t.Context(), body); !errors.Is(err, transportcap.ErrCorruptedBlock) { + if _, err := store.Put(t.Context(), body); !errors.Is(err, nodeapi.ErrCorruptedBlock) { t.Fatalf("Put unreadable shard error = %v, want safe refusal", err) } info, err = os.Stat(shard) diff --git a/transport/local/platform_unix.go b/transport/local/platform_unix.go index 9d143e4..6bd5b85 100644 --- a/transport/local/platform_unix.go +++ b/transport/local/platform_unix.go @@ -12,7 +12,7 @@ import ( "os" "path/filepath" - transportcap "github.com/dewebprotocol/malt-client/transport/capability" + "github.com/dewebprotocol/malt-client/nodeapi" "golang.org/x/sys/unix" ) @@ -198,17 +198,17 @@ func (s *platformStore) readBlock(ctx context.Context, shard, name string, maxBy fd, err := unix.Openat(shardFD, name, unix.O_RDONLY|unix.O_NONBLOCK|unix.O_CLOEXEC|unix.O_NOFOLLOW, 0) if err != nil { if errors.Is(err, unix.ENOENT) { - return nil, fmt.Errorf("%w: local CAS block is absent", transportcap.ErrNotFound) + return nil, fmt.Errorf("%w: local CAS block is absent", nodeapi.ErrNotFound) } if errors.Is(err, unix.ELOOP) || errors.Is(err, unix.ENOTDIR) { - return nil, fmt.Errorf("%w: local CAS block path is unsafe", transportcap.ErrCorruptedBlock) + return nil, fmt.Errorf("%w: local CAS block path is unsafe", nodeapi.ErrCorruptedBlock) } if errors.Is(err, unix.EACCES) || errors.Is(err, unix.EPERM) || errors.Is(err, unix.ENXIO) || errors.Is(err, unix.ENODEV) { var stat unix.Stat_t if inspectErr := unix.Fstatat(shardFD, name, &stat, unix.AT_SYMLINK_NOFOLLOW); inspectErr == nil && unsafeUnixBlockMetadata(&stat) { - return nil, fmt.Errorf("%w: local CAS block exists but is unreadable or is not a regular file", transportcap.ErrCorruptedBlock) + return nil, fmt.Errorf("%w: local CAS block exists but is unreadable or is not a regular file", nodeapi.ErrCorruptedBlock) } else if errors.Is(inspectErr, unix.ENOENT) { - return nil, fmt.Errorf("%w: local CAS block is absent", transportcap.ErrNotFound) + return nil, fmt.Errorf("%w: local CAS block is absent", nodeapi.ErrNotFound) } } return nil, fmt.Errorf("open local CAS block without following links: %w", err) @@ -228,20 +228,20 @@ func (s *platformStore) readBlock(ctx context.Context, shard, name string, maxBy // this already-open immutable inode to zero. That handle is still contained // and safe to verify; only additional hard links create an external alias. if stat.Mode&unix.S_IFMT != unix.S_IFREG || stat.Nlink > 1 { - return nil, fmt.Errorf("%w: local CAS block must be a regular file without additional hard links", transportcap.ErrCorruptedBlock) + return nil, fmt.Errorf("%w: local CAS block must be a regular file without additional hard links", nodeapi.ErrCorruptedBlock) } if stat.Mode&0o777 != 0o600 || stat.Uid != uint32(os.Geteuid()) { - return nil, fmt.Errorf("%w: local CAS block is not owner-private", transportcap.ErrCorruptedBlock) + return nil, fmt.Errorf("%w: local CAS block is not owner-private", nodeapi.ErrCorruptedBlock) } if stat.Size < 0 || stat.Size > maxBytes { - return nil, fmt.Errorf("%w: local CAS block exceeds %d bytes", transportcap.ErrCorruptedBlock, maxBytes) + return nil, fmt.Errorf("%w: local CAS block exceeds %d bytes", nodeapi.ErrCorruptedBlock, maxBytes) } data, err := io.ReadAll(io.LimitReader(file, maxBytes+1)) if err != nil { return nil, fmt.Errorf("read local CAS block: %w", err) } if int64(len(data)) > maxBytes { - return nil, fmt.Errorf("%w: local CAS block exceeds %d bytes", transportcap.ErrCorruptedBlock, maxBytes) + return nil, fmt.Errorf("%w: local CAS block exceeds %d bytes", nodeapi.ErrCorruptedBlock, maxBytes) } if err := ctx.Err(); err != nil { return nil, err @@ -326,17 +326,17 @@ func (s *platformStore) openShard(shard string, create bool) (*os.File, error) { fd, err := unix.Openat(blocksFD, shard, unix.O_RDONLY|unix.O_DIRECTORY|unix.O_CLOEXEC|unix.O_NOFOLLOW, 0) if err != nil { if errors.Is(err, unix.ENOENT) && !create { - return nil, fmt.Errorf("%w: local CAS shard is absent", transportcap.ErrNotFound) + return nil, fmt.Errorf("%w: local CAS shard is absent", nodeapi.ErrNotFound) } if errors.Is(err, unix.ELOOP) || errors.Is(err, unix.ENOTDIR) { - return nil, fmt.Errorf("%w: local CAS shard path is unsafe", transportcap.ErrCorruptedBlock) + return nil, fmt.Errorf("%w: local CAS shard path is unsafe", nodeapi.ErrCorruptedBlock) } if errors.Is(err, unix.EACCES) || errors.Is(err, unix.EPERM) { var stat unix.Stat_t if inspectErr := unix.Fstatat(blocksFD, shard, &stat, unix.AT_SYMLINK_NOFOLLOW); inspectErr == nil && unsafeUnixShardMetadata(&stat) { - return nil, fmt.Errorf("%w: local CAS shard exists but is not safely searchable; repair its owner-private directory metadata offline", transportcap.ErrCorruptedBlock) + return nil, fmt.Errorf("%w: local CAS shard exists but is not safely searchable; repair its owner-private directory metadata offline", nodeapi.ErrCorruptedBlock) } else if errors.Is(inspectErr, unix.ENOENT) && !create { - return nil, fmt.Errorf("%w: local CAS shard is absent", transportcap.ErrNotFound) + return nil, fmt.Errorf("%w: local CAS shard is absent", nodeapi.ErrNotFound) } } return nil, fmt.Errorf("open local CAS shard without following links: %w", err) @@ -348,7 +348,7 @@ func (s *platformStore) openShard(shard string, create bool) (*os.File, error) { } if err := requireUnixDirectory(fd, "local CAS shard"); err != nil { _ = directory.Close() - return nil, fmt.Errorf("%w: %v", transportcap.ErrCorruptedBlock, err) + return nil, fmt.Errorf("%w: %v", nodeapi.ErrCorruptedBlock, err) } var stat unix.Stat_t if err := unix.Fstat(fd, &stat); err != nil { @@ -361,7 +361,7 @@ func (s *platformStore) openShard(shard string, create bool) (*os.File, error) { // unrelated immutable blocks back into an online write target. if !created && stat.Mode&0o500 != 0o500 { _ = directory.Close() - return nil, fmt.Errorf("%w: local CAS shard is not safely searchable; repair its owner-private directory metadata offline", transportcap.ErrCorruptedBlock) + return nil, fmt.Errorf("%w: local CAS shard is not safely searchable; repair its owner-private directory metadata offline", nodeapi.ErrCorruptedBlock) } if create { if err := unix.Fchmod(fd, 0o700); err != nil { @@ -371,7 +371,7 @@ func (s *platformStore) openShard(shard string, create bool) (*os.File, error) { } else { if stat.Mode&0o777 != 0o700 { _ = directory.Close() - return nil, fmt.Errorf("%w: local CAS shard is not owner-private", transportcap.ErrCorruptedBlock) + return nil, fmt.Errorf("%w: local CAS shard is not owner-private", nodeapi.ErrCorruptedBlock) } } if create { diff --git a/transport/local/platform_windows.go b/transport/local/platform_windows.go index 1c670bb..45ba53a 100644 --- a/transport/local/platform_windows.go +++ b/transport/local/platform_windows.go @@ -13,7 +13,7 @@ import ( "path/filepath" "github.com/dewebprotocol/malt-client/internal/securefile" - transportcap "github.com/dewebprotocol/malt-client/transport/capability" + "github.com/dewebprotocol/malt-client/nodeapi" "golang.org/x/sys/windows" ) @@ -121,16 +121,16 @@ func (s *platformStore) readBlock(ctx context.Context, shard, name string, maxBy metadataHandle, metadata, err := openWindowsFile(path, windows.READ_CONTROL, windows.OPEN_EXISTING, true) if err != nil { if errors.Is(err, windows.ERROR_FILE_NOT_FOUND) || errors.Is(err, windows.ERROR_PATH_NOT_FOUND) { - return nil, fmt.Errorf("%w: local CAS block is absent", transportcap.ErrNotFound) + return nil, fmt.Errorf("%w: local CAS block is absent", nodeapi.ErrNotFound) } if errors.Is(err, windows.ERROR_ACCESS_DENIED) { fallback, _, inspectErr := openWindowsFile(path, 0, windows.OPEN_EXISTING, true) if inspectErr == nil { _ = windows.CloseHandle(fallback) - return nil, fmt.Errorf("%w: local CAS block security access is denied", transportcap.ErrCorruptedBlock) + return nil, fmt.Errorf("%w: local CAS block security access is denied", nodeapi.ErrCorruptedBlock) } if errors.Is(inspectErr, windows.ERROR_FILE_NOT_FOUND) || errors.Is(inspectErr, windows.ERROR_PATH_NOT_FOUND) { - return nil, fmt.Errorf("%w: local CAS block is absent", transportcap.ErrNotFound) + return nil, fmt.Errorf("%w: local CAS block is absent", nodeapi.ErrNotFound) } } return nil, fmt.Errorf("open local CAS block without following reparse points: %w", err) @@ -148,10 +148,10 @@ func (s *platformStore) readBlock(ctx context.Context, shard, name string, maxBy handle, information, err := openWindowsFile(path, windows.GENERIC_READ|windows.READ_CONTROL, windows.OPEN_EXISTING, true) if err != nil { if errors.Is(err, windows.ERROR_ACCESS_DENIED) { - return nil, fmt.Errorf("%w: local CAS block became unreadable", transportcap.ErrCorruptedBlock) + return nil, fmt.Errorf("%w: local CAS block became unreadable", nodeapi.ErrCorruptedBlock) } if errors.Is(err, windows.ERROR_FILE_NOT_FOUND) || errors.Is(err, windows.ERROR_PATH_NOT_FOUND) { - return nil, fmt.Errorf("%w: local CAS block is absent", transportcap.ErrNotFound) + return nil, fmt.Errorf("%w: local CAS block is absent", nodeapi.ErrNotFound) } return nil, fmt.Errorf("open local CAS block data handle: %w", err) } @@ -169,14 +169,14 @@ func (s *platformStore) readBlock(ctx context.Context, shard, name string, maxBy } size := int64(uint64(information.FileSizeHigh)<<32 | uint64(information.FileSizeLow)) if size < 0 || size > maxBytes { - return nil, fmt.Errorf("%w: local CAS block exceeds %d bytes", transportcap.ErrCorruptedBlock, maxBytes) + return nil, fmt.Errorf("%w: local CAS block exceeds %d bytes", nodeapi.ErrCorruptedBlock, maxBytes) } data, err := io.ReadAll(io.LimitReader(file, maxBytes+1)) if err != nil { return nil, fmt.Errorf("read local CAS block: %w", err) } if int64(len(data)) > maxBytes { - return nil, fmt.Errorf("%w: local CAS block exceeds %d bytes", transportcap.ErrCorruptedBlock, maxBytes) + return nil, fmt.Errorf("%w: local CAS block exceeds %d bytes", nodeapi.ErrCorruptedBlock, maxBytes) } if err := ctx.Err(); err != nil { return nil, err @@ -254,17 +254,17 @@ func (s *platformStore) closeHandle(file *os.File) error { func validateWindowsBlockHandle(handle windows.Handle, information windows.ByHandleFileInformation) error { if information.FileAttributes&(windows.FILE_ATTRIBUTE_REPARSE_POINT|windows.FILE_ATTRIBUTE_DIRECTORY) != 0 || information.NumberOfLinks > 1 { - return fmt.Errorf("%w: local CAS block must be a regular file without additional hard links", transportcap.ErrCorruptedBlock) + return fmt.Errorf("%w: local CAS block must be a regular file without additional hard links", nodeapi.ErrCorruptedBlock) } private, err := securefile.IsSecureHandle(handle) if err != nil { if errors.Is(err, windows.ERROR_ACCESS_DENIED) { - return fmt.Errorf("%w: local CAS block security cannot be verified", transportcap.ErrCorruptedBlock) + return fmt.Errorf("%w: local CAS block security cannot be verified", nodeapi.ErrCorruptedBlock) } return fmt.Errorf("inspect local CAS block security: %w", err) } if !private { - return fmt.Errorf("%w: local CAS block is not owner-private", transportcap.ErrCorruptedBlock) + return fmt.Errorf("%w: local CAS block is not owner-private", nodeapi.ErrCorruptedBlock) } return nil } @@ -279,10 +279,10 @@ func (s *platformStore) openShard(shard string, create bool) (*os.File, string, directory, err := s.openShardDirectory(path) if err != nil { if !create && (errors.Is(err, windows.ERROR_FILE_NOT_FOUND) || errors.Is(err, windows.ERROR_PATH_NOT_FOUND)) { - return nil, "", fmt.Errorf("%w: local CAS shard is absent", transportcap.ErrNotFound) + return nil, "", fmt.Errorf("%w: local CAS shard is absent", nodeapi.ErrNotFound) } if errors.Is(err, windows.ERROR_ACCESS_DENIED) || errors.Is(err, errUnsafeWindowsDirectory) { - return nil, "", fmt.Errorf("%w: local CAS shard path is unsafe: %v", transportcap.ErrCorruptedBlock, err) + return nil, "", fmt.Errorf("%w: local CAS shard path is unsafe: %v", nodeapi.ErrCorruptedBlock, err) } return nil, "", fmt.Errorf("open local CAS shard without following reparse points: %w", err) } @@ -294,7 +294,7 @@ func (s *platformStore) openShard(shard string, create bool) (*os.File, string, } if !owned { _ = directory.Close() - return nil, "", fmt.Errorf("%w: local CAS shard is not owned by the current user", transportcap.ErrCorruptedBlock) + return nil, "", fmt.Errorf("%w: local CAS shard is not owned by the current user", nodeapi.ErrCorruptedBlock) } if create { if err := protectDirectory(path); err != nil { @@ -309,7 +309,7 @@ func (s *platformStore) openShard(shard string, create bool) (*os.File, string, } if !private { _ = directory.Close() - return nil, "", fmt.Errorf("%w: local CAS shard is not owner-private", transportcap.ErrCorruptedBlock) + return nil, "", fmt.Errorf("%w: local CAS shard is not owner-private", nodeapi.ErrCorruptedBlock) } } return directory, path, nil diff --git a/transport/local/platform_windows_test.go b/transport/local/platform_windows_test.go index 7b62363..500c590 100644 --- a/transport/local/platform_windows_test.go +++ b/transport/local/platform_windows_test.go @@ -9,7 +9,7 @@ import ( "testing" clientcas "github.com/dewebprotocol/malt-client/internal/cas" - "github.com/dewebprotocol/malt-client/transport/capability" + "github.com/dewebprotocol/malt-client/nodeapi" "golang.org/x/sys/windows" ) @@ -58,7 +58,7 @@ func TestCASRepairsDenyReadBlockDACL(t *testing.T) { ); err != nil { t.Fatal(err) } - if _, err := store.Get(t.Context(), key); !errors.Is(err, capability.ErrCorruptedBlock) { + if _, err := store.Get(t.Context(), key); !errors.Is(err, nodeapi.ErrCorruptedBlock) { t.Fatalf("Get deny-read block error = %v, want ErrCorruptedBlock", err) } if _, err := store.Put(t.Context(), body); err != nil { @@ -89,7 +89,7 @@ func TestCASCloseRetriesOnlyUnconfirmedWindowsComponents(t *testing.T) { if store.platform == nil || platform.blocks != nil || platform.root != nil { t.Fatalf("failed Close retained an invalid terminally closed component") } - key, err := clientcas.CIDForBlock(capability.Block{Data: []byte("closed")}) + key, err := clientcas.CIDForBlock(nodeapi.Block{Data: []byte("closed")}) if err != nil { t.Fatal(err) } @@ -125,7 +125,7 @@ func TestCASPreservesOperationalShardOpenErrors(t *testing.T) { if !errors.Is(err, windows.ERROR_SHARING_VIOLATION) { t.Fatalf("Get operational shard error = %v, want sharing violation", err) } - if errors.Is(err, capability.ErrCorruptedBlock) { + if errors.Is(err, nodeapi.ErrCorruptedBlock) { t.Fatalf("Get operational shard error = %v, must not be corruption", err) } } diff --git a/transport/ports.go b/transport/ports.go index 435a9cb..ad76934 100644 --- a/transport/ports.go +++ b/transport/ports.go @@ -3,7 +3,7 @@ package transport import ( "context" - transportcap "github.com/dewebprotocol/malt-client/transport/capability" + "github.com/dewebprotocol/malt-client/nodeapi" ) // Diagnostics exposes operator measurements only. It is never part of a @@ -22,11 +22,11 @@ type MerkleDAGProfile interface { } var ( - _ transportcap.Authentication = (*Client)(nil) - _ transportcap.AuthenticationWriter = (*Client)(nil) - _ transportcap.AuthenticationBatch = (*Client)(nil) - _ transportcap.CAS = (*Client)(nil) - _ transportcap.BatchCAS = (*Client)(nil) - _ Diagnostics = (*Client)(nil) - _ MerkleDAGProfile = (*Client)(nil) + _ nodeapi.Authentication = (*Client)(nil) + _ nodeapi.AuthenticationWriter = (*Client)(nil) + _ nodeapi.AuthenticationBatch = (*Client)(nil) + _ nodeapi.CAS = (*Client)(nil) + _ nodeapi.BatchCAS = (*Client)(nil) + _ Diagnostics = (*Client)(nil) + _ MerkleDAGProfile = (*Client)(nil) ) diff --git a/unixfs/authentication_adapter.go b/unixfs/authentication_adapter.go index 4fb4625..e0670a2 100644 --- a/unixfs/authentication_adapter.go +++ b/unixfs/authentication_adapter.go @@ -6,7 +6,7 @@ import ( "sort" "strings" - transportcap "github.com/dewebprotocol/malt-client/transport/capability" + "github.com/dewebprotocol/malt-client/nodeapi" "github.com/dewebprotocol/malt-core/auth/commitment/ipa" "github.com/dewebprotocol/malt-core/auth/commitment/kzg" "github.com/dewebprotocol/malt-core/auth/coordinate" @@ -23,13 +23,13 @@ import ( // block sequences carry measured structural metadata and no system payload. // It computes candidates locally and checks the exact remote receipt. type AuthenticationAdapter struct { - remote transportcap.AuthenticationWriter + remote nodeapi.AuthenticationWriter engine *engine.Engine profile maltcid.ProfileID layout LayoutKind } -func NewAuthenticationAdapter(layout LayoutKind, remote transportcap.AuthenticationWriter, e *engine.Engine, profile maltcid.ProfileID) (*AuthenticationAdapter, error) { +func NewAuthenticationAdapter(layout LayoutKind, remote nodeapi.AuthenticationWriter, e *engine.Engine, profile maltcid.ProfileID) (*AuthenticationAdapter, error) { if _, err := NewLayout(layout); err != nil { return nil, err } diff --git a/unixfs/verified_facade.go b/unixfs/verified_facade.go index 86f2d91..82460bc 100644 --- a/unixfs/verified_facade.go +++ b/unixfs/verified_facade.go @@ -12,7 +12,7 @@ import ( "slices" "strings" - transportcap "github.com/dewebprotocol/malt-client/transport/capability" + "github.com/dewebprotocol/malt-client/nodeapi" unixfsmodel "github.com/dewebprotocol/malt-client/unixfs/model" "github.com/dewebprotocol/malt-core/engine" "github.com/dewebprotocol/malt-core/maltcid" @@ -151,7 +151,7 @@ type WriterOptions struct { type verifiedReader struct { layoutKind LayoutKind - authentication transportcap.Authentication + authentication nodeapi.Authentication authenticationVerifier *engine.Engine blocks BlockGetter stagedResolutions map[stagedProjectionCacheKey]*Resolution @@ -244,7 +244,7 @@ func NewWriter(opts WriterOptions) (Writer, error) { kind = opts.Layout.Kind() } if opts.Roots == nil || opts.Payloads == nil { - remote, ok := opts.Remote.(transportcap.AuthenticationWriter) + remote, ok := opts.Remote.(nodeapi.AuthenticationWriter) if !ok { return nil, fmt.Errorf("typed authentication writer capability is required") }