Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unified wireprotocol #348

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 0 additions & 132 deletions src/blockstore/fp-envelope.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/blockstore/gateway.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Result, URI } from "@adviser/cement";
import { NotFoundError } from "../utils.js";
import { FPEnvelope, FPEnvelopeMeta } from "./fp-envelope.js";
import { FPEnvelope, FPEnvelopeMeta } from "../protocols/fp-envelope.js";
import { Loadable } from "./types.js";

export interface GatewayOpts {
Expand Down
2 changes: 1 addition & 1 deletion src/blockstore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export * from "./types.js";
export * from "./store-factory.js";
export * from "./gateway.js";

export * from "./fp-envelope.js";
export * from "../protocols/fp-envelope.js";

export * from "./register-store-protocol.js";
export * from "./interceptor-gateway.js";
Expand Down
2 changes: 1 addition & 1 deletion src/blockstore/interceptor-gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from "./gateway.js";
import { SuperThis } from "../types.js";
import { ensureSuperLog } from "../utils.js";
import { FPEnvelope, FPEnvelopeMeta } from "./fp-envelope.js";
import { FPEnvelope, FPEnvelopeMeta } from "../protocols/fp-envelope.js";
import { Loadable } from "./types.js";

export class PassThroughGateway implements GatewayInterceptor {
Expand Down
2 changes: 1 addition & 1 deletion src/blockstore/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { ensureLogger, inplaceFilter, isNotFoundError } from "../utils.js";
import { carLogIncludesGroup } from "./loader.js";
import { CommitQueue } from "./commit-queue.js";
import { keyedCryptoFactory } from "../runtime/keyed-crypto.js";
import { Car2FPMsg, File2FPMsg, FPEnvelopeCar, FPEnvelopeFile, FPEnvelopeMeta, FPEnvelopeWAL } from "./fp-envelope.js";
import { Car2FPMsg, File2FPMsg, FPEnvelopeCar, FPEnvelopeFile, FPEnvelopeMeta, FPEnvelopeWAL } from "../protocols/fp-envelope.js";
import { EventView } from "@web3-storage/pail/clock/api";
import { EventBlock } from "@web3-storage/pail/clock";
import { format } from "@ipld/dag-json";
Expand Down
137 changes: 137 additions & 0 deletions src/protocols/fp-car.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// import { Result } from "@adviser/cement";
import { FPEnvelopeTurnaround, FPEnvelopeType, FPStoreType } from "./fp-envelope";
import { CID } from "multiformats";

export interface FPGetCarReq {
readonly cid: CID;
}
/*
* A request to get a CAR file.
* As JSON, this is:
* {
* "type": "get-car-req",
* "tid": "123",
* "payload": {
* "cid": "bafybeib2v"
* }
* "auth": { ... }
* "meta": { ... }
* }
*/
export interface FPEnvelopeGetCarReq extends FPCarReq<FPGetCarReq> {
readonly type: FPEnvelopeType.GET_CARREQ;
readonly storeType: FPStoreType.CAR;
}

export interface FPGetCarRes {
readonly cid: CID;
readonly bytes: Uint8Array;
}
/*
* The response to a GetCar request.
* As JSON, this is:
* {
* "type": "get-car-res",
* "tid": "123",
* "payload": {
* "cid": "bafybeib2v"
* "bytes": [0x65, 0x66, 0x67, ...],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just send the car raw as binary? the CAR get and PUT dont need to be parsed by the server

* }
* "auth": { ... }
* "meta": { ... }
* }
*/
export interface FPEnvelopeGetCarRes extends FPCarRes<FPGetCarRes> {
readonly type: FPEnvelopeType.GET_CARRES;
readonly storeType: FPStoreType.CAR;
}

export interface FPPutCarReq {
readonly cid: CID;
readonly bytes: Uint8Array;
}
/*
* A request to get a CAR file.
* As JSON, this is:
* {
* "type": "put-car-req",
* "tid": "123",
* "payload": {
* "cid": "bafybeib2v"
* "bytes": [0x65, 0x66, 0x67, ...],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the put request to the signed upload URL generator doesnt include the bytes, the bytes are sent raw on the s3 protocol on a subsequent request

* }
* "auth": { ... }
* "meta": { ... }
* }
*/
export interface FPEnvelopePutCarReq extends FPCarReq<FPPutCarReq> {
readonly type: FPEnvelopeType.PUT_CARREQ;
readonly storeType: FPStoreType.CAR;
}

export interface FPDelCarReq {
readonly cid: CID;
}
/*
* The response to a PutCar request.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the signed upload url can be returned as a redirect, but today we put it in a json envelope, either is ok, but the result here should just be a URL in the s3 protocol

* As JSON, this is:
* {
* "type": "del-car-res",
* "tid": "123",
* "payload": {
* "cid": "bafybeib2v"
* "meta": {
* "key1": "value1",
* }
* }
* "auth": { ... }
* "meta": { ... }
* }
*/
export interface FPEnvelopeDelCarReq extends FPCarReq<FPDelCarReq> {
readonly type: FPEnvelopeType.DEL_CARREQ;
readonly storeType: FPStoreType.CAR;
}


export interface FPDelCarRes {
readonly cid: CID;
// optional deleted bytes
readonly bytes?: Uint8Array;
}
/*
* A request to get a CAR file.
* As JSON, this is:
* {
* "type": "get-car-req",
* "tid": "123",
* "payload": {
* "cid": "bafybeib2v"
* "bytes": [0x65, 0x66, 0x67, ...],
* }
* "auth": { ... }
* "meta": { ... }
* }
*/
export interface FPEnvelopeDelCarRes extends FPCarRes<FPDelCarRes> {
readonly type: FPEnvelopeType.DEL_CARRES;
readonly storeType: FPStoreType.CAR;
}

export interface FPCarReq<T> extends FPEnvelopeTurnaround<T> {
readonly type: FPEnvelopeType.DEL_CARREQ | FPEnvelopeType.GET_CARREQ | FPEnvelopeType.PUT_CARREQ;
readonly storeType: FPStoreType.CAR;
}

export interface FPCarRes<T> extends FPEnvelopeTurnaround<T> {
readonly type: FPEnvelopeType.DEL_CARRES | FPEnvelopeType.GET_CARRES | FPEnvelopeType.PUT_CARRES;
readonly storeType: FPStoreType.CAR;
}

// export interface FPEnvelopeCar extends FPEnvelope<Uint8Array> {
// readonly type: FPEnvelopeType.CAR;
// }

// export function Car2FPMsg(fpcar: Uint8Array): Result<FPEnvelopeCar> {
// return Result.Ok({ type: FPEnvelopeType.CAR, payload: fpcar });
// }
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@ import {
DbMetaBinary,
DbMetaEvent,
FPEnvelope,
FPEnvelopeCar,
FPEnvelopeFile,
FPEnvelopeMeta,
FPEnvelopeReq,
FPEnvelopeType,
FPEnvelopeWAL,
FPStoreType,
WALState,
} from "../../blockstore";
import { PARAM, PromiseToUInt8, SuperThis } from "../../types";
} from "../blockstore";
import { PARAM, PromiseToUInt8, SuperThis } from "../types";
import { decodeEventBlock, EventBlock } from "@web3-storage/pail/clock";
import { base64pad } from "multiformats/bases/base64";
import { CID, Link } from "multiformats";
import { fromJSON } from "multiformats/link";
import { format, parse } from "@ipld/dag-json";
import { EventView } from "@web3-storage/pail/src/clock/api";
import { coercePromiseIntoUint8 } from "../../utils";
import { coercePromiseIntoUint8 } from "../utils";

export interface SerializedMeta {
readonly data: string; // base64pad encoded
Expand Down Expand Up @@ -86,21 +84,21 @@ const defaultEncoder: Encoder = {

export async function fpSerialize<T>(
sthis: SuperThis,
env: FPEnvelope<T>,
env: FPEnvelopeReq<T>,
pencoder?: Partial<Encoder>,
): Promise<Result<Uint8Array>> {
const encoder = {
...defaultEncoder,
...pencoder,
};
switch (env.type) {
case FPEnvelopeType.FILE:
switch (env.storeType) {
case FPStoreType.FILE:
return encoder.file(sthis, (env as FPEnvelopeFile).payload);
case FPEnvelopeType.CAR:
case FPStoreType.CAR:
return encoder.car(sthis, (env as FPEnvelopeCar).payload);
case FPEnvelopeType.WAL:
case FPStoreType.WAL:
return encoder.wal(sthis, WALState2Serialized(sthis, (env as FPEnvelopeWAL).payload));
case FPEnvelopeType.META:
case FPStoreType.META:
return encoder.meta(sthis, await dbMetaEvent2Serialized(sthis, (env as FPEnvelopeMeta).payload));
default:
throw sthis.logger.Error().Str("type", env.type).Msg("unsupported store").AsError();
Expand Down
Loading
Loading