@hashtree/core 0.1.1 → 0.1.4
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/README.md +45 -0
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js +2 -1
- package/dist/builder.js.map +1 -1
- package/dist/compare.d.ts +2 -0
- package/dist/compare.d.ts.map +1 -0
- package/dist/compare.js +8 -0
- package/dist/compare.js.map +1 -0
- package/dist/encrypted.d.ts +5 -1
- package/dist/encrypted.d.ts.map +1 -1
- package/dist/encrypted.js +59 -32
- package/dist/encrypted.js.map +1 -1
- package/dist/hashtree.d.ts +9 -1
- package/dist/hashtree.d.ts.map +1 -1
- package/dist/hashtree.js +13 -7
- package/dist/hashtree.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/nhash.d.ts.map +1 -1
- package/dist/nhash.js +20 -39
- package/dist/nhash.js.map +1 -1
- package/dist/store/blossom.d.ts.map +1 -1
- package/dist/store/blossom.js +52 -22
- package/dist/store/blossom.js.map +1 -1
- package/dist/store/fallback.d.ts +3 -1
- package/dist/store/fallback.d.ts.map +1 -1
- package/dist/store/fallback.js +60 -15
- package/dist/store/fallback.js.map +1 -1
- package/dist/tree/create.d.ts.map +1 -1
- package/dist/tree/create.js +2 -1
- package/dist/tree/create.js.map +1 -1
- package/dist/tree/read.d.ts +5 -1
- package/dist/tree/read.d.ts.map +1 -1
- package/dist/tree/read.js +29 -11
- package/dist/tree/read.js.map +1 -1
- package/dist/types.d.ts +14 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/upload.d.ts +27 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +107 -0
- package/dist/upload.js.map +1 -0
- package/dist/worker/protocol.d.ts +18 -1
- package/dist/worker/protocol.d.ts.map +1 -1
- package/dist/worker/protocol.js +1 -1
- package/dist/worker/protocol.js.map +1 -1
- package/package.json +6 -3
- package/dist/resolver/index.d.ts +0 -5
- package/dist/resolver/index.d.ts.map +0 -1
- package/dist/resolver/index.js +0 -5
- package/dist/resolver/index.js.map +0 -1
- package/dist/resolver/nostr.d.ts +0 -82
- package/dist/resolver/nostr.d.ts.map +0 -1
- package/dist/resolver/nostr.js +0 -868
- package/dist/resolver/nostr.js.map +0 -1
- package/dist/store/dexie.d.ts +0 -44
- package/dist/store/dexie.d.ts.map +0 -1
- package/dist/store/dexie.js +0 -196
- package/dist/store/dexie.js.map +0 -1
- package/dist/store/opfs.d.ts +0 -56
- package/dist/store/opfs.d.ts.map +0 -1
- package/dist/store/opfs.js +0 -200
- package/dist/store/opfs.js.map +0 -1
- package/dist/webrtc/index.d.ts +0 -4
- package/dist/webrtc/index.d.ts.map +0 -1
- package/dist/webrtc/index.js +0 -4
- package/dist/webrtc/index.js.map +0 -1
- package/dist/webrtc/lruCache.d.ts +0 -20
- package/dist/webrtc/lruCache.d.ts.map +0 -1
- package/dist/webrtc/lruCache.js +0 -59
- package/dist/webrtc/lruCache.js.map +0 -1
- package/dist/webrtc/peer.d.ts +0 -122
- package/dist/webrtc/peer.d.ts.map +0 -1
- package/dist/webrtc/peer.js +0 -583
- package/dist/webrtc/peer.js.map +0 -1
- package/dist/webrtc/protocol.d.ts +0 -76
- package/dist/webrtc/protocol.d.ts.map +0 -1
- package/dist/webrtc/protocol.js +0 -167
- package/dist/webrtc/protocol.js.map +0 -1
- package/dist/webrtc/store.d.ts +0 -190
- package/dist/webrtc/store.d.ts.map +0 -1
- package/dist/webrtc/store.js +0 -1043
- package/dist/webrtc/store.js.map +0 -1
- package/dist/webrtc/types.d.ts +0 -196
- package/dist/webrtc/types.d.ts.map +0 -1
- package/dist/webrtc/types.js +0 -46
- package/dist/webrtc/types.js.map +0 -1
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import type { DataRequest, DataResponse, DataMessage } from './types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Encode a request message to wire format
|
|
4
|
-
*/
|
|
5
|
-
export declare function encodeRequest(req: DataRequest): ArrayBuffer;
|
|
6
|
-
/**
|
|
7
|
-
* Encode a response message to wire format
|
|
8
|
-
*/
|
|
9
|
-
export declare function encodeResponse(res: DataResponse): ArrayBuffer;
|
|
10
|
-
/**
|
|
11
|
-
* Parse a wire format message
|
|
12
|
-
*/
|
|
13
|
-
export declare function parseMessage(data: ArrayBuffer | Uint8Array): DataMessage | null;
|
|
14
|
-
/**
|
|
15
|
-
* Verify that data matches its expected hash
|
|
16
|
-
*/
|
|
17
|
-
export declare function verifyHash(data: Uint8Array, expectedHash: Uint8Array): Promise<boolean>;
|
|
18
|
-
/**
|
|
19
|
-
* Pending request tracking
|
|
20
|
-
*/
|
|
21
|
-
export interface PendingRequest {
|
|
22
|
-
hash: Uint8Array;
|
|
23
|
-
resolve: (data: Uint8Array | null) => void;
|
|
24
|
-
timeout: ReturnType<typeof setTimeout>;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Per-peer HTL config (Freenet-style probabilistic decrement)
|
|
28
|
-
* Generated once per peer connection, stays fixed for connection lifetime
|
|
29
|
-
*/
|
|
30
|
-
export interface PeerHTLConfig {
|
|
31
|
-
decrementAtMax: boolean;
|
|
32
|
-
decrementAtMin: boolean;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Generate random HTL config for a new peer connection
|
|
36
|
-
*/
|
|
37
|
-
export declare function generatePeerHTLConfig(): PeerHTLConfig;
|
|
38
|
-
/**
|
|
39
|
-
* Decrement HTL using peer's config (Freenet-style probabilistic)
|
|
40
|
-
* Called when SENDING to a peer, not on receive
|
|
41
|
-
*/
|
|
42
|
-
export declare function decrementHTL(htl: number, config: PeerHTLConfig): number;
|
|
43
|
-
/**
|
|
44
|
-
* Check if a request should be forwarded based on HTL
|
|
45
|
-
*/
|
|
46
|
-
export declare function shouldForward(htl: number): boolean;
|
|
47
|
-
/**
|
|
48
|
-
* Create a request body
|
|
49
|
-
*/
|
|
50
|
-
export declare function createRequest(hash: Uint8Array, htl?: number): DataRequest;
|
|
51
|
-
/**
|
|
52
|
-
* Create a response body
|
|
53
|
-
*/
|
|
54
|
-
export declare function createResponse(hash: Uint8Array, data: Uint8Array): DataResponse;
|
|
55
|
-
/**
|
|
56
|
-
* Create a fragmented response body
|
|
57
|
-
*/
|
|
58
|
-
export declare function createFragmentResponse(hash: Uint8Array, data: Uint8Array, index: number, total: number): DataResponse;
|
|
59
|
-
/**
|
|
60
|
-
* Check if a response is fragmented
|
|
61
|
-
*/
|
|
62
|
-
export declare function isFragmented(res: DataResponse): boolean;
|
|
63
|
-
/**
|
|
64
|
-
* Convert hash to hex string for use as map key
|
|
65
|
-
*/
|
|
66
|
-
export declare function hashToKey(hash: Uint8Array): string;
|
|
67
|
-
/**
|
|
68
|
-
* Handle a response message - verify hash and resolve pending request
|
|
69
|
-
* Returns true if hash verified, false if hash mismatch, undefined if no pending request
|
|
70
|
-
*/
|
|
71
|
-
export declare function handleResponse(res: DataResponse, pendingRequests: Map<string, PendingRequest>): Promise<boolean | undefined>;
|
|
72
|
-
/**
|
|
73
|
-
* Clear all pending requests (on disconnect/close)
|
|
74
|
-
*/
|
|
75
|
-
export declare function clearPendingRequests(pendingRequests: Map<string, PendingRequest>): void;
|
|
76
|
-
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/webrtc/protocol.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AASzE;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,WAAW,GAAG,WAAW,CAM3D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,YAAY,GAAG,WAAW,CAM7D;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,WAAW,GAAG,UAAU,GAAG,W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EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,GAC3C,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAe9B;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,IAAI,CAMvF"}
|
package/dist/webrtc/protocol.js
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared protocol utilities for hashtree data exchange
|
|
3
|
-
*
|
|
4
|
-
* Used by WebRTC peer.ts implementation.
|
|
5
|
-
*
|
|
6
|
-
* Wire format: [type byte][msgpack body]
|
|
7
|
-
* Request: [0x00][msgpack: {id: u32, h: bytes32, htl?: u8}]
|
|
8
|
-
* Response: [0x01][msgpack: {id: u32, h: bytes32, d: bytes}]
|
|
9
|
-
*/
|
|
10
|
-
import { encode, decode } from '@msgpack/msgpack';
|
|
11
|
-
import { sha256 } from '../hash.js';
|
|
12
|
-
import { MAX_HTL, DECREMENT_AT_MAX_PROB, DECREMENT_AT_MIN_PROB, MSG_TYPE_REQUEST, MSG_TYPE_RESPONSE, } from './types.js';
|
|
13
|
-
/**
|
|
14
|
-
* Encode a request message to wire format
|
|
15
|
-
*/
|
|
16
|
-
export function encodeRequest(req) {
|
|
17
|
-
const body = encode(req);
|
|
18
|
-
const result = new Uint8Array(1 + body.length);
|
|
19
|
-
result[0] = MSG_TYPE_REQUEST;
|
|
20
|
-
result.set(body, 1);
|
|
21
|
-
return result.buffer;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Encode a response message to wire format
|
|
25
|
-
*/
|
|
26
|
-
export function encodeResponse(res) {
|
|
27
|
-
const body = encode(res);
|
|
28
|
-
const result = new Uint8Array(1 + body.length);
|
|
29
|
-
result[0] = MSG_TYPE_RESPONSE;
|
|
30
|
-
result.set(body, 1);
|
|
31
|
-
return result.buffer;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Parse a wire format message
|
|
35
|
-
*/
|
|
36
|
-
export function parseMessage(data) {
|
|
37
|
-
try {
|
|
38
|
-
const bytes = data instanceof ArrayBuffer ? new Uint8Array(data) : data;
|
|
39
|
-
if (bytes.length < 2)
|
|
40
|
-
return null;
|
|
41
|
-
const type = bytes[0];
|
|
42
|
-
const body = bytes.slice(1);
|
|
43
|
-
if (type === MSG_TYPE_REQUEST) {
|
|
44
|
-
return { type: MSG_TYPE_REQUEST, body: decode(body) };
|
|
45
|
-
}
|
|
46
|
-
else if (type === MSG_TYPE_RESPONSE) {
|
|
47
|
-
return { type: MSG_TYPE_RESPONSE, body: decode(body) };
|
|
48
|
-
}
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
catch {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Verify that data matches its expected hash
|
|
57
|
-
*/
|
|
58
|
-
export async function verifyHash(data, expectedHash) {
|
|
59
|
-
const computedHash = await sha256(data);
|
|
60
|
-
if (computedHash.length !== expectedHash.length)
|
|
61
|
-
return false;
|
|
62
|
-
for (let i = 0; i < computedHash.length; i++) {
|
|
63
|
-
if (computedHash[i] !== expectedHash[i])
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Generate random HTL config for a new peer connection
|
|
70
|
-
*/
|
|
71
|
-
export function generatePeerHTLConfig() {
|
|
72
|
-
return {
|
|
73
|
-
decrementAtMax: Math.random() < DECREMENT_AT_MAX_PROB,
|
|
74
|
-
decrementAtMin: Math.random() < DECREMENT_AT_MIN_PROB,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Decrement HTL using peer's config (Freenet-style probabilistic)
|
|
79
|
-
* Called when SENDING to a peer, not on receive
|
|
80
|
-
*/
|
|
81
|
-
export function decrementHTL(htl, config) {
|
|
82
|
-
if (htl <= 0)
|
|
83
|
-
return 0;
|
|
84
|
-
if (htl === MAX_HTL) {
|
|
85
|
-
// At max: only decrement if this peer's config says so
|
|
86
|
-
return config.decrementAtMax ? htl - 1 : htl;
|
|
87
|
-
}
|
|
88
|
-
else if (htl === 1) {
|
|
89
|
-
// At min: only decrement if this peer's config says so
|
|
90
|
-
return config.decrementAtMin ? 0 : htl;
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
// Middle values: always decrement
|
|
94
|
-
return htl - 1;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Check if a request should be forwarded based on HTL
|
|
99
|
-
*/
|
|
100
|
-
export function shouldForward(htl) {
|
|
101
|
-
return htl > 0;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Create a request body
|
|
105
|
-
*/
|
|
106
|
-
export function createRequest(hash, htl = MAX_HTL) {
|
|
107
|
-
return { h: hash, htl };
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Create a response body
|
|
111
|
-
*/
|
|
112
|
-
export function createResponse(hash, data) {
|
|
113
|
-
return { h: hash, d: data };
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Create a fragmented response body
|
|
117
|
-
*/
|
|
118
|
-
export function createFragmentResponse(hash, data, index, total) {
|
|
119
|
-
return { h: hash, d: data, i: index, n: total };
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Check if a response is fragmented
|
|
123
|
-
*/
|
|
124
|
-
export function isFragmented(res) {
|
|
125
|
-
return res.i !== undefined && res.n !== undefined;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Convert hash to hex string for use as map key
|
|
129
|
-
*/
|
|
130
|
-
export function hashToKey(hash) {
|
|
131
|
-
let key = '';
|
|
132
|
-
for (let i = 0; i < hash.length; i++) {
|
|
133
|
-
key += hash[i].toString(16).padStart(2, '0');
|
|
134
|
-
}
|
|
135
|
-
return key;
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Handle a response message - verify hash and resolve pending request
|
|
139
|
-
* Returns true if hash verified, false if hash mismatch, undefined if no pending request
|
|
140
|
-
*/
|
|
141
|
-
export async function handleResponse(res, pendingRequests) {
|
|
142
|
-
const key = hashToKey(res.h);
|
|
143
|
-
const pending = pendingRequests.get(key);
|
|
144
|
-
if (!pending)
|
|
145
|
-
return undefined;
|
|
146
|
-
clearTimeout(pending.timeout);
|
|
147
|
-
pendingRequests.delete(key);
|
|
148
|
-
const isValid = await verifyHash(res.d, res.h);
|
|
149
|
-
if (isValid) {
|
|
150
|
-
pending.resolve(res.d);
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
pending.resolve(null);
|
|
154
|
-
}
|
|
155
|
-
return isValid;
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Clear all pending requests (on disconnect/close)
|
|
159
|
-
*/
|
|
160
|
-
export function clearPendingRequests(pendingRequests) {
|
|
161
|
-
for (const pending of pendingRequests.values()) {
|
|
162
|
-
clearTimeout(pending.timeout);
|
|
163
|
-
pending.resolve(null);
|
|
164
|
-
}
|
|
165
|
-
pendingRequests.clear();
|
|
166
|
-
}
|
|
167
|
-
//# sourceMappingURL=protocol.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/webrtc/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpC,OAAO,EACL,OAAO,EACP,qBAAqB,EACrB,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,GAAgB;IAC5C,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IACzB,MAAM,MAAM,GAAG,IAAI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AG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAC7B,MAAM,OAAO,GAAG,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACzC,IAAI,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IAE/B,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9B,eAAe,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAE5B,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;IAC/C,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,eAA4C;IAC/E,KAAK,MAAM,OAAO,IAAI,eAAe,CAAC,MAAM,EAAE,EAAE,CAAC;QAC/C,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC9B,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IACD,eAAe,CAAC,KAAK,EAAE,CAAC;AAC1B,CAAC"}
|
package/dist/webrtc/store.d.ts
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import type { Store, Hash } from '../types.js';
|
|
2
|
-
import { type WebRTCStoreConfig, type PeerStatus, type WebRTCStoreEventHandler, type PeerPool, type PeerClassifier, type PoolConfig, type WebRTCStats } from './types.js';
|
|
3
|
-
import { Peer } from './peer.js';
|
|
4
|
-
export declare const DEFAULT_RELAYS: string[];
|
|
5
|
-
export declare class WebRTCStore implements Store {
|
|
6
|
-
private config;
|
|
7
|
-
private pools;
|
|
8
|
-
private peerClassifier;
|
|
9
|
-
private getFollowedPubkeys;
|
|
10
|
-
private isPeerBlocked;
|
|
11
|
-
private signer;
|
|
12
|
-
private encrypt;
|
|
13
|
-
private decrypt;
|
|
14
|
-
private giftWrap;
|
|
15
|
-
private giftUnwrap;
|
|
16
|
-
private myPeerId;
|
|
17
|
-
private pool;
|
|
18
|
-
private subscriptions;
|
|
19
|
-
private helloSubscription;
|
|
20
|
-
private peers;
|
|
21
|
-
private pendingOtherPubkeys;
|
|
22
|
-
private helloInterval;
|
|
23
|
-
private cleanupInterval;
|
|
24
|
-
private eventHandlers;
|
|
25
|
-
private running;
|
|
26
|
-
private pendingReqs;
|
|
27
|
-
private pendingGets;
|
|
28
|
-
private blossomFetches;
|
|
29
|
-
private currentHelloAuthors;
|
|
30
|
-
constructor(config: WebRTCStoreConfig);
|
|
31
|
-
private log;
|
|
32
|
-
/**
|
|
33
|
-
* Get pool counts
|
|
34
|
-
*/
|
|
35
|
-
private getPoolCounts;
|
|
36
|
-
/**
|
|
37
|
-
* Check if we can accept a peer in a given pool
|
|
38
|
-
*/
|
|
39
|
-
private canAcceptPeer;
|
|
40
|
-
/**
|
|
41
|
-
* Check if a pool is satisfied
|
|
42
|
-
*/
|
|
43
|
-
private isPoolSatisfied;
|
|
44
|
-
/**
|
|
45
|
-
* Check if we already have a connection from a pubkey in the 'other' pool.
|
|
46
|
-
* In the 'other' pool, we only allow 1 instance per pubkey.
|
|
47
|
-
* Also checks pendingOtherPubkeys to prevent race conditions.
|
|
48
|
-
*/
|
|
49
|
-
private hasOtherPoolPubkey;
|
|
50
|
-
/**
|
|
51
|
-
* Start the WebRTC store - connect to relays and begin peer discovery
|
|
52
|
-
*/
|
|
53
|
-
start(): void;
|
|
54
|
-
/**
|
|
55
|
-
* Stop the WebRTC store
|
|
56
|
-
*/
|
|
57
|
-
stop(): void;
|
|
58
|
-
/**
|
|
59
|
-
* Set relays and reconnect. Useful for runtime relay configuration changes.
|
|
60
|
-
* Closes existing subscriptions and starts new ones with the updated relays.
|
|
61
|
-
*/
|
|
62
|
-
setRelays(relays: string[]): void;
|
|
63
|
-
/**
|
|
64
|
-
* Add event listener
|
|
65
|
-
*/
|
|
66
|
-
on(handler: WebRTCStoreEventHandler): () => void;
|
|
67
|
-
private emit;
|
|
68
|
-
private startSubscription;
|
|
69
|
-
/**
|
|
70
|
-
* Setup hello subscription based on pool configuration
|
|
71
|
-
* - If both pools are 0: don't subscribe to hellos
|
|
72
|
-
* - If other pool is disabled but follows is enabled: subscribe to followed pubkeys only
|
|
73
|
-
* - If other pool is enabled: subscribe to all hellos
|
|
74
|
-
*/
|
|
75
|
-
private setupHelloSubscription;
|
|
76
|
-
/**
|
|
77
|
-
* Update hello subscription when follows list changes
|
|
78
|
-
* Call this after social graph updates
|
|
79
|
-
*/
|
|
80
|
-
updateHelloSubscription(): void;
|
|
81
|
-
private handleSignalingEvent;
|
|
82
|
-
private handleSignalingMessage;
|
|
83
|
-
private handleHello;
|
|
84
|
-
private handleOffer;
|
|
85
|
-
private connectToPeer;
|
|
86
|
-
private handlePeerClose;
|
|
87
|
-
/**
|
|
88
|
-
* Forward a request to other peers (excluding the requester)
|
|
89
|
-
* Called by Peer when it receives a request it can't fulfill locally
|
|
90
|
-
* Uses sequential queries with delays between attempts
|
|
91
|
-
* @param htl - Hops To Live (already decremented by calling peer)
|
|
92
|
-
*/
|
|
93
|
-
private forwardRequest;
|
|
94
|
-
/**
|
|
95
|
-
* Send data to all peers who have requested this hash
|
|
96
|
-
* Called when we receive data that peers may be waiting for
|
|
97
|
-
*/
|
|
98
|
-
sendToInterestedPeers(hash: Uint8Array, data: Uint8Array): number;
|
|
99
|
-
private sendSignaling;
|
|
100
|
-
/**
|
|
101
|
-
* Force send a hello message (useful for testing after pool config changes)
|
|
102
|
-
*/
|
|
103
|
-
sendHello(): void;
|
|
104
|
-
private maybeSendHello;
|
|
105
|
-
private cleanupConnections;
|
|
106
|
-
/**
|
|
107
|
-
* Get number of connected peers
|
|
108
|
-
*/
|
|
109
|
-
getConnectedCount(): number;
|
|
110
|
-
/**
|
|
111
|
-
* Get all peer statuses
|
|
112
|
-
*/
|
|
113
|
-
getPeers(): PeerStatus[];
|
|
114
|
-
/**
|
|
115
|
-
* Disconnect all peers with a given pubkey
|
|
116
|
-
* Used when blocking a peer to immediately disconnect them
|
|
117
|
-
*/
|
|
118
|
-
disconnectPeerByPubkey(pubkey: string): void;
|
|
119
|
-
/**
|
|
120
|
-
* Get my peer ID (uuid part only)
|
|
121
|
-
*/
|
|
122
|
-
getMyPeerId(): string;
|
|
123
|
-
/**
|
|
124
|
-
* Check if store is satisfied (has enough connections in all pools)
|
|
125
|
-
*/
|
|
126
|
-
isSatisfied(): boolean;
|
|
127
|
-
/**
|
|
128
|
-
* Update peer classifier (e.g., when social graph updates)
|
|
129
|
-
*/
|
|
130
|
-
setPeerClassifier(classifier: PeerClassifier): void;
|
|
131
|
-
/**
|
|
132
|
-
* Update pool configuration (e.g., from settings)
|
|
133
|
-
*/
|
|
134
|
-
setPoolConfig(pools: {
|
|
135
|
-
follows: PoolConfig;
|
|
136
|
-
other: PoolConfig;
|
|
137
|
-
}): void;
|
|
138
|
-
/**
|
|
139
|
-
* Get current pool configuration
|
|
140
|
-
*/
|
|
141
|
-
getPoolConfig(): {
|
|
142
|
-
follows: PoolConfig;
|
|
143
|
-
other: PoolConfig;
|
|
144
|
-
};
|
|
145
|
-
/**
|
|
146
|
-
* Get fallback stores count
|
|
147
|
-
*/
|
|
148
|
-
getFallbackStoresCount(): number;
|
|
149
|
-
/**
|
|
150
|
-
* Get WebRTC stats (aggregate and per-peer)
|
|
151
|
-
*/
|
|
152
|
-
getStats(): {
|
|
153
|
-
aggregate: WebRTCStats;
|
|
154
|
-
perPeer: Map<string, {
|
|
155
|
-
pubkey: string;
|
|
156
|
-
pool: PeerPool;
|
|
157
|
-
stats: ReturnType<Peer['getStats']>;
|
|
158
|
-
}>;
|
|
159
|
-
};
|
|
160
|
-
put(hash: Hash, data: Uint8Array): Promise<boolean>;
|
|
161
|
-
get(hash: Hash): Promise<Uint8Array | null>;
|
|
162
|
-
/**
|
|
163
|
-
* Internal method to fetch data from peers (separated for deduplication)
|
|
164
|
-
*/
|
|
165
|
-
private fetchFromPeers;
|
|
166
|
-
/**
|
|
167
|
-
* Helper to create a delay promise
|
|
168
|
-
*/
|
|
169
|
-
private delay;
|
|
170
|
-
/**
|
|
171
|
-
* Add hash to pending requests list and wait for it to be resolved by peers
|
|
172
|
-
* Also immediately tries any connected peers that weren't tried yet
|
|
173
|
-
*/
|
|
174
|
-
private waitForHash;
|
|
175
|
-
/**
|
|
176
|
-
* Try all currently connected peers for a specific hash in the pending requests
|
|
177
|
-
*/
|
|
178
|
-
private tryConnectedPeersForHash;
|
|
179
|
-
/**
|
|
180
|
-
* Remove a pending request from the list
|
|
181
|
-
*/
|
|
182
|
-
private removePendingReq;
|
|
183
|
-
/**
|
|
184
|
-
* Try pending requests with a newly connected peer
|
|
185
|
-
*/
|
|
186
|
-
private tryPendingReqs;
|
|
187
|
-
has(hash: Hash): Promise<boolean>;
|
|
188
|
-
delete(hash: Hash): Promise<boolean>;
|
|
189
|
-
}
|
|
190
|
-
//# sourceMappingURL=store.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/webrtc/store.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,EAKL,KAAK,iBAAiB,EACtB,KAAK,UAAU,EAEf,KAAK,uBAAuB,EAO5B,KAAK,QAAQ,EACb,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,WAAW,EACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,eAAO,MAAM,cAAc,UAO1B,CAAC;AAsBF,qBAAa,WAAY,YAAW,KAAK;IACvC,OAAO,CAAC,MAAM,CASZ;IACF,OAAO,CAAC,KAAK,CAA6C;IAC1D,OAAO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