@peerbit/shared-log 2.0.1 → 3.0.0
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/__benchmark__/index.d.ts +1 -0
- package/lib/esm/__benchmark__/index.js +127 -0
- package/lib/esm/__benchmark__/index.js.map +1 -0
- package/lib/esm/exchange-heads.d.ts +15 -12
- package/lib/esm/exchange-heads.js +71 -38
- package/lib/esm/exchange-heads.js.map +1 -1
- package/lib/esm/index.d.ts +42 -14
- package/lib/esm/index.js +322 -66
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/replication.d.ts +26 -0
- package/lib/esm/replication.js +61 -0
- package/lib/esm/replication.js.map +1 -0
- package/package.json +6 -6
- package/src/__benchmark__/index.ts +111 -0
- package/src/exchange-heads.ts +73 -43
- package/src/index.ts +443 -77
- package/src/replication.ts +61 -0
- package/lib/esm/exchange-replication.d.ts +0 -14
- package/lib/esm/exchange-replication.js +0 -215
- package/lib/esm/exchange-replication.js.map +0 -1
- package/src/exchange-replication.ts +0 -206
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { variant, deserialize, serialize, field } from "@dao-xyz/borsh";
|
|
2
|
+
|
|
3
|
+
interface SharedLog {
|
|
4
|
+
getReplicatorsSorted(): { hash: string; timestamp: number }[] | undefined;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export class MinReplicas {
|
|
8
|
+
getValue(log: SharedLog): number {
|
|
9
|
+
throw new Error("Not implemented");
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@variant(0)
|
|
14
|
+
export class AbsoluteReplicas extends MinReplicas {
|
|
15
|
+
@field({ type: "u32" })
|
|
16
|
+
_value: number;
|
|
17
|
+
|
|
18
|
+
constructor(value: number) {
|
|
19
|
+
super();
|
|
20
|
+
this._value = value;
|
|
21
|
+
}
|
|
22
|
+
getValue(_log: SharedLog): number {
|
|
23
|
+
return this._value;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/*
|
|
28
|
+
@variant(1)
|
|
29
|
+
export class RelativeMinReplicas extends MinReplicas {
|
|
30
|
+
_value: number; // (0, 1]
|
|
31
|
+
|
|
32
|
+
constructor(value: number) {
|
|
33
|
+
super();
|
|
34
|
+
this._value = value;
|
|
35
|
+
}
|
|
36
|
+
getValue(log: SharedLog): number {
|
|
37
|
+
return Math.ceil(this._value * log.getReplicatorsSorted()!.length); // TODO TYPES
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
export const encodeReplicas = (minReplicas: MinReplicas): Uint8Array => {
|
|
43
|
+
return serialize(minReplicas);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const decodeReplicas = (entry: {
|
|
47
|
+
meta: { data?: Uint8Array };
|
|
48
|
+
}): MinReplicas => {
|
|
49
|
+
return deserialize(entry.meta.data!, MinReplicas);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const maxReplicas = (
|
|
53
|
+
log: SharedLog,
|
|
54
|
+
entries: { meta: { data?: Uint8Array } }[]
|
|
55
|
+
) => {
|
|
56
|
+
let max = 0;
|
|
57
|
+
for (const entry of entries) {
|
|
58
|
+
max = Math.max(decodeReplicas(entry).getValue(log), max);
|
|
59
|
+
}
|
|
60
|
+
return max;
|
|
61
|
+
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { TransportMessage } from "./message.js";
|
|
2
|
-
export declare const WAIT_FOR_PEERS_TIME = 5000;
|
|
3
|
-
export declare class ReplicatorInfo extends TransportMessage {
|
|
4
|
-
fromId?: string;
|
|
5
|
-
topic: string;
|
|
6
|
-
store: number;
|
|
7
|
-
heads?: string[];
|
|
8
|
-
constructor(props?: {
|
|
9
|
-
fromId?: string;
|
|
10
|
-
topic: string;
|
|
11
|
-
store: number;
|
|
12
|
-
heads?: string[];
|
|
13
|
-
});
|
|
14
|
-
}
|
|
@@ -1,215 +0,0 @@
|
|
|
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 { variant, field, option, vec } from "@dao-xyz/borsh";
|
|
11
|
-
import { TransportMessage } from "./message.js";
|
|
12
|
-
export const WAIT_FOR_PEERS_TIME = 5000;
|
|
13
|
-
export let ReplicatorInfo = class ReplicatorInfo extends TransportMessage {
|
|
14
|
-
fromId;
|
|
15
|
-
topic;
|
|
16
|
-
store; // address
|
|
17
|
-
heads; // address
|
|
18
|
-
constructor(props) {
|
|
19
|
-
super();
|
|
20
|
-
if (props) {
|
|
21
|
-
this.fromId = props.fromId;
|
|
22
|
-
this.topic = props.topic;
|
|
23
|
-
this.store = props.store;
|
|
24
|
-
this.heads = props.heads;
|
|
25
|
-
/* this.allowForks = props.allowForks; */
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
__decorate([
|
|
30
|
-
field({ type: option("string") }),
|
|
31
|
-
__metadata("design:type", String)
|
|
32
|
-
], ReplicatorInfo.prototype, "fromId", void 0);
|
|
33
|
-
__decorate([
|
|
34
|
-
field({ type: "string" }),
|
|
35
|
-
__metadata("design:type", String)
|
|
36
|
-
], ReplicatorInfo.prototype, "topic", void 0);
|
|
37
|
-
__decorate([
|
|
38
|
-
field({ type: "u32" }),
|
|
39
|
-
__metadata("design:type", Number)
|
|
40
|
-
], ReplicatorInfo.prototype, "store", void 0);
|
|
41
|
-
__decorate([
|
|
42
|
-
field({ type: vec("string") }),
|
|
43
|
-
__metadata("design:type", Array)
|
|
44
|
-
], ReplicatorInfo.prototype, "heads", void 0);
|
|
45
|
-
ReplicatorInfo = __decorate([
|
|
46
|
-
variant([2, 0]),
|
|
47
|
-
__metadata("design:paramtypes", [Object])
|
|
48
|
-
], ReplicatorInfo);
|
|
49
|
-
/* @variant([2, 1])
|
|
50
|
-
export class RequestReplicatorInfo extends ProtocolMessage {
|
|
51
|
-
@field({ type: "string" })
|
|
52
|
-
id: string;
|
|
53
|
-
|
|
54
|
-
@field({ type: "string" })
|
|
55
|
-
topic: string;
|
|
56
|
-
|
|
57
|
-
@field({ type: "string" })
|
|
58
|
-
address: string; // address
|
|
59
|
-
|
|
60
|
-
@field({ type: vec("string") })
|
|
61
|
-
heads: string[];
|
|
62
|
-
|
|
63
|
-
constructor(props?: {
|
|
64
|
-
topic: string;
|
|
65
|
-
address: Address | string;
|
|
66
|
-
heads: string[];
|
|
67
|
-
}) {
|
|
68
|
-
super();
|
|
69
|
-
if (props) {
|
|
70
|
-
this.id = uuid();
|
|
71
|
-
this.topic = props.topic;
|
|
72
|
-
this.address =
|
|
73
|
-
typeof props.address === "string"
|
|
74
|
-
? props.address
|
|
75
|
-
: props.address.toString();
|
|
76
|
-
this.heads = props.heads;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
*/
|
|
81
|
-
/* export interface PeerInfoWithMeta {
|
|
82
|
-
peerInfo: ReplicatorInfo;
|
|
83
|
-
publicKey: PublicSignKey;
|
|
84
|
-
} */
|
|
85
|
-
/* return new PeerInfo({
|
|
86
|
-
key: this._shard.peer.orbitDB.identity,
|
|
87
|
-
addresses: (await this._shard.peer.node.id()).addresses.map(x => x.toString()),
|
|
88
|
-
memoryLeft: v8.getHeapStatistics().total_available_size//v8
|
|
89
|
-
}) */
|
|
90
|
-
/* export const createEmitHealthCheckJob = (properties: { stores: () => string[] | undefined, subscribingForReplication: (topic: string) => boolean }, replicationTopic: string, publish: (topic: string, message: Uint8Array) => Promise<void>, isOnline: () => boolean, controller: AbortController, sign: (bytes: Uint8Array) => Promise<{ signature: Uint8Array, publicKey: PublicKey }>, encryption: PublicKeyEncryption) => {
|
|
91
|
-
|
|
92
|
-
const emitHealthcheck = async (): Promise<void> => {
|
|
93
|
-
const s = properties.stores();
|
|
94
|
-
if (!s || s.length === 0) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
const signedMessage = await new MaybeSigned({
|
|
98
|
-
data: serialize(new PeerInfo({
|
|
99
|
-
replicationTopic,
|
|
100
|
-
stores: s,
|
|
101
|
-
subscribingForReplication: properties.subscribingForReplication(replicationTopic),
|
|
102
|
-
memoryLeft: v8.getHeapStatistics().total_available_size//v8
|
|
103
|
-
|
|
104
|
-
}))
|
|
105
|
-
}).sign(sign)
|
|
106
|
-
const decryptedMessage = new DecryptedThing({
|
|
107
|
-
data: serialize(signedMessage)
|
|
108
|
-
})// TODO add encryption .init(encryption).encrypt(lala)
|
|
109
|
-
|
|
110
|
-
return publish(replicationTopic, serialize(decryptedMessage))
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const task = async () => {
|
|
114
|
-
await emitHealthcheck();
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const cron = async () => {
|
|
118
|
-
let stop = false;
|
|
119
|
-
let promise: Promise<any> = undefined;
|
|
120
|
-
let delayStopper: () => void | undefined = undefined;
|
|
121
|
-
controller.signal.addEventListener("abort", async () => {
|
|
122
|
-
stop = true;
|
|
123
|
-
if (delayStopper)
|
|
124
|
-
delayStopper();
|
|
125
|
-
await promise;
|
|
126
|
-
});
|
|
127
|
-
while (isOnline() && !stop) { //
|
|
128
|
-
promise = task();
|
|
129
|
-
await promise;
|
|
130
|
-
await delay(EMIT_HEALTHCHECK_INTERVAL, { stopperCallback: (stopper) => { delayStopper = stopper } }); // some delay
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return cron;
|
|
134
|
-
}
|
|
135
|
-
*/
|
|
136
|
-
/* export const requestPeerInfo = async (
|
|
137
|
-
serializedRequest: Uint8Array,
|
|
138
|
-
replicationTopic: string,
|
|
139
|
-
publish: (topic: string, message: Uint8Array) => Promise<void>,
|
|
140
|
-
identity: Identity
|
|
141
|
-
) => {
|
|
142
|
-
const signedMessage = await new MaybeSigned({
|
|
143
|
-
data: serializedRequest,
|
|
144
|
-
}).sign(async (data) => {
|
|
145
|
-
return {
|
|
146
|
-
publicKey: identity.publicKey,
|
|
147
|
-
signature: await identity.sign(data),
|
|
148
|
-
};
|
|
149
|
-
});
|
|
150
|
-
const decryptedMessage = new DecryptedThing({
|
|
151
|
-
data: serialize(signedMessage),
|
|
152
|
-
}); // TODO add encryption .init(encryption).encrypt(lala)
|
|
153
|
-
|
|
154
|
-
return publish(replicationTopic, serialize(decryptedMessage));
|
|
155
|
-
}; */
|
|
156
|
-
/* export const exchangePeerInfo = async (
|
|
157
|
-
fromId: string,
|
|
158
|
-
replicationTopic: string,
|
|
159
|
-
store: Store<any>,
|
|
160
|
-
heads: string[] | undefined,
|
|
161
|
-
publish: (message: Uint8Array) => Promise<void>,
|
|
162
|
-
sign: (
|
|
163
|
-
bytes: Uint8Array
|
|
164
|
-
) => Promise<{ signature: Uint8Array; publicKey: PublicSignKey }>
|
|
165
|
-
) => {
|
|
166
|
-
const signedMessage = await new MaybeSigned({
|
|
167
|
-
data: serialize(
|
|
168
|
-
new ReplicatorInfo({
|
|
169
|
-
fromId,
|
|
170
|
-
replicationTopic,
|
|
171
|
-
store: store._storeIndex,
|
|
172
|
-
heads,
|
|
173
|
-
})
|
|
174
|
-
),
|
|
175
|
-
}).sign(sign);
|
|
176
|
-
|
|
177
|
-
const decryptedMessage = new DecryptedThing({
|
|
178
|
-
data: serialize(signedMessage),
|
|
179
|
-
}); // TODO add encryption .init(encryption).encrypt(lala)
|
|
180
|
-
|
|
181
|
-
return publish(serialize(decryptedMessage));
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
export class ResourceRequirement {
|
|
185
|
-
async ok(_orbitdb: Peerbit): Promise<boolean> {
|
|
186
|
-
throw new Error("Not implemented");
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
@variant(0)
|
|
191
|
-
export class NoResourceRequirement extends ResourceRequirement {} */
|
|
192
|
-
/* @variant(1)
|
|
193
|
-
export class HeapSizeRequirement extends ResourceRequirement {
|
|
194
|
-
|
|
195
|
-
@field({ type: 'u64' })
|
|
196
|
-
heapSize: bigint
|
|
197
|
-
|
|
198
|
-
constructor(properties?: { heapSize: bigint }) {
|
|
199
|
-
super();
|
|
200
|
-
if (properties) {
|
|
201
|
-
this.heapSize = properties.heapSize;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
async ok(orbitdb: OrbitDB): Promise<boolean> {
|
|
206
|
-
if (!v8 || typeof orbitdb.heapsizeLimitForForks !== 'number') {
|
|
207
|
-
return true;
|
|
208
|
-
}
|
|
209
|
-
const usedHeap: number = v8.getHeapStatistics().used_heap_size;
|
|
210
|
-
return BigInt(usedHeap) + this.heapSize < orbitdb.heapsizeLimitForForks;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
} */
|
|
215
|
-
//# sourceMappingURL=exchange-replication.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"exchange-replication.js","sourceRoot":"","sources":["../../src/exchange-replication.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC;AAGjC,WAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,gBAAgB;IAEnD,MAAM,CAAU;IAGhB,KAAK,CAAS;IAGd,KAAK,CAAS,CAAC,UAAU;IAGzB,KAAK,CAAY,CAAC,UAAU;IAE5B,YAAY,KAKX;QACA,KAAK,EAAE,CAAC;QACR,IAAI,KAAK,EAAE;YACV,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;YAC3B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;YACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;YACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;YACzB,0CAA0C;SAC1C;IACF,CAAC;CACD,CAAA;AA1BA;IADC,KAAK,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;;8CAClB;AAGhB;IADC,KAAK,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;;6CACZ;AAGd;IADC,KAAK,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;;6CACT;AAGd;IADC,KAAK,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;;6CACd;AAXL,cAAc;IAD1B,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;;GACH,cAAc,CA4B1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH;;;IAGI;AACJ;;;;KAIK;AAEL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAEH;;;;;;;;;;;;;;;;;;;KAmBK;AAEL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oEAmCoE;AAEpE;;;;;;;;;;;;;;;;;;;;;;IAsBI"}
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import { variant, field, option, vec } from "@dao-xyz/borsh";
|
|
2
|
-
import { TransportMessage } from "./message.js";
|
|
3
|
-
|
|
4
|
-
export const WAIT_FOR_PEERS_TIME = 5000;
|
|
5
|
-
|
|
6
|
-
@variant([2, 0])
|
|
7
|
-
export class ReplicatorInfo extends TransportMessage {
|
|
8
|
-
@field({ type: option("string") })
|
|
9
|
-
fromId?: string;
|
|
10
|
-
|
|
11
|
-
@field({ type: "string" })
|
|
12
|
-
topic: string;
|
|
13
|
-
|
|
14
|
-
@field({ type: "u32" })
|
|
15
|
-
store: number; // address
|
|
16
|
-
|
|
17
|
-
@field({ type: vec("string") })
|
|
18
|
-
heads?: string[]; // address
|
|
19
|
-
|
|
20
|
-
constructor(props?: {
|
|
21
|
-
fromId?: string;
|
|
22
|
-
topic: string;
|
|
23
|
-
store: number;
|
|
24
|
-
heads?: string[];
|
|
25
|
-
}) {
|
|
26
|
-
super();
|
|
27
|
-
if (props) {
|
|
28
|
-
this.fromId = props.fromId;
|
|
29
|
-
this.topic = props.topic;
|
|
30
|
-
this.store = props.store;
|
|
31
|
-
this.heads = props.heads;
|
|
32
|
-
/* this.allowForks = props.allowForks; */
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/* @variant([2, 1])
|
|
38
|
-
export class RequestReplicatorInfo extends ProtocolMessage {
|
|
39
|
-
@field({ type: "string" })
|
|
40
|
-
id: string;
|
|
41
|
-
|
|
42
|
-
@field({ type: "string" })
|
|
43
|
-
topic: string;
|
|
44
|
-
|
|
45
|
-
@field({ type: "string" })
|
|
46
|
-
address: string; // address
|
|
47
|
-
|
|
48
|
-
@field({ type: vec("string") })
|
|
49
|
-
heads: string[];
|
|
50
|
-
|
|
51
|
-
constructor(props?: {
|
|
52
|
-
topic: string;
|
|
53
|
-
address: Address | string;
|
|
54
|
-
heads: string[];
|
|
55
|
-
}) {
|
|
56
|
-
super();
|
|
57
|
-
if (props) {
|
|
58
|
-
this.id = uuid();
|
|
59
|
-
this.topic = props.topic;
|
|
60
|
-
this.address =
|
|
61
|
-
typeof props.address === "string"
|
|
62
|
-
? props.address
|
|
63
|
-
: props.address.toString();
|
|
64
|
-
this.heads = props.heads;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
*/
|
|
69
|
-
/* export interface PeerInfoWithMeta {
|
|
70
|
-
peerInfo: ReplicatorInfo;
|
|
71
|
-
publicKey: PublicSignKey;
|
|
72
|
-
} */
|
|
73
|
-
/* return new PeerInfo({
|
|
74
|
-
key: this._shard.peer.orbitDB.identity,
|
|
75
|
-
addresses: (await this._shard.peer.node.id()).addresses.map(x => x.toString()),
|
|
76
|
-
memoryLeft: v8.getHeapStatistics().total_available_size//v8
|
|
77
|
-
}) */
|
|
78
|
-
|
|
79
|
-
/* export const createEmitHealthCheckJob = (properties: { stores: () => string[] | undefined, subscribingForReplication: (topic: string) => boolean }, replicationTopic: string, publish: (topic: string, message: Uint8Array) => Promise<void>, isOnline: () => boolean, controller: AbortController, sign: (bytes: Uint8Array) => Promise<{ signature: Uint8Array, publicKey: PublicKey }>, encryption: PublicKeyEncryption) => {
|
|
80
|
-
|
|
81
|
-
const emitHealthcheck = async (): Promise<void> => {
|
|
82
|
-
const s = properties.stores();
|
|
83
|
-
if (!s || s.length === 0) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
const signedMessage = await new MaybeSigned({
|
|
87
|
-
data: serialize(new PeerInfo({
|
|
88
|
-
replicationTopic,
|
|
89
|
-
stores: s,
|
|
90
|
-
subscribingForReplication: properties.subscribingForReplication(replicationTopic),
|
|
91
|
-
memoryLeft: v8.getHeapStatistics().total_available_size//v8
|
|
92
|
-
|
|
93
|
-
}))
|
|
94
|
-
}).sign(sign)
|
|
95
|
-
const decryptedMessage = new DecryptedThing({
|
|
96
|
-
data: serialize(signedMessage)
|
|
97
|
-
})// TODO add encryption .init(encryption).encrypt(lala)
|
|
98
|
-
|
|
99
|
-
return publish(replicationTopic, serialize(decryptedMessage))
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const task = async () => {
|
|
103
|
-
await emitHealthcheck();
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const cron = async () => {
|
|
107
|
-
let stop = false;
|
|
108
|
-
let promise: Promise<any> = undefined;
|
|
109
|
-
let delayStopper: () => void | undefined = undefined;
|
|
110
|
-
controller.signal.addEventListener("abort", async () => {
|
|
111
|
-
stop = true;
|
|
112
|
-
if (delayStopper)
|
|
113
|
-
delayStopper();
|
|
114
|
-
await promise;
|
|
115
|
-
});
|
|
116
|
-
while (isOnline() && !stop) { //
|
|
117
|
-
promise = task();
|
|
118
|
-
await promise;
|
|
119
|
-
await delay(EMIT_HEALTHCHECK_INTERVAL, { stopperCallback: (stopper) => { delayStopper = stopper } }); // some delay
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return cron;
|
|
123
|
-
}
|
|
124
|
-
*/
|
|
125
|
-
|
|
126
|
-
/* export const requestPeerInfo = async (
|
|
127
|
-
serializedRequest: Uint8Array,
|
|
128
|
-
replicationTopic: string,
|
|
129
|
-
publish: (topic: string, message: Uint8Array) => Promise<void>,
|
|
130
|
-
identity: Identity
|
|
131
|
-
) => {
|
|
132
|
-
const signedMessage = await new MaybeSigned({
|
|
133
|
-
data: serializedRequest,
|
|
134
|
-
}).sign(async (data) => {
|
|
135
|
-
return {
|
|
136
|
-
publicKey: identity.publicKey,
|
|
137
|
-
signature: await identity.sign(data),
|
|
138
|
-
};
|
|
139
|
-
});
|
|
140
|
-
const decryptedMessage = new DecryptedThing({
|
|
141
|
-
data: serialize(signedMessage),
|
|
142
|
-
}); // TODO add encryption .init(encryption).encrypt(lala)
|
|
143
|
-
|
|
144
|
-
return publish(replicationTopic, serialize(decryptedMessage));
|
|
145
|
-
}; */
|
|
146
|
-
|
|
147
|
-
/* export const exchangePeerInfo = async (
|
|
148
|
-
fromId: string,
|
|
149
|
-
replicationTopic: string,
|
|
150
|
-
store: Store<any>,
|
|
151
|
-
heads: string[] | undefined,
|
|
152
|
-
publish: (message: Uint8Array) => Promise<void>,
|
|
153
|
-
sign: (
|
|
154
|
-
bytes: Uint8Array
|
|
155
|
-
) => Promise<{ signature: Uint8Array; publicKey: PublicSignKey }>
|
|
156
|
-
) => {
|
|
157
|
-
const signedMessage = await new MaybeSigned({
|
|
158
|
-
data: serialize(
|
|
159
|
-
new ReplicatorInfo({
|
|
160
|
-
fromId,
|
|
161
|
-
replicationTopic,
|
|
162
|
-
store: store._storeIndex,
|
|
163
|
-
heads,
|
|
164
|
-
})
|
|
165
|
-
),
|
|
166
|
-
}).sign(sign);
|
|
167
|
-
|
|
168
|
-
const decryptedMessage = new DecryptedThing({
|
|
169
|
-
data: serialize(signedMessage),
|
|
170
|
-
}); // TODO add encryption .init(encryption).encrypt(lala)
|
|
171
|
-
|
|
172
|
-
return publish(serialize(decryptedMessage));
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
export class ResourceRequirement {
|
|
176
|
-
async ok(_orbitdb: Peerbit): Promise<boolean> {
|
|
177
|
-
throw new Error("Not implemented");
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
@variant(0)
|
|
182
|
-
export class NoResourceRequirement extends ResourceRequirement {} */
|
|
183
|
-
|
|
184
|
-
/* @variant(1)
|
|
185
|
-
export class HeapSizeRequirement extends ResourceRequirement {
|
|
186
|
-
|
|
187
|
-
@field({ type: 'u64' })
|
|
188
|
-
heapSize: bigint
|
|
189
|
-
|
|
190
|
-
constructor(properties?: { heapSize: bigint }) {
|
|
191
|
-
super();
|
|
192
|
-
if (properties) {
|
|
193
|
-
this.heapSize = properties.heapSize;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
async ok(orbitdb: OrbitDB): Promise<boolean> {
|
|
198
|
-
if (!v8 || typeof orbitdb.heapsizeLimitForForks !== 'number') {
|
|
199
|
-
return true;
|
|
200
|
-
}
|
|
201
|
-
const usedHeap: number = v8.getHeapStatistics().used_heap_size;
|
|
202
|
-
return BigInt(usedHeap) + this.heapSize < orbitdb.heapsizeLimitForForks;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
} */
|