@peerbit/blocks 1.1.6 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/{level.d.ts → any-blockstore.d.ts} +7 -11
- package/lib/esm/{level.js → any-blockstore.js} +21 -30
- package/lib/esm/any-blockstore.js.map +1 -0
- package/lib/esm/block.d.ts +2 -2
- package/lib/esm/block.js.map +1 -1
- package/lib/esm/index.d.ts +3 -2
- package/lib/esm/index.js +3 -2
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/{store.d.ts → interface.d.ts} +2 -1
- package/lib/esm/interface.js +2 -0
- package/lib/esm/interface.js.map +1 -0
- package/lib/esm/libp2p.d.ts +5 -20
- package/lib/esm/libp2p.js +38 -177
- package/lib/esm/libp2p.js.map +1 -1
- package/lib/esm/remote.d.ts +59 -0
- package/lib/esm/remote.js +245 -0
- package/lib/esm/remote.js.map +1 -0
- package/package.json +8 -10
- package/src/{level.ts → any-blockstore.ts} +25 -37
- package/src/block.ts +1 -1
- package/src/index.ts +3 -2
- package/src/{store.ts → interface.ts} +4 -1
- package/src/libp2p.ts +45 -195
- package/src/remote.ts +298 -0
- package/lib/esm/level.js.map +0 -1
- package/lib/esm/store.js +0 -2
- package/lib/esm/store.js.map +0 -1
- package/lib/esm/streams.d.ts +0 -1
- package/lib/esm/streams.js +0 -2
- package/lib/esm/streams.js.map +0 -1
- package/src/streams.ts +0 -1
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { Blocks } from "@peerbit/blocks-interface";
|
|
2
|
-
import { AbstractLevel } from "abstract-level";
|
|
3
|
-
import { LazyLevelOptions } from "@peerbit/lazy-level";
|
|
4
2
|
import { PeerId } from "@libp2p/interface/peer-id";
|
|
5
3
|
import { PublicSignKey } from "@peerbit/crypto";
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
import { AnyStore } from "@peerbit/any-store";
|
|
5
|
+
export declare class AnyBlockStore implements Blocks {
|
|
6
|
+
private _store;
|
|
8
7
|
private _opening;
|
|
9
|
-
private _closed;
|
|
10
8
|
private _onClose;
|
|
11
|
-
|
|
9
|
+
private _closeController;
|
|
10
|
+
constructor(store?: AnyStore);
|
|
12
11
|
get(cid: string, options?: {
|
|
13
12
|
raw?: boolean;
|
|
14
13
|
links?: string[];
|
|
@@ -21,10 +20,7 @@ export declare class LevelBlockStore implements Blocks {
|
|
|
21
20
|
has(cid: string): Promise<boolean>;
|
|
22
21
|
start(): Promise<void>;
|
|
23
22
|
stop(): Promise<void>;
|
|
24
|
-
|
|
25
|
-
status(): "open" | "opening" | "closed" | "closing";
|
|
23
|
+
status(): import("@peerbit/any-store").MaybePromise<"opening" | "open" | "closing" | "closed">;
|
|
26
24
|
waitFor(peer: PeerId | PublicSignKey): Promise<void>;
|
|
27
|
-
|
|
28
|
-
export declare class MemoryLevelBlockStore extends LevelBlockStore {
|
|
29
|
-
constructor(options?: LazyLevelOptions);
|
|
25
|
+
size(): Promise<number>;
|
|
30
26
|
}
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import { cidifyString, codecCodes, createBlock, defaultHasher, stringifyCid } from "./block.js";
|
|
2
2
|
import * as Block from "multiformats/block";
|
|
3
|
-
import { MemoryLevel } from "memory-level";
|
|
4
3
|
import { waitFor } from "@peerbit/time";
|
|
5
|
-
import
|
|
6
|
-
export class
|
|
7
|
-
|
|
4
|
+
import { createStore } from "@peerbit/any-store";
|
|
5
|
+
export class AnyBlockStore {
|
|
6
|
+
_store;
|
|
8
7
|
_opening;
|
|
9
|
-
_closed = false;
|
|
10
8
|
_onClose;
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
_closeController;
|
|
10
|
+
constructor(store = createStore()) {
|
|
11
|
+
this._store = store;
|
|
13
12
|
}
|
|
14
13
|
async get(cid, options) {
|
|
15
14
|
const cidObject = cidifyString(cid);
|
|
16
15
|
try {
|
|
17
|
-
const bytes = await this.
|
|
16
|
+
const bytes = await this._store.get(cid);
|
|
18
17
|
if (!bytes) {
|
|
19
18
|
return undefined;
|
|
20
19
|
}
|
|
@@ -38,30 +37,28 @@ export class LevelBlockStore {
|
|
|
38
37
|
const block = await createBlock(bytes, "raw");
|
|
39
38
|
const cid = stringifyCid(block.cid);
|
|
40
39
|
const bbytes = block.bytes;
|
|
41
|
-
await this.
|
|
40
|
+
await this._store.put(cid, bbytes);
|
|
42
41
|
return cid;
|
|
43
42
|
}
|
|
44
43
|
async rm(cid) {
|
|
45
|
-
await this.
|
|
44
|
+
await this._store.del(cid);
|
|
46
45
|
}
|
|
47
46
|
async *iterator() {
|
|
48
|
-
for await (const [key, value] of this.
|
|
47
|
+
for await (const [key, value] of this._store.iterator()) {
|
|
49
48
|
yield [key, value];
|
|
50
49
|
}
|
|
51
50
|
}
|
|
52
51
|
async has(cid) {
|
|
53
|
-
return !!(await this.
|
|
52
|
+
return !!(await this._store.get(cid));
|
|
54
53
|
}
|
|
55
54
|
async start() {
|
|
56
|
-
this.
|
|
57
|
-
|
|
55
|
+
await this._store.open();
|
|
56
|
+
this._closeController = new AbortController();
|
|
58
57
|
try {
|
|
59
|
-
this._opening = waitFor(() => this.
|
|
58
|
+
this._opening = waitFor(async () => (await this._store.status()) === "open", {
|
|
60
59
|
delayInterval: 100,
|
|
61
60
|
timeout: 10 * 1000,
|
|
62
|
-
|
|
63
|
-
this._onClose = fn;
|
|
64
|
-
}
|
|
61
|
+
signal: this._closeController.signal
|
|
65
62
|
});
|
|
66
63
|
await this._opening;
|
|
67
64
|
}
|
|
@@ -70,24 +67,18 @@ export class LevelBlockStore {
|
|
|
70
67
|
}
|
|
71
68
|
}
|
|
72
69
|
async stop() {
|
|
73
|
-
await this.idle();
|
|
74
|
-
this._closed = true;
|
|
75
70
|
this._onClose && this._onClose();
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
async idle() {
|
|
79
|
-
await this._level.idle();
|
|
71
|
+
this._closeController.abort();
|
|
72
|
+
return this._store.close();
|
|
80
73
|
}
|
|
81
74
|
status() {
|
|
82
|
-
return this.
|
|
75
|
+
return this._store.status();
|
|
83
76
|
}
|
|
84
77
|
async waitFor(peer) {
|
|
85
78
|
return; // Offline storage // TODO this feels off resolving
|
|
86
79
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
constructor(options) {
|
|
90
|
-
super(new MemoryLevel({ valueEncoding: "view" }), options);
|
|
80
|
+
async size() {
|
|
81
|
+
return this._store.size();
|
|
91
82
|
}
|
|
92
83
|
}
|
|
93
|
-
//# sourceMappingURL=
|
|
84
|
+
//# sourceMappingURL=any-blockstore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"any-blockstore.js","sourceRoot":"","sources":["../../src/any-blockstore.ts"],"names":[],"mappings":"AACA,OAAO,EACN,YAAY,EACZ,UAAU,EACV,WAAW,EACX,aAAa,EACb,YAAY,EACZ,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,KAAK,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAGxC,OAAO,EAAY,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAE3D,MAAM,OAAO,aAAa;IACjB,MAAM,CAAW;IACjB,QAAQ,CAAe;IACvB,QAAQ,CAA0B;IAClC,gBAAgB,CAAkB;IAC1C,YAAY,QAAkB,WAAW,EAAE;QAC1C,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,GAAG,CACR,GAAW,EACX,OAKC;QAED,MAAM,SAAS,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;QACpC,IAAI,CAAC;YACJ,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACzC,IAAI,CAAC,KAAK,EAAE,CAAC;gBACZ,OAAO,SAAS,CAAC;YAClB,CAAC;YACD,MAAM,KAAK,GAAG,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YACzC,MAAM,KA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ACvC,CAAC;IAED,KAAK,CAAC,KAAK;QACV,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QACzB,IAAI,CAAC,gBAAgB,GAAG,IAAI,eAAe,EAAE,CAAC;QAE9C,IAAI,CAAC;YACJ,IAAI,CAAC,QAAQ,GAAG,OAAO,CACtB,KAAK,IAAI,EAAE,CAAC,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,MAAM,EACnD;gBACC,aAAa,EAAE,GAAG;gBAClB,OAAO,EAAE,EAAE,GAAG,IAAI;gBAClB,MAAM,EAAE,IAAI,CAAC,gBAAgB,CAAC,MAAM;aACpC,CACD,CAAC;YACF,MAAM,IAAI,CAAC,QAAQ,CAAC;QACrB,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC;QAC3B,CAAC;IACF,CAAC;IAED,KAAK,CAAC,IAAI;QACT,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QACjC,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;QAC9B,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;IAED,MAAM;QACL,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;IAC7B,CAAC;IACD,KAAK,CAAC,OAAO,CAAC,IAA4B;QACzC,OAAO,CAAC,mDAAmD;IAC5D,CAAC;IAED,KAAK,CAAC,IAAI;QACT,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAC3B,CAAC;CACD"}
|
package/lib/esm/block.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { CID } from "multiformats/cid";
|
|
|
2
2
|
import * as raw from "multiformats/codecs/raw";
|
|
3
3
|
import * as dagCbor from "@ipld/dag-cbor";
|
|
4
4
|
import * as Block from "multiformats/block";
|
|
5
|
-
import type { MultihashHasher } from "multiformats/hashes/
|
|
6
|
-
export declare const defaultHasher: import("multiformats/hashes/hasher").Hasher<"sha2-256", 18>;
|
|
5
|
+
import type { MultihashHasher } from "multiformats/hashes/interface";
|
|
6
|
+
export declare const defaultHasher: import("multiformats/dist/src/hashes/hasher").Hasher<"sha2-256", 18>;
|
|
7
7
|
export declare const codecCodes: {
|
|
8
8
|
113: typeof dagCbor;
|
|
9
9
|
85: typeof raw;
|
package/lib/esm/block.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block.js","sourceRoot":"","sources":["../../src/block.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,GAAG,MAAM,yBAAyB,CAAC;AAC/C,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,KAAK,KAAK,MAAM,oBAAoB,CAAC;AAG5C,MAAM,qBAAqB,GAAG,GAAG,EAAE,CAAC,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;AAEnE,MAAM,WAAW,GAAG,SAAS,CAAC;AAE9B,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC;AAEpC,MAAM,CAAC,MAAM,UAAU,GAAG;IACzB,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO;IACvB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG;CACf,CAAC;AACF,MAAM,CAAC,MAAM,QAAQ,GAAG;IACvB,GAAG,EAAE,GAAG;IACR,UAAU,EAAE,OAAO;CACnB,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,GAAW,EAAO,EAAE;IAChD,IAAI,CAAC,GAAG,EAAE;
|
|
1
|
+
{"version":3,"file":"block.js","sourceRoot":"","sources":["../../src/block.ts"],"names":[],"mappings":"AAAA,OA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AAM,KAAK,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC;QAChC,KAAK;QACL,KAAK;QACL,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,aAAa;KACxC,CAAC,CAAC;IACH,OAAO,KAAwC,CAAC;AACjD,CAAC,CAAC"}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { cidifyString, stringifyCid, createBlock, getBlockValue } from "./block.js";
|
|
2
2
|
export { DirectBlock } from "./libp2p.js";
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
3
|
+
export * from "./interface.js";
|
|
4
|
+
export * from "./any-blockstore.js";
|
|
5
5
|
export * from "./libp2p.js";
|
|
6
|
+
export * from "./remote.js";
|
package/lib/esm/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { cidifyString, stringifyCid, createBlock, getBlockValue } from "./block.js";
|
|
2
2
|
export { DirectBlock } from "./libp2p.js";
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
3
|
+
export * from "./interface.js";
|
|
4
|
+
export * from "./any-blockstore.js";
|
|
5
5
|
export * from "./libp2p.js";
|
|
6
|
+
export * from "./remote.js";
|
|
6
7
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,aAAa,EACb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,aAAa,EACb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { MaybePromise } from "@peerbit/any-store";
|
|
1
2
|
import { Blocks as IBlockStore } from "@peerbit/blocks-interface";
|
|
2
|
-
export type StoreStatus = "open" | "opening" | "closed" | "closing"
|
|
3
|
+
export type StoreStatus = MaybePromise<"open" | "opening" | "closed" | "closing">;
|
|
3
4
|
export interface BlockStore extends IBlockStore {
|
|
4
5
|
start(): Promise<void>;
|
|
5
6
|
stop(): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.js","sourceRoot":"","sources":["../../src/interface.ts"],"names":[],"mappings":""}
|
package/lib/esm/libp2p.d.ts
CHANGED
|
@@ -2,25 +2,11 @@ import { Blocks as IBlocks } from "@peerbit/blocks-interface";
|
|
|
2
2
|
import { DirectStream } from "@peerbit/stream";
|
|
3
3
|
import { DirectStreamComponents } from "@peerbit/stream";
|
|
4
4
|
import { GetOptions } from "@peerbit/blocks-interface";
|
|
5
|
-
export declare class BlockMessage {
|
|
6
|
-
}
|
|
7
|
-
export declare class BlockRequest extends BlockMessage {
|
|
8
|
-
cid: string;
|
|
9
|
-
constructor(cid: string);
|
|
10
|
-
}
|
|
11
|
-
export declare class BlockResponse extends BlockMessage {
|
|
12
|
-
cid: string;
|
|
13
|
-
bytes: Uint8Array;
|
|
14
|
-
constructor(cid: string, bytes: Uint8Array);
|
|
15
|
-
}
|
|
16
5
|
export type DirectBlockComponents = DirectStreamComponents;
|
|
17
6
|
export declare class DirectBlock extends DirectStream implements IBlocks {
|
|
18
|
-
private
|
|
19
|
-
private
|
|
20
|
-
private
|
|
21
|
-
private _loadFetchQueue;
|
|
22
|
-
private _readFromPeersPromises;
|
|
23
|
-
_open: boolean;
|
|
7
|
+
private remoteBlocks;
|
|
8
|
+
private onDataFn;
|
|
9
|
+
private onPeerConnectedFn;
|
|
24
10
|
constructor(components: DirectBlockComponents, options?: {
|
|
25
11
|
directory?: string;
|
|
26
12
|
canRelayMessage?: boolean;
|
|
@@ -33,8 +19,7 @@ export declare class DirectBlock extends DirectStream implements IBlocks {
|
|
|
33
19
|
rm(cid: string): Promise<void>;
|
|
34
20
|
iterator(): AsyncGenerator<[string, Uint8Array], void, void>;
|
|
35
21
|
start(): Promise<void>;
|
|
36
|
-
private handleFetchRequest;
|
|
37
|
-
private _readFromPeers;
|
|
38
22
|
stop(): Promise<void>;
|
|
39
|
-
|
|
23
|
+
size(): Promise<number>;
|
|
24
|
+
get status(): import("./interface.js").StoreStatus;
|
|
40
25
|
}
|
package/lib/esm/libp2p.js
CHANGED
|
@@ -1,208 +1,69 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { stringifyCid, cidifyString, codecCodes, checkDecodeBlock } from "./block.js";
|
|
11
|
-
import { variant, field, serialize, deserialize } from "@dao-xyz/borsh";
|
|
12
1
|
import { DirectStream } from "@peerbit/stream";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
let BlockRequest = class BlockRequest extends BlockMessage {
|
|
19
|
-
cid;
|
|
20
|
-
constructor(cid) {
|
|
21
|
-
super();
|
|
22
|
-
this.cid = cid;
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
__decorate([
|
|
26
|
-
field({ type: "string" }),
|
|
27
|
-
__metadata("design:type", String)
|
|
28
|
-
], BlockRequest.prototype, "cid", void 0);
|
|
29
|
-
BlockRequest = __decorate([
|
|
30
|
-
variant(0),
|
|
31
|
-
__metadata("design:paramtypes", [String])
|
|
32
|
-
], BlockRequest);
|
|
33
|
-
export { BlockRequest };
|
|
34
|
-
let BlockResponse = class BlockResponse extends BlockMessage {
|
|
35
|
-
cid;
|
|
36
|
-
bytes;
|
|
37
|
-
constructor(cid, bytes) {
|
|
38
|
-
super();
|
|
39
|
-
this.cid = cid;
|
|
40
|
-
this.bytes = bytes;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
__decorate([
|
|
44
|
-
field({ type: "string" }),
|
|
45
|
-
__metadata("design:type", String)
|
|
46
|
-
], BlockResponse.prototype, "cid", void 0);
|
|
47
|
-
__decorate([
|
|
48
|
-
field({ type: Uint8Array }),
|
|
49
|
-
__metadata("design:type", Uint8Array)
|
|
50
|
-
], BlockResponse.prototype, "bytes", void 0);
|
|
51
|
-
BlockResponse = __decorate([
|
|
52
|
-
variant(1),
|
|
53
|
-
__metadata("design:paramtypes", [String, Uint8Array])
|
|
54
|
-
], BlockResponse);
|
|
55
|
-
export { BlockResponse };
|
|
2
|
+
import { AnyBlockStore } from "./any-blockstore.js";
|
|
3
|
+
import { createStore } from "@peerbit/any-store";
|
|
4
|
+
import { BlockMessage, RemoteBlocks } from "./remote.js";
|
|
5
|
+
import { deserialize, serialize } from "@dao-xyz/borsh";
|
|
56
6
|
export class DirectBlock extends DirectStream {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
_loadFetchQueue;
|
|
61
|
-
_readFromPeersPromises;
|
|
62
|
-
_open = false;
|
|
7
|
+
remoteBlocks;
|
|
8
|
+
onDataFn;
|
|
9
|
+
onPeerConnectedFn;
|
|
63
10
|
constructor(components, options) {
|
|
64
|
-
super(components, ["
|
|
65
|
-
emitSelf: false,
|
|
11
|
+
super(components, ["/lazyblock/0.0.0"], {
|
|
66
12
|
signaturePolicy: "StrictNoSign",
|
|
67
13
|
messageProcessingConcurrency: options?.messageProcessingConcurrency || 10,
|
|
68
|
-
canRelayMessage: options?.canRelayMessage ?? true
|
|
14
|
+
canRelayMessage: options?.canRelayMessage ?? true,
|
|
15
|
+
connectionManager: {
|
|
16
|
+
dialer: false,
|
|
17
|
+
pruner: false
|
|
18
|
+
}
|
|
69
19
|
});
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
20
|
+
this.remoteBlocks = new RemoteBlocks({
|
|
21
|
+
local: new AnyBlockStore(createStore(options?.directory)),
|
|
22
|
+
publish: (message) => this.publish(serialize(message)),
|
|
23
|
+
localTimeout: options?.localTimeout || 1000,
|
|
24
|
+
messageProcessingConcurrency: options?.messageProcessingConcurrency || 10,
|
|
25
|
+
waitFor: this.waitFor.bind(this)
|
|
73
26
|
});
|
|
74
|
-
this.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
: new MemoryLevelBlockStore();
|
|
78
|
-
this._resolvers = new Map();
|
|
79
|
-
this._readFromPeersPromises = new Map();
|
|
80
|
-
this._responseHandler = async (evt) => {
|
|
81
|
-
if (!evt) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
const message = evt.detail;
|
|
85
|
-
try {
|
|
86
|
-
const decoded = deserialize(message.data, BlockMessage);
|
|
87
|
-
if (decoded instanceof BlockRequest && this._localStore) {
|
|
88
|
-
this._loadFetchQueue.add(() => this.handleFetchRequest(decoded, localTimeout));
|
|
89
|
-
}
|
|
90
|
-
else if (decoded instanceof BlockResponse) {
|
|
91
|
-
// TODO make sure we are not storing too much bytes in ram (like filter large blocks)
|
|
92
|
-
this._resolvers.get(decoded.cid)?.(decoded.bytes);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
catch (error) {
|
|
96
|
-
console.error("Got error for libp2p block transport: ", error);
|
|
97
|
-
return; // timeout o r invalid cid
|
|
98
|
-
}
|
|
27
|
+
this.onDataFn = (data) => {
|
|
28
|
+
data.detail?.data &&
|
|
29
|
+
this.remoteBlocks.onMessage(deserialize(data.detail.data, BlockMessage));
|
|
99
30
|
};
|
|
31
|
+
this.onPeerConnectedFn = (evt) => this.remoteBlocks.onReachable(evt.detail);
|
|
100
32
|
}
|
|
101
33
|
async put(bytes) {
|
|
102
|
-
|
|
103
|
-
throw new Error("Local store not set");
|
|
104
|
-
}
|
|
105
|
-
return this._localStore.put(bytes);
|
|
34
|
+
return this.remoteBlocks.put(bytes);
|
|
106
35
|
}
|
|
107
36
|
async has(cid) {
|
|
108
|
-
return this.
|
|
37
|
+
return this.remoteBlocks.has(cid);
|
|
109
38
|
}
|
|
110
39
|
async get(cid, options) {
|
|
111
|
-
|
|
112
|
-
let value = this._localStore
|
|
113
|
-
? await this._localStore.get(cid, options)
|
|
114
|
-
: undefined;
|
|
115
|
-
if (!value) {
|
|
116
|
-
// try to get it remotelly
|
|
117
|
-
value = await this._readFromPeers(cid, cidObject, options);
|
|
118
|
-
if (options?.replicate && value) {
|
|
119
|
-
this._localStore.put(value);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return value;
|
|
40
|
+
return this.remoteBlocks.get(cid, options);
|
|
123
41
|
}
|
|
124
42
|
async rm(cid) {
|
|
125
|
-
|
|
43
|
+
return this.remoteBlocks.rm(cid);
|
|
126
44
|
}
|
|
127
45
|
async *iterator() {
|
|
128
|
-
for await (const [key, value] of this.
|
|
46
|
+
for await (const [key, value] of this.remoteBlocks.iterator()) {
|
|
129
47
|
yield [key, value];
|
|
130
48
|
}
|
|
131
49
|
}
|
|
132
50
|
async start() {
|
|
133
|
-
|
|
51
|
+
this.addEventListener("data", this.onDataFn);
|
|
52
|
+
this.addEventListener("peer:reachable", this.onPeerConnectedFn);
|
|
134
53
|
await super.start();
|
|
135
|
-
this.
|
|
136
|
-
this._open = true;
|
|
137
|
-
}
|
|
138
|
-
async handleFetchRequest(request, localTimeout) {
|
|
139
|
-
const cid = stringifyCid(request.cid);
|
|
140
|
-
const bytes = await this._localStore.get(cid, {
|
|
141
|
-
timeout: localTimeout
|
|
142
|
-
});
|
|
143
|
-
if (!bytes) {
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
const response = serialize(new BlockResponse(cid, bytes));
|
|
147
|
-
await this.publish(response);
|
|
148
|
-
}
|
|
149
|
-
async _readFromPeers(cidString, cidObject, options = {}) {
|
|
150
|
-
const codec = codecCodes[cidObject.code];
|
|
151
|
-
let promise = this._readFromPeersPromises.get(cidString);
|
|
152
|
-
if (!promise) {
|
|
153
|
-
promise = new Promise((resolve, reject) => {
|
|
154
|
-
const timeoutCallback = setTimeout(() => {
|
|
155
|
-
resolve(undefined);
|
|
156
|
-
}, options.timeout || 30 * 1000);
|
|
157
|
-
this._resolvers.set(cidString, async (bytes) => {
|
|
158
|
-
const value = await checkDecodeBlock(cidObject, bytes, {
|
|
159
|
-
codec,
|
|
160
|
-
hasher: options?.hasher
|
|
161
|
-
});
|
|
162
|
-
clearTimeout(timeoutCallback);
|
|
163
|
-
this._resolvers.delete(cidString); // TODO concurrency might not work as expected here
|
|
164
|
-
resolve(value);
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
this._readFromPeersPromises.set(cidString, promise);
|
|
168
|
-
const publish = (to) => this.publish(serialize(new BlockRequest(cidString)), { to: to });
|
|
169
|
-
const publishOnNewPeers = (e) => {
|
|
170
|
-
return publish([e.detail]);
|
|
171
|
-
};
|
|
172
|
-
this.addEventListener("peer:reachable", publishOnNewPeers);
|
|
173
|
-
await publish();
|
|
174
|
-
// we want to make sure that if some new peers join, we also try to ask them
|
|
175
|
-
const result = await promise;
|
|
176
|
-
this._readFromPeersPromises.delete(cidString);
|
|
177
|
-
// stop asking new peers, because we already got an response
|
|
178
|
-
this.removeEventListener("peer:reachable", publishOnNewPeers);
|
|
179
|
-
return result?.bytes;
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
const result = await promise;
|
|
183
|
-
return result?.bytes;
|
|
184
|
-
}
|
|
54
|
+
await this.remoteBlocks.start();
|
|
185
55
|
}
|
|
186
56
|
async stop() {
|
|
187
|
-
|
|
188
|
-
this.removeEventListener("
|
|
189
|
-
// Wait for processing request
|
|
190
|
-
this._loadFetchQueue.clear();
|
|
191
|
-
await this._loadFetchQueue.onIdle(); // wait for pending
|
|
57
|
+
this.removeEventListener("data", this.onDataFn);
|
|
58
|
+
this.removeEventListener("peer:reachable", this.onPeerConnectedFn);
|
|
192
59
|
await super.stop();
|
|
193
|
-
await this.
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
this.
|
|
197
|
-
// we dont cleanup subscription because we dont know if someone else is sbuscribing also
|
|
60
|
+
await this.remoteBlocks.stop();
|
|
61
|
+
}
|
|
62
|
+
async size() {
|
|
63
|
+
return this.remoteBlocks?.size() || 0;
|
|
198
64
|
}
|
|
199
65
|
get status() {
|
|
200
|
-
|
|
201
|
-
return this._localStore?.status() || this.started;
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
return "closed";
|
|
205
|
-
}
|
|
66
|
+
return this.remoteBlocks?.status || this.started;
|
|
206
67
|
}
|
|
207
68
|
}
|
|
208
69
|
//# sourceMappingURL=libp2p.js.map
|
package/lib/esm/libp2p.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"libp2p.js","sourceRoot":"","sources":["../../src/libp2p.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"libp2p.js","sourceRoot":"","sources":["../../src/libp2p.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,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EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;QACnE,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,MAAM,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,IAAI;QACT,OAAO,IAAI,CAAC,YAAY,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACvC,CAAC;IACD,IAAI,MAAM;QACT,OAAO,IAAI,CAAC,YAAY,EAAE,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC;IAClD,CAAC;CACD"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { BlockStore } from "./interface.js";
|
|
2
|
+
import { Blocks as IBlocks } from "@peerbit/blocks-interface";
|
|
3
|
+
import { PublicSignKey } from "@peerbit/crypto";
|
|
4
|
+
import { AnyBlockStore } from "./any-blockstore.js";
|
|
5
|
+
import { GetOptions } from "@peerbit/blocks-interface";
|
|
6
|
+
import type { PeerId } from "@libp2p/interface/peer-id";
|
|
7
|
+
export declare class BlockMessage {
|
|
8
|
+
}
|
|
9
|
+
export declare class BlockRequest extends BlockMessage {
|
|
10
|
+
cid: string;
|
|
11
|
+
constructor(cid: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class BlockResponse extends BlockMessage {
|
|
14
|
+
cid: string;
|
|
15
|
+
bytes: Uint8Array;
|
|
16
|
+
constructor(cid: string, bytes: Uint8Array);
|
|
17
|
+
}
|
|
18
|
+
export declare class RemoteBlocks implements IBlocks {
|
|
19
|
+
readonly options: {
|
|
20
|
+
local: AnyBlockStore;
|
|
21
|
+
localTimeout?: number;
|
|
22
|
+
messageProcessingConcurrency?: number;
|
|
23
|
+
publish: (message: BlockRequest | BlockResponse, options?: {
|
|
24
|
+
to?: string[];
|
|
25
|
+
}) => Promise<Uint8Array | void>;
|
|
26
|
+
waitFor(peer: PeerId | PublicSignKey): Promise<void>;
|
|
27
|
+
};
|
|
28
|
+
localStore: BlockStore;
|
|
29
|
+
private _responseHandler?;
|
|
30
|
+
private _resolvers;
|
|
31
|
+
private _loadFetchQueue;
|
|
32
|
+
private _readFromPeersPromises;
|
|
33
|
+
_open: boolean;
|
|
34
|
+
private _events;
|
|
35
|
+
private closeController;
|
|
36
|
+
constructor(options: {
|
|
37
|
+
local: AnyBlockStore;
|
|
38
|
+
localTimeout?: number;
|
|
39
|
+
messageProcessingConcurrency?: number;
|
|
40
|
+
publish: (message: BlockRequest | BlockResponse, options?: {
|
|
41
|
+
to?: string[];
|
|
42
|
+
}) => Promise<Uint8Array | void>;
|
|
43
|
+
waitFor(peer: PeerId | PublicSignKey): Promise<void>;
|
|
44
|
+
});
|
|
45
|
+
put(bytes: Uint8Array): Promise<string>;
|
|
46
|
+
has(cid: string): Promise<boolean>;
|
|
47
|
+
get(cid: string, options?: GetOptions | undefined): Promise<Uint8Array | undefined>;
|
|
48
|
+
rm(cid: string): Promise<void>;
|
|
49
|
+
iterator(): AsyncGenerator<[string, Uint8Array], void, void>;
|
|
50
|
+
start(): Promise<void>;
|
|
51
|
+
onMessage(data: BlockMessage): any;
|
|
52
|
+
onReachable(publicKey: PublicSignKey): void;
|
|
53
|
+
private handleFetchRequest;
|
|
54
|
+
private _readFromPeers;
|
|
55
|
+
stop(): Promise<void>;
|
|
56
|
+
waitFor(peer: PeerId | PublicSignKey): Promise<void>;
|
|
57
|
+
size(): Promise<number>;
|
|
58
|
+
get status(): import("./interface.js").StoreStatus;
|
|
59
|
+
}
|