peerbit 5.3.5 → 5.3.7
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/dist/src/bootstrap-recovery.d.ts +79 -0
- package/dist/src/bootstrap-recovery.d.ts.map +1 -0
- package/dist/src/bootstrap-recovery.js +216 -0
- package/dist/src/bootstrap-recovery.js.map +1 -0
- package/dist/src/bootstrap.d.ts +4 -1
- package/dist/src/bootstrap.d.ts.map +1 -1
- package/dist/src/bootstrap.js +201 -7
- package/dist/src/bootstrap.js.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/peer.d.ts +24 -1
- package/dist/src/peer.d.ts.map +1 -1
- package/dist/src/peer.js +116 -5
- package/dist/src/peer.js.map +1 -1
- package/package.json +21 -23
- package/src/bootstrap-recovery.ts +343 -0
- package/src/bootstrap.ts +286 -12
- package/src/index.ts +1 -0
- package/src/peer.ts +154 -5
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { Multiaddr } from "@multiformats/multiaddr";
|
|
2
|
+
/**
|
|
3
|
+
* Automatic bootstrap recovery is opt-in so creating a Peerbit client keeps
|
|
4
|
+
* its existing no-network-side-effect behavior unless an application asks for
|
|
5
|
+
* recovery explicitly.
|
|
6
|
+
*/
|
|
7
|
+
export type BootstrapRecoveryOptions = {
|
|
8
|
+
/** Set to false to leave recovery disabled. Defaults to true for an options object. */
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Fixed bootstrap targets. When omitted, every recovery attempt resolves the
|
|
12
|
+
* current public bootstrap list, including its canonical fallback source.
|
|
13
|
+
*/
|
|
14
|
+
addresses?: Array<string | Multiaddr>;
|
|
15
|
+
/**
|
|
16
|
+
* Delay after the first failed attempt. Defaults to 1 second; maximum is
|
|
17
|
+
* 2,147,483,647 ms.
|
|
18
|
+
*/
|
|
19
|
+
initialDelayMs?: number;
|
|
20
|
+
/**
|
|
21
|
+
* Maximum retry delay, including jitter. Defaults to 60 seconds; maximum is
|
|
22
|
+
* 2,147,483,647 ms.
|
|
23
|
+
*/
|
|
24
|
+
maxDelayMs?: number;
|
|
25
|
+
/** Exponential multiplier applied after each failed attempt. Defaults to 2. */
|
|
26
|
+
backoffFactor?: number;
|
|
27
|
+
/** Symmetric jitter ratio in the inclusive range 0..1. Defaults to 0.2. */
|
|
28
|
+
jitter?: number;
|
|
29
|
+
/**
|
|
30
|
+
* Minimum time between attempts and reconnects. Defaults to 1 second;
|
|
31
|
+
* maximum is 2,147,483,647 ms.
|
|
32
|
+
*/
|
|
33
|
+
cooldownMs?: number;
|
|
34
|
+
};
|
|
35
|
+
export type BootstrapRecoveryEventTarget = {
|
|
36
|
+
addEventListener(type: string, listener: EventListener): void;
|
|
37
|
+
removeEventListener(type: string, listener: EventListener): void;
|
|
38
|
+
};
|
|
39
|
+
export type BootstrapRecoveryRuntime = {
|
|
40
|
+
bootstrap(signal: AbortSignal): Promise<unknown>;
|
|
41
|
+
connectionEvents: BootstrapRecoveryEventTarget;
|
|
42
|
+
onlineEvents?: BootstrapRecoveryEventTarget;
|
|
43
|
+
isConnected(): boolean;
|
|
44
|
+
isOnline?: () => boolean;
|
|
45
|
+
now?: () => number;
|
|
46
|
+
random?: () => number;
|
|
47
|
+
onError?: (error: unknown) => void;
|
|
48
|
+
};
|
|
49
|
+
/** Validate policy configuration before an owning client acquires resources. */
|
|
50
|
+
export declare const validateBootstrapRecoveryOptions: (options: BootstrapRecoveryOptions) => void;
|
|
51
|
+
/** Internal lifecycle controller, exported from its source module for tests. */
|
|
52
|
+
export declare class BootstrapRecoveryController {
|
|
53
|
+
private readonly runtime;
|
|
54
|
+
private readonly options;
|
|
55
|
+
private readonly now;
|
|
56
|
+
private readonly random;
|
|
57
|
+
private running;
|
|
58
|
+
private timer?;
|
|
59
|
+
private timerDueAt?;
|
|
60
|
+
private inFlight?;
|
|
61
|
+
private attemptAbort?;
|
|
62
|
+
private consecutiveFailures;
|
|
63
|
+
private lastAttemptAt;
|
|
64
|
+
private retryNotBefore;
|
|
65
|
+
private readonly onConnectionOpen;
|
|
66
|
+
private readonly onConnectionClose;
|
|
67
|
+
private readonly onOnline;
|
|
68
|
+
constructor(runtime: BootstrapRecoveryRuntime, options?: BootstrapRecoveryOptions);
|
|
69
|
+
get started(): boolean;
|
|
70
|
+
start(): void;
|
|
71
|
+
stop(): Promise<void>;
|
|
72
|
+
private markConnected;
|
|
73
|
+
private requestRecovery;
|
|
74
|
+
private clearTimer;
|
|
75
|
+
private schedule;
|
|
76
|
+
private runAttempt;
|
|
77
|
+
private scheduleRetry;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=bootstrap-recovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrap-recovery.d.ts","sourceRoot":"","sources":["../../src/bootstrap-recovery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEzD;;;;GAIG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACtC,uFAAuF;IACvF,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,SAAS,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACtC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,+EAA+E;IAC/E,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,2EAA2E;IAC3E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAUF,MAAM,MAAM,4BAA4B,GAAG;IAC1C,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI,CAAC;IAC9D,mBAAmB,CAAC,IAAI,EAAE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AE,wBAA6B;IAOvC,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,KAAK,IAAI,IAAI;IAoBb,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAmBrB,OAAO,CAAC,aAAa;IAQrB,OAAO,CAAC,eAAe;IAWvB,OAAO,CAAC,UAAU;IAQlB,OAAO,CAAC,QAAQ;IAqBhB,OAAO,CAAC,UAAU;IAmDlB,OAAO,CAAC,aAAa;CA0BrB"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
const DEFAULT_OPTIONS = {
|
|
2
|
+
initialDelayMs: 1_000,
|
|
3
|
+
maxDelayMs: 60_000,
|
|
4
|
+
backoffFactor: 2,
|
|
5
|
+
jitter: 0.2,
|
|
6
|
+
cooldownMs: 1_000,
|
|
7
|
+
};
|
|
8
|
+
const MAX_TIMER_DELAY_MS = 2_147_483_647;
|
|
9
|
+
const finiteNumber = (name, value, minimum) => {
|
|
10
|
+
if (!Number.isFinite(value) || value < minimum) {
|
|
11
|
+
throw new Error(`${name} must be a finite number >= ${minimum}`);
|
|
12
|
+
}
|
|
13
|
+
return value;
|
|
14
|
+
};
|
|
15
|
+
const timerDelay = (name, value, minimum) => {
|
|
16
|
+
const delay = finiteNumber(name, value, minimum);
|
|
17
|
+
if (delay > MAX_TIMER_DELAY_MS) {
|
|
18
|
+
throw new Error(`${name} must be <= ${MAX_TIMER_DELAY_MS}`);
|
|
19
|
+
}
|
|
20
|
+
return delay;
|
|
21
|
+
};
|
|
22
|
+
const normalizeOptions = (options) => {
|
|
23
|
+
const initialDelayMs = timerDelay("bootstrapRecovery.initialDelayMs", options.initialDelayMs ?? DEFAULT_OPTIONS.initialDelayMs, 1);
|
|
24
|
+
const maxDelayMs = timerDelay("bootstrapRecovery.maxDelayMs", options.maxDelayMs ?? DEFAULT_OPTIONS.maxDelayMs, initialDelayMs);
|
|
25
|
+
const backoffFactor = finiteNumber("bootstrapRecovery.backoffFactor", options.backoffFactor ?? DEFAULT_OPTIONS.backoffFactor, 1);
|
|
26
|
+
const jitter = finiteNumber("bootstrapRecovery.jitter", options.jitter ?? DEFAULT_OPTIONS.jitter, 0);
|
|
27
|
+
if (jitter > 1) {
|
|
28
|
+
throw new Error("bootstrapRecovery.jitter must be <= 1");
|
|
29
|
+
}
|
|
30
|
+
const cooldownMs = timerDelay("bootstrapRecovery.cooldownMs", options.cooldownMs ?? DEFAULT_OPTIONS.cooldownMs, 0);
|
|
31
|
+
return {
|
|
32
|
+
initialDelayMs,
|
|
33
|
+
maxDelayMs,
|
|
34
|
+
backoffFactor,
|
|
35
|
+
jitter,
|
|
36
|
+
cooldownMs,
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
/** Validate policy configuration before an owning client acquires resources. */
|
|
40
|
+
export const validateBootstrapRecoveryOptions = (options) => {
|
|
41
|
+
if (options.addresses?.length === 0) {
|
|
42
|
+
throw new Error("bootstrapRecovery.addresses must not be empty");
|
|
43
|
+
}
|
|
44
|
+
normalizeOptions(options);
|
|
45
|
+
};
|
|
46
|
+
/** Internal lifecycle controller, exported from its source module for tests. */
|
|
47
|
+
export class BootstrapRecoveryController {
|
|
48
|
+
runtime;
|
|
49
|
+
options;
|
|
50
|
+
now;
|
|
51
|
+
random;
|
|
52
|
+
running = false;
|
|
53
|
+
timer;
|
|
54
|
+
timerDueAt;
|
|
55
|
+
inFlight;
|
|
56
|
+
attemptAbort;
|
|
57
|
+
consecutiveFailures = 0;
|
|
58
|
+
lastAttemptAt = Number.NEGATIVE_INFINITY;
|
|
59
|
+
retryNotBefore = Number.NEGATIVE_INFINITY;
|
|
60
|
+
onConnectionOpen = () => {
|
|
61
|
+
// A bootstrap attempt emits this event from inside its own successful dial.
|
|
62
|
+
// Let that attempt finish all Peerbit bootstrap side effects before treating
|
|
63
|
+
// the recovery as complete.
|
|
64
|
+
if (this.inFlight)
|
|
65
|
+
return;
|
|
66
|
+
this.markConnected();
|
|
67
|
+
};
|
|
68
|
+
onConnectionClose = () => {
|
|
69
|
+
this.requestRecovery(false);
|
|
70
|
+
};
|
|
71
|
+
onOnline = () => {
|
|
72
|
+
this.requestRecovery(true);
|
|
73
|
+
};
|
|
74
|
+
constructor(runtime, options = {}) {
|
|
75
|
+
this.runtime = runtime;
|
|
76
|
+
this.options = normalizeOptions(options);
|
|
77
|
+
this.now = runtime.now ?? Date.now;
|
|
78
|
+
this.random = runtime.random ?? Math.random;
|
|
79
|
+
}
|
|
80
|
+
get started() {
|
|
81
|
+
return this.running;
|
|
82
|
+
}
|
|
83
|
+
start() {
|
|
84
|
+
if (this.running)
|
|
85
|
+
return;
|
|
86
|
+
this.running = true;
|
|
87
|
+
this.runtime.connectionEvents.addEventListener("connection:open", this.onConnectionOpen);
|
|
88
|
+
this.runtime.connectionEvents.addEventListener("connection:close", this.onConnectionClose);
|
|
89
|
+
this.runtime.onlineEvents?.addEventListener("online", this.onOnline);
|
|
90
|
+
if (this.runtime.isConnected()) {
|
|
91
|
+
this.markConnected();
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
this.schedule(0, false);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
stop() {
|
|
98
|
+
if (this.running) {
|
|
99
|
+
this.running = false;
|
|
100
|
+
this.runtime.connectionEvents.removeEventListener("connection:open", this.onConnectionOpen);
|
|
101
|
+
this.runtime.connectionEvents.removeEventListener("connection:close", this.onConnectionClose);
|
|
102
|
+
this.runtime.onlineEvents?.removeEventListener("online", this.onOnline);
|
|
103
|
+
this.clearTimer();
|
|
104
|
+
this.attemptAbort?.abort(new Error("Bootstrap recovery stopped"));
|
|
105
|
+
this.attemptAbort = undefined;
|
|
106
|
+
}
|
|
107
|
+
return this.inFlight ?? Promise.resolve();
|
|
108
|
+
}
|
|
109
|
+
markConnected() {
|
|
110
|
+
if (!this.running)
|
|
111
|
+
return;
|
|
112
|
+
this.consecutiveFailures = 0;
|
|
113
|
+
this.retryNotBefore = Number.NEGATIVE_INFINITY;
|
|
114
|
+
this.lastAttemptAt = this.now();
|
|
115
|
+
this.clearTimer();
|
|
116
|
+
}
|
|
117
|
+
requestRecovery(urgent) {
|
|
118
|
+
if (!this.running || this.runtime.isConnected() || this.inFlight)
|
|
119
|
+
return;
|
|
120
|
+
const now = this.now();
|
|
121
|
+
const cooldownRemaining = Math.max(0, this.lastAttemptAt + this.options.cooldownMs - now);
|
|
122
|
+
const retryRemaining = Math.max(0, this.retryNotBefore - now);
|
|
123
|
+
this.schedule(Math.max(cooldownRemaining, retryRemaining), urgent);
|
|
124
|
+
}
|
|
125
|
+
clearTimer() {
|
|
126
|
+
if (this.timer) {
|
|
127
|
+
clearTimeout(this.timer);
|
|
128
|
+
}
|
|
129
|
+
this.timer = undefined;
|
|
130
|
+
this.timerDueAt = undefined;
|
|
131
|
+
}
|
|
132
|
+
schedule(delayMs, replaceIfEarlier) {
|
|
133
|
+
if (!this.running)
|
|
134
|
+
return;
|
|
135
|
+
const delay = Math.max(0, delayMs);
|
|
136
|
+
const dueAt = this.now() + delay;
|
|
137
|
+
if (this.timer) {
|
|
138
|
+
if (!replaceIfEarlier || (this.timerDueAt ?? dueAt) <= dueAt) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
this.clearTimer();
|
|
142
|
+
}
|
|
143
|
+
this.timerDueAt = dueAt;
|
|
144
|
+
this.timer = setTimeout(() => {
|
|
145
|
+
this.timer = undefined;
|
|
146
|
+
this.timerDueAt = undefined;
|
|
147
|
+
this.runAttempt();
|
|
148
|
+
}, delay);
|
|
149
|
+
this.timer.unref?.();
|
|
150
|
+
}
|
|
151
|
+
runAttempt() {
|
|
152
|
+
if (!this.running || this.runtime.isConnected()) {
|
|
153
|
+
if (this.runtime.isConnected())
|
|
154
|
+
this.markConnected();
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (this.runtime.isOnline?.() === false) {
|
|
158
|
+
// Browser online events bring this forward immediately; the bounded timer
|
|
159
|
+
// remains as a safety net for missed or unreliable environment signals.
|
|
160
|
+
this.schedule(this.options.maxDelayMs, false);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const cooldownRemaining = Math.max(0, this.lastAttemptAt + this.options.cooldownMs - this.now());
|
|
164
|
+
if (cooldownRemaining > 0) {
|
|
165
|
+
this.schedule(cooldownRemaining, false);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if (this.inFlight)
|
|
169
|
+
return;
|
|
170
|
+
this.lastAttemptAt = this.now();
|
|
171
|
+
const controller = new AbortController();
|
|
172
|
+
this.attemptAbort = controller;
|
|
173
|
+
const attempt = Promise.resolve().then(async () => {
|
|
174
|
+
await this.runtime.bootstrap(controller.signal);
|
|
175
|
+
});
|
|
176
|
+
const flight = attempt
|
|
177
|
+
.catch((error) => {
|
|
178
|
+
if (this.running && !controller.signal.aborted) {
|
|
179
|
+
this.runtime.onError?.(error);
|
|
180
|
+
}
|
|
181
|
+
})
|
|
182
|
+
.finally(() => {
|
|
183
|
+
if (this.inFlight !== flight)
|
|
184
|
+
return;
|
|
185
|
+
this.inFlight = undefined;
|
|
186
|
+
if (this.attemptAbort === controller) {
|
|
187
|
+
this.attemptAbort = undefined;
|
|
188
|
+
}
|
|
189
|
+
if (!this.running)
|
|
190
|
+
return;
|
|
191
|
+
if (this.runtime.isConnected()) {
|
|
192
|
+
this.markConnected();
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
// A bootstrap call that returns after its connection has already closed is
|
|
196
|
+
// still a recovery failure and must remain on the bounded retry path.
|
|
197
|
+
this.scheduleRetry();
|
|
198
|
+
});
|
|
199
|
+
this.inFlight = flight;
|
|
200
|
+
}
|
|
201
|
+
scheduleRetry() {
|
|
202
|
+
const exponent = Math.min(this.consecutiveFailures, 52);
|
|
203
|
+
const baseDelay = Math.min(this.options.maxDelayMs, this.options.initialDelayMs *
|
|
204
|
+
Math.pow(this.options.backoffFactor, exponent));
|
|
205
|
+
this.consecutiveFailures += 1;
|
|
206
|
+
const random = Math.max(0, Math.min(1, this.random()));
|
|
207
|
+
const jitterMultiplier = 1 + (random * 2 - 1) * this.options.jitter;
|
|
208
|
+
const retryDelay = Math.max(1, Math.min(this.options.maxDelayMs, Math.round(baseDelay * jitterMultiplier)));
|
|
209
|
+
const now = this.now();
|
|
210
|
+
const cooldownRemaining = Math.max(0, this.lastAttemptAt + this.options.cooldownMs - now);
|
|
211
|
+
const delay = Math.max(retryDelay, cooldownRemaining);
|
|
212
|
+
this.retryNotBefore = now + delay;
|
|
213
|
+
this.schedule(delay, false);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
//# sourceMappingURL=bootstrap-recovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrap-recovery.js","sourceRoot":"","sources":["../../src/bootstrap-recovery.ts"],"names":[],"mappings":"AA4DA,MAAM,eAAe,GAAuC;IAC3D,cAAc,EAAE,KAAK;IACrB,UAAU,EAAE,MAAM;IAClB,aAAa,EAAE,CAAC;IAChB,MAAM,EAAE,GAAG;IACX,UAAU,EAAE,KAAK;CACjB,CAAC;AAEF,MAAM,kBAAkB,GAAG,aAAa,CAAC;AAEzC,MAAM,YAAY,GAAG,CAAC,IAAY,EAAE,KAAa,EAAE,OAAe,EAAU,EAAE;IAC7E,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,OAAO,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,+BAA+B,OAAO,EAAE,CAAC,CAAC;IAClE,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,KAAa,EAAE,OAAe,EAAU,EAAE;IAC3E,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IACjD,IAAI,KAAK,GAAG,kBAAkB,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,eAAe,kBAAkB,EAA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,OAAO,CAAC,UAAU,EACvB,IAAI,CAAC,OAAO,CAAC,cAAc;YAC1B,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,QAAQ,CAAC,CAC/C,CAAC;QACF,IAAI,CAAC,mBAAmB,IAAI,CAAC,CAAC;QAC9B,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QACvD,MAAM,gBAAgB,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;QACpE,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAC1B,CAAC,EACD,IAAI,CAAC,GAAG,CACP,IAAI,CAAC,OAAO,CAAC,UAAU,EACvB,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,gBAAgB,CAAC,CACxC,CACD,CAAC;QACF,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,MAAM,iBAAiB,GAAG,IAAI,CAAC,GAAG,CACjC,CAAC,EACD,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,GAAG,GAAG,CAClD,CAAC;QACF,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;QACtD,IAAI,CAAC,cAAc,GAAG,GAAG,GAAG,KAAK,CAAC;QAClC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC;CACD"}
|
package/dist/src/bootstrap.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { type Multiaddr } from "@multiformats/multiaddr";
|
|
2
|
-
export
|
|
2
|
+
export type ResolveBootstrapAddressesOptions = {
|
|
3
|
+
signal?: AbortSignal;
|
|
4
|
+
};
|
|
5
|
+
export declare const resolveBootstrapAddresses: (v?: string, options?: ResolveBootstrapAddressesOptions) => Promise<string[]>;
|
|
3
6
|
export declare const getBootstrapPeerId: (address: string | Multiaddr) => string | undefined;
|
|
4
7
|
//# sourceMappingURL=bootstrap.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAa,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAa,MAAM,yBAAyB,CAAC;AA2PpE,MAAM,MAAM,gCAAgC,GAAG;IAC9C,MAAM,CAAC,EAAE,WAAW,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,yBAAyB,GACrC,IAAG,MAAY,EACf,UAAS,gCAAqC,KAC5C,OAAO,CAAC,MAAM,EAAE,CA0BlB,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC9B,SAAS,MAAM,GAAG,SAAS,KACzB,MAAM,GAAG,SAaX,CAAC"}
|
package/dist/src/bootstrap.js
CHANGED
|
@@ -1,15 +1,209 @@
|
|
|
1
1
|
import { multiaddr } from "@multiformats/multiaddr";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import { Circuit, DNSADDR, TCP, WebRTC, WebSockets, WebSocketsSecure, } from "@multiformats/multiaddr-matcher";
|
|
3
|
+
const BOOTSTRAP_LIST_FETCH_TIMEOUT_MS = 10_000;
|
|
4
|
+
const MAX_BOOTSTRAP_LIST_BYTES = 64 * 1024;
|
|
5
|
+
const MAX_BOOTSTRAP_LIST_LINES = 512;
|
|
6
|
+
const MAX_BOOTSTRAP_ADDRESS_COUNT = 256;
|
|
7
|
+
const hasRemoteEndpoint = (address) => !address
|
|
8
|
+
.getComponents()
|
|
9
|
+
.some((component) => (component.name === "tcp" && component.value === "0") ||
|
|
10
|
+
(component.name === "ip4" && component.value === "0.0.0.0") ||
|
|
11
|
+
(component.name === "ip6" && component.value === "::"));
|
|
12
|
+
const hasDatagramTransport = (address) => address
|
|
13
|
+
.getComponents()
|
|
14
|
+
.some((component) => ["udp", "quic", "quic-v1", "webtransport", "webrtc-direct"].includes(component.name));
|
|
15
|
+
const isWebSocketTarget = (address) => !hasDatagramTransport(address) && WebSockets.exactMatch(address);
|
|
16
|
+
const isSecureWebSocketTarget = (address) => !hasDatagramTransport(address) && WebSocketsSecure.exactMatch(address);
|
|
17
|
+
const hasDefaultDirectPrefix = (address) => !hasDatagramTransport(address) &&
|
|
18
|
+
(DNSADDR.matches(address) ||
|
|
19
|
+
TCP.matches(address) ||
|
|
20
|
+
WebSockets.matches(address) ||
|
|
21
|
+
WebSocketsSecure.matches(address));
|
|
22
|
+
const hasBrowserSafeDirectPrefix = (address) => !hasDatagramTransport(address) &&
|
|
23
|
+
(DNSADDR.matches(address) || WebSocketsSecure.matches(address));
|
|
24
|
+
const hasCircuitPeerIds = (address) => {
|
|
25
|
+
const components = address.getComponents();
|
|
26
|
+
const circuitIndex = components.findIndex((component) => component.name === "p2p-circuit");
|
|
27
|
+
return (circuitIndex >= 0 &&
|
|
28
|
+
components
|
|
29
|
+
.slice(0, circuitIndex)
|
|
30
|
+
.some((component) => component.name === "p2p") &&
|
|
31
|
+
components
|
|
32
|
+
.slice(circuitIndex + 1)
|
|
33
|
+
.some((component) => component.name === "p2p"));
|
|
34
|
+
};
|
|
35
|
+
const classifyBootstrapAddress = (address) => {
|
|
36
|
+
if (!hasRemoteEndpoint(address)) {
|
|
37
|
+
return { supported: false, crossRuntime: false };
|
|
38
|
+
}
|
|
39
|
+
const direct = DNSADDR.exactMatch(address) ||
|
|
40
|
+
TCP.exactMatch(address) ||
|
|
41
|
+
isWebSocketTarget(address) ||
|
|
42
|
+
isSecureWebSocketTarget(address);
|
|
43
|
+
const circuit = hasCircuitPeerIds(address) &&
|
|
44
|
+
Circuit.exactMatch(address) &&
|
|
45
|
+
hasDefaultDirectPrefix(address);
|
|
46
|
+
const webRTC = hasCircuitPeerIds(address) &&
|
|
47
|
+
WebRTC.exactMatch(address) &&
|
|
48
|
+
hasBrowserSafeDirectPrefix(address);
|
|
49
|
+
const crossRuntime = DNSADDR.exactMatch(address) ||
|
|
50
|
+
isSecureWebSocketTarget(address) ||
|
|
51
|
+
(circuit && hasBrowserSafeDirectPrefix(address));
|
|
52
|
+
return { supported: direct || circuit || webRTC, crossRuntime };
|
|
53
|
+
};
|
|
54
|
+
const getBootstrapListSources = (v) => {
|
|
55
|
+
const file = `bootstrap${v ? "-" + encodeURIComponent(v) : ""}.env`;
|
|
56
|
+
return [
|
|
57
|
+
`https://bootstrap.peerbit.org/${file}`,
|
|
58
|
+
`https://raw.githubusercontent.com/dao-xyz/peerbit-bootstrap/master/${file}`,
|
|
59
|
+
];
|
|
60
|
+
};
|
|
61
|
+
const parseBootstrapAddresses = (value) => {
|
|
62
|
+
const lines = value.split(/\r?\n/);
|
|
63
|
+
if (lines.length > MAX_BOOTSTRAP_LIST_LINES) {
|
|
64
|
+
throw new Error(`Bootstrap list has too many lines (${lines.length} > ${MAX_BOOTSTRAP_LIST_LINES})`);
|
|
65
|
+
}
|
|
66
|
+
const addresses = lines
|
|
67
|
+
.map((line) => line.trim())
|
|
68
|
+
.filter((line) => line.length > 0 && !line.startsWith("#"));
|
|
69
|
+
if (addresses.length === 0) {
|
|
70
|
+
throw new Error("Bootstrap list is empty");
|
|
71
|
+
}
|
|
72
|
+
if (addresses.length > MAX_BOOTSTRAP_ADDRESS_COUNT) {
|
|
73
|
+
throw new Error(`Bootstrap list has too many addresses (${addresses.length} > ${MAX_BOOTSTRAP_ADDRESS_COUNT})`);
|
|
74
|
+
}
|
|
75
|
+
const canonicalAddresses = [];
|
|
76
|
+
let hasCrossRuntimeAddress = false;
|
|
77
|
+
for (const address of addresses) {
|
|
78
|
+
let parsed;
|
|
79
|
+
try {
|
|
80
|
+
parsed = multiaddr(address);
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
const classification = classifyBootstrapAddress(parsed);
|
|
86
|
+
if (!classification.supported) {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
hasCrossRuntimeAddress ||= classification.crossRuntime;
|
|
90
|
+
canonicalAddresses.push(parsed.toString());
|
|
91
|
+
}
|
|
92
|
+
if (canonicalAddresses.length === 0) {
|
|
93
|
+
throw new Error("Bootstrap list has no supported dial targets");
|
|
94
|
+
}
|
|
95
|
+
if (!hasCrossRuntimeAddress) {
|
|
96
|
+
throw new Error("Bootstrap list has no browser-safe cross-runtime dial target");
|
|
97
|
+
}
|
|
98
|
+
return [...new Set(canonicalAddresses)];
|
|
99
|
+
};
|
|
100
|
+
const readBootstrapList = async (response) => {
|
|
101
|
+
const declaredLength = response.headers.get("content-length");
|
|
102
|
+
if (declaredLength != null) {
|
|
103
|
+
if (!/^\d+$/.test(declaredLength)) {
|
|
104
|
+
throw new Error(`Invalid bootstrap list Content-Length: ${declaredLength}`);
|
|
105
|
+
}
|
|
106
|
+
const length = Number(declaredLength);
|
|
107
|
+
if (!Number.isSafeInteger(length) || length > MAX_BOOTSTRAP_LIST_BYTES) {
|
|
108
|
+
throw new Error(`Bootstrap list is too large (${declaredLength} > ${MAX_BOOTSTRAP_LIST_BYTES} bytes)`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (!response.body) {
|
|
112
|
+
return "";
|
|
113
|
+
}
|
|
114
|
+
const reader = response.body.getReader();
|
|
115
|
+
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
116
|
+
let bytesRead = 0;
|
|
117
|
+
let value = "";
|
|
118
|
+
let completed = false;
|
|
119
|
+
try {
|
|
120
|
+
while (true) {
|
|
121
|
+
const chunk = await reader.read();
|
|
122
|
+
if (chunk.done) {
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
bytesRead += chunk.value.byteLength;
|
|
126
|
+
if (bytesRead > MAX_BOOTSTRAP_LIST_BYTES) {
|
|
127
|
+
throw new Error(`Bootstrap list is too large (${bytesRead} > ${MAX_BOOTSTRAP_LIST_BYTES} bytes)`);
|
|
128
|
+
}
|
|
129
|
+
value += decoder.decode(chunk.value, { stream: true });
|
|
130
|
+
}
|
|
131
|
+
value += decoder.decode();
|
|
132
|
+
completed = true;
|
|
133
|
+
return value;
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
if (!completed) {
|
|
137
|
+
await reader
|
|
138
|
+
.cancel("Bootstrap list read did not complete")
|
|
139
|
+
.catch(() => { });
|
|
140
|
+
}
|
|
141
|
+
reader.releaseLock();
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
const abortReason = (signal) => signal.reason ?? new Error("Bootstrap address resolution aborted");
|
|
145
|
+
const fetchBootstrapAddresses = async (source, externalSignal) => {
|
|
146
|
+
const controller = new AbortController();
|
|
147
|
+
const onExternalAbort = () => controller.abort(abortReason(externalSignal));
|
|
148
|
+
if (externalSignal?.aborted) {
|
|
149
|
+
onExternalAbort();
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
externalSignal?.addEventListener("abort", onExternalAbort, { once: true });
|
|
153
|
+
}
|
|
154
|
+
const timeout = setTimeout(() => {
|
|
155
|
+
controller.abort(new Error(`Timed out fetching bootstrap list after ${BOOTSTRAP_LIST_FETCH_TIMEOUT_MS} ms`));
|
|
156
|
+
}, BOOTSTRAP_LIST_FETCH_TIMEOUT_MS);
|
|
157
|
+
let response;
|
|
158
|
+
try {
|
|
159
|
+
response = await fetch(source, { signal: controller.signal });
|
|
160
|
+
if (!response.ok) {
|
|
161
|
+
throw new Error(`Bootstrap list returned HTTP ${response.status}${response.statusText ? ` ${response.statusText}` : ""}`);
|
|
162
|
+
}
|
|
163
|
+
return parseBootstrapAddresses(await readBootstrapList(response));
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
if (response?.body && !response.body.locked) {
|
|
167
|
+
await response.body.cancel(error).catch(() => { });
|
|
168
|
+
}
|
|
169
|
+
if (!controller.signal.aborted) {
|
|
170
|
+
controller.abort(error);
|
|
171
|
+
}
|
|
172
|
+
throw error;
|
|
173
|
+
}
|
|
174
|
+
finally {
|
|
175
|
+
clearTimeout(timeout);
|
|
176
|
+
externalSignal?.removeEventListener("abort", onExternalAbort);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
export const resolveBootstrapAddresses = async (v = "5", options = {}) => {
|
|
180
|
+
const failures = [];
|
|
181
|
+
for (const source of getBootstrapListSources(v)) {
|
|
182
|
+
if (options.signal?.aborted) {
|
|
183
|
+
throw abortReason(options.signal);
|
|
184
|
+
}
|
|
185
|
+
try {
|
|
186
|
+
return await fetchBootstrapAddresses(source, options.signal);
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
if (options.signal?.aborted) {
|
|
190
|
+
throw abortReason(options.signal);
|
|
191
|
+
}
|
|
192
|
+
failures.push(new Error(`Failed to load bootstrap addresses from ${source}: ${error instanceof Error ? error.message : String(error)}`));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
throw new AggregateError(failures, `Failed to resolve bootstrap addresses for network version ${v || "default"}`);
|
|
7
196
|
};
|
|
8
197
|
export const getBootstrapPeerId = (address) => {
|
|
9
198
|
try {
|
|
10
199
|
const parsed = typeof address === "string" ? multiaddr(address) : address;
|
|
11
|
-
|
|
12
|
-
|
|
200
|
+
const components = parsed.getComponents();
|
|
201
|
+
for (let index = components.length - 1; index >= 0; index--) {
|
|
202
|
+
if (components[index].name === "p2p") {
|
|
203
|
+
return components[index].value;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return undefined;
|
|
13
207
|
}
|
|
14
208
|
catch {
|
|
15
209
|
return undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,SAAS,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EACN,OAAO,EACP,OAAO,EACP,GAAG,EACH,MAAM,EACN,UAAU,EACV,gBAAgB,GAChB,MAAM,iCAAiC,CAAC;AAEzC,MAAM,+BAA+B,GAAG,MAAM,CAAC;AAC/C,MAAM,wBAAwB,GAAG,EAAE,GAAG,IAAI,CAAC;AAC3C,MAAM,wBAAwB,GAAG,GAAG,CAAC;AACrC,MAAM,2BAA2B,GAAG,GAAG,CAAC;AAExC,MAAM,iBAAiB,GAAG,CAAC,OAAkB,EAAW,EAAE,CACzD,CAAC,OAAO;KACN,aAAa,EAAE;KACf,IAAI,CACJ,CAAC,SAAS,EAAE,EAAE,CACb,CAAC,SAAS,CAAC,IAAI,KAAK,KAAK,IAAI,SAAS,CAAC,KAAK,KAAK,GAAG,CAAC;IACrD,CAAC,SAAS,CAAC,IAAI,KAAK,KAAK,IAAI,SAAS,CAAC,KAAK,KAAK,SAAS,CAAC;IAC3D,CAAC,SAAS,CAAC,IAAI,KAAK,KAAK,IAAI,SAAS,CAAC,KAAK,KAAK,IAAI,CAAC,CACvD,CAAC;AAEJ,MAAM,oBAAoB,GAAG,CAAC,OAAkB,EAAW,EAAE,CAC5D,OAAO;KACL,aAAa,EAAE;KACf,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CACnB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,cAAc,EAAE,eAAe,CAAC,CAAC,QAAQ,CACnE,SAAS,CAAC,IAAI,CACd,CACD,CAAC;AAEJ,MAAM,iBAAiB,GAAG,CAAC,OAAkB,EAAW,EAAE,CACzD,CAA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,GAAG,MAAM,CAAC,aAAa,EAAE,CAAC;QAC1C,KAAK,IAAI,KAAK,GAAG,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;YAC7D,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;gBACtC,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC;YAChC,CAAC;QACF,CAAC;QACD,OAAO,SAAS,CAAC;IAClB,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,SAAS,CAAC;IAClB,CAAC;AACF,CAAC,CAAC"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from "./peer.js";
|
|
2
2
|
export * from "./bootstrap.js";
|
|
3
|
+
export type { BootstrapRecoveryOptions } from "./bootstrap-recovery.js";
|
|
3
4
|
export { createLibp2pExtended, type Libp2pExtendServices, type Libp2pExtended, type Libp2pCreateOptions, type Libp2pCreateOptionsWithServices, } from "./libp2p.js";
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EACN,oBAAoB,EACpB,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,+BAA+B,GACpC,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,YAAY,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACxE,OAAO,EACN,oBAAoB,EACpB,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,+BAA+B,GACpC,MAAM,aAAa,CAAC"}
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAE/B,OAAO,EACN,oBAAoB,GAKpB,MAAM,aAAa,CAAC"}
|
package/dist/src/peer.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { Indices } from "@peerbit/indexer-interface";
|
|
|
6
6
|
import { type Address, type ExtractArgs, type OpenOptions, type Program, type ProgramClient, ProgramHandler } from "@peerbit/program";
|
|
7
7
|
import { FanoutChannel, type FanoutTreeChannelOptions, type FanoutTreeJoinOptions } from "@peerbit/pubsub";
|
|
8
8
|
import type { RustCoreStream } from "@peerbit/stream";
|
|
9
|
+
import { type BootstrapRecoveryOptions } from "./bootstrap-recovery.js";
|
|
9
10
|
import { type Libp2pExtended, type PartialLibp2pCreateOptions } from "./libp2p.js";
|
|
10
11
|
export declare const logger: import("@libp2p/interface").Logger;
|
|
11
12
|
export type OptionalCreateOptions = {
|
|
@@ -124,6 +125,12 @@ export type CreateInstanceOptions = (SimpleLibp2pOptions | Libp2pOptions) & {
|
|
|
124
125
|
indexer?: (directory?: string) => Promise<Indices> | Indices;
|
|
125
126
|
storage?: StorageCreateOptions;
|
|
126
127
|
network?: NativeNetworkCreateOptions;
|
|
128
|
+
/**
|
|
129
|
+
* Opt-in automatic bootstrap recovery. `true` uses bounded defaults; an
|
|
130
|
+
* options object customizes retry policy or fixed targets. It is disabled by
|
|
131
|
+
* default to avoid unexpected network access from `Peerbit.create()`.
|
|
132
|
+
*/
|
|
133
|
+
bootstrapRecovery?: boolean | BootstrapRecoveryOptions;
|
|
127
134
|
} & OptionalCreateOptions;
|
|
128
135
|
export type DialReadiness = "connection" | "services" | "services-and-fanout";
|
|
129
136
|
export type DialOptions = {
|
|
@@ -140,6 +147,10 @@ export type BootstrapResult = {
|
|
|
140
147
|
connectedPeerIds: string[];
|
|
141
148
|
failures: BootstrapFailure[];
|
|
142
149
|
};
|
|
150
|
+
export type BootstrapDialOptions = {
|
|
151
|
+
dialTimeoutMs?: number;
|
|
152
|
+
signal?: AbortSignal;
|
|
153
|
+
};
|
|
143
154
|
export declare class Peerbit implements ProgramClient {
|
|
144
155
|
_libp2p: Libp2pExtended;
|
|
145
156
|
directory?: string;
|
|
@@ -147,6 +158,11 @@ export declare class Peerbit implements ProgramClient {
|
|
|
147
158
|
private _indexer;
|
|
148
159
|
private _libp2pExternal?;
|
|
149
160
|
private _nativeNetwork?;
|
|
161
|
+
private _bootstrapRecoveryOptions?;
|
|
162
|
+
private _bootstrapRecovery?;
|
|
163
|
+
private _bootstrapRecoveryGeneration;
|
|
164
|
+
private _bootstrapRecoveryTransition;
|
|
165
|
+
private _bootstrapRecoveryPaused;
|
|
150
166
|
/**
|
|
151
167
|
* Native shared-log defaults advertised to programs opened on this
|
|
152
168
|
* client; read by `@peerbit/shared-log` (`SharedLogNativeDefaults`).
|
|
@@ -170,9 +186,16 @@ export declare class Peerbit implements ProgramClient {
|
|
|
170
186
|
*/
|
|
171
187
|
dial(address: string | Multiaddr | Multiaddr[] | ProgramClient, options?: DialOptions): Promise<boolean>;
|
|
172
188
|
hangUp(address: PeerId | PublicSignKey | string | Multiaddr): Promise<void>;
|
|
189
|
+
get bootstrapRecoveryEnabled(): boolean;
|
|
190
|
+
/** Enable automatic recovery and schedule an immediate attempt if disconnected. */
|
|
191
|
+
enableBootstrapRecovery(options?: BootstrapRecoveryOptions): void;
|
|
192
|
+
/** Disable recovery, remove environment listeners, and abort its active dial. */
|
|
193
|
+
disableBootstrapRecovery(): void;
|
|
194
|
+
private transitionBootstrapRecovery;
|
|
195
|
+
private startBootstrapRecovery;
|
|
173
196
|
start(): Promise<void>;
|
|
174
197
|
stop(): Promise<void>;
|
|
175
|
-
bootstrap(addresses?: string
|
|
198
|
+
bootstrap(addresses?: Array<string | Multiaddr>, options?: BootstrapDialOptions): Promise<BootstrapResult>;
|
|
176
199
|
/**
|
|
177
200
|
* Default behaviour of a store is only to accept heads that are forks (new roots) with some probability
|
|
178
201
|
* and to replicate heads (and updates) which is requested by another peer
|