@ipab/cli 0.1.0-rc.10 → 0.1.0-rc.12
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 +24 -11
- package/dist/authoring.d.ts +7 -0
- package/dist/authoring.d.ts.map +1 -1
- package/dist/authoring.js +85 -5
- package/dist/authoring.js.map +1 -1
- package/dist/builtins/skill.ipab.car +0 -0
- package/dist/builtins/template.bundle-viewer.car +0 -0
- package/dist/builtins/template.check.car +0 -0
- package/dist/builtins/template.node.car +0 -0
- package/dist/builtins/template.web-app.car +0 -0
- package/dist/bundled-skills.d.ts +1 -1
- package/dist/cli.d.ts +2 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +904 -183
- package/dist/cli.js.map +1 -1
- package/dist/config-secret.js +1 -1
- package/dist/config-secret.js.map +1 -1
- package/dist/config.d.ts +4 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +17 -2
- package/dist/config.js.map +1 -1
- package/dist/daemon-ui.d.ts +1 -0
- package/dist/daemon-ui.d.ts.map +1 -1
- package/dist/daemon-ui.js +2 -0
- package/dist/daemon-ui.js.map +1 -1
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +7 -3
- package/dist/doctor.js.map +1 -1
- package/dist/get.d.ts.map +1 -1
- package/dist/get.js +1 -1
- package/dist/get.js.map +1 -1
- package/dist/history.d.ts +3 -1
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +16 -1
- package/dist/history.js.map +1 -1
- package/dist/kubo-topology.d.ts +2 -0
- package/dist/kubo-topology.d.ts.map +1 -1
- package/dist/kubo-topology.js +17 -20
- package/dist/kubo-topology.js.map +1 -1
- package/dist/kubo.d.ts +5 -3
- package/dist/kubo.d.ts.map +1 -1
- package/dist/kubo.js +83 -13
- package/dist/kubo.js.map +1 -1
- package/dist/name-reference.d.ts +8 -0
- package/dist/name-reference.d.ts.map +1 -0
- package/dist/name-reference.js +63 -0
- package/dist/name-reference.js.map +1 -0
- package/dist/pivot-rpc.d.ts +37 -2
- package/dist/pivot-rpc.d.ts.map +1 -1
- package/dist/pivot-rpc.js +188 -8
- package/dist/pivot-rpc.js.map +1 -1
- package/dist/search-index.d.ts.map +1 -1
- package/dist/search-index.js +1 -0
- package/dist/search-index.js.map +1 -1
- package/dist/skill-definition.d.ts +9 -0
- package/dist/skill-definition.d.ts.map +1 -1
- package/dist/skill-definition.js +26 -2
- package/dist/skill-definition.js.map +1 -1
- package/dist/skill-source.d.ts +1 -0
- package/dist/skill-source.d.ts.map +1 -1
- package/dist/skill-source.js +10 -4
- package/dist/skill-source.js.map +1 -1
- package/dist/skills.d.ts +9 -3
- package/dist/skills.d.ts.map +1 -1
- package/dist/skills.js +31 -2
- package/dist/skills.js.map +1 -1
- package/dist/state.d.ts +20 -0
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +87 -3
- package/dist/state.js.map +1 -1
- package/dist/swarm-fs-core.d.ts +217 -0
- package/dist/swarm-fs-core.d.ts.map +1 -0
- package/dist/swarm-fs-core.js +885 -0
- package/dist/swarm-fs-core.js.map +1 -0
- package/dist/swarm-fs-path.d.ts +17 -0
- package/dist/swarm-fs-path.d.ts.map +1 -0
- package/dist/swarm-fs-path.js +46 -0
- package/dist/swarm-fs-path.js.map +1 -0
- package/dist/swarm-fs.d.ts +9 -0
- package/dist/swarm-fs.d.ts.map +1 -0
- package/dist/swarm-fs.js +21 -0
- package/dist/swarm-fs.js.map +1 -0
- package/dist/swarm-observations.d.ts +6 -0
- package/dist/swarm-observations.d.ts.map +1 -1
- package/dist/swarm-observations.js +28 -8
- package/dist/swarm-observations.js.map +1 -1
- package/dist/swarm.d.ts +192 -17
- package/dist/swarm.d.ts.map +1 -1
- package/dist/swarm.js +1360 -442
- package/dist/swarm.js.map +1 -1
- package/dist/unixfs-tree.d.ts +55 -0
- package/dist/unixfs-tree.d.ts.map +1 -1
- package/dist/unixfs-tree.js +361 -2
- package/dist/unixfs-tree.js.map +1 -1
- package/package.json +5 -5
- package/src/authoring.ts +125 -8
- package/src/cli.ts +1215 -281
- package/src/config-secret.ts +1 -1
- package/src/config.ts +20 -2
- package/src/daemon-ui.ts +3 -0
- package/src/doctor.ts +12 -2
- package/src/get.ts +2 -1
- package/src/history.ts +26 -1
- package/src/kubo-topology.ts +25 -22
- package/src/kubo.ts +127 -9
- package/src/name-reference.ts +91 -0
- package/src/pivot-rpc.ts +272 -14
- package/src/search-index.ts +1 -0
- package/src/skill-definition.ts +45 -3
- package/src/skill-source.ts +10 -4
- package/src/skills.ts +43 -2
- package/src/state.ts +117 -2
- package/src/swarm-fs-core.ts +1461 -0
- package/src/swarm-fs-path.ts +68 -0
- package/src/swarm-fs.ts +104 -0
- package/src/swarm-observations.ts +40 -14
- package/src/swarm.ts +1950 -727
- package/src/unixfs-tree.ts +447 -2
package/src/config-secret.ts
CHANGED
package/src/config.ts
CHANGED
|
@@ -33,9 +33,26 @@ export interface ConfigItem {
|
|
|
33
33
|
value: ConfigValue;
|
|
34
34
|
source: Source;
|
|
35
35
|
}
|
|
36
|
+
export const LOCAL_SWARM_ALIAS = "local";
|
|
37
|
+
export const LOCAL_SWARM_URL =
|
|
38
|
+
"https://example.invalid/v1/0000000000000000/0000000000000000";
|
|
39
|
+
|
|
40
|
+
export function isLocalSwarm(value: string): boolean {
|
|
41
|
+
return value === LOCAL_SWARM_URL;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function isReservedLocalHost(value: string): boolean {
|
|
45
|
+
try {
|
|
46
|
+
const host = new URL(value).hostname.toLowerCase();
|
|
47
|
+
return host === "invalid" || host.endsWith(".invalid");
|
|
48
|
+
} catch {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
36
53
|
export const defaults: Record<ConfigKey, ConfigValue> = {
|
|
37
54
|
"daemon.uiPort": 0,
|
|
38
|
-
"swarm.default":
|
|
55
|
+
"swarm.default": LOCAL_SWARM_URL,
|
|
39
56
|
"swarm.listen": "lan",
|
|
40
57
|
"swarm.pivot": false,
|
|
41
58
|
"swarm.cacheTtl": 300,
|
|
@@ -135,7 +152,8 @@ export function parseValue(
|
|
|
135
152
|
if (text && typeof value === "string") {
|
|
136
153
|
if (key === "daemon.uiPort" && value === "default") return defaults[key];
|
|
137
154
|
if (key.startsWith("swarm.") && value === "default")
|
|
138
|
-
return key === "swarm.
|
|
155
|
+
return key === "swarm.default" ||
|
|
156
|
+
key === "swarm.cacheTtl" ||
|
|
139
157
|
key === "swarm.syncInterval" ||
|
|
140
158
|
key === "swarm.forceRefresh" ||
|
|
141
159
|
key === "swarm.pivot" ||
|
package/src/daemon-ui.ts
CHANGED
|
@@ -18,6 +18,7 @@ export interface DaemonSyncSummary {
|
|
|
18
18
|
headCid: string | null;
|
|
19
19
|
stateCid: string | null;
|
|
20
20
|
skills: DaemonSyncSection;
|
|
21
|
+
typeSkills: DaemonSyncSection;
|
|
21
22
|
templates: DaemonSyncSection;
|
|
22
23
|
registry: DaemonSyncSection;
|
|
23
24
|
}
|
|
@@ -97,6 +98,7 @@ export function emptySyncState(): DaemonSyncState {
|
|
|
97
98
|
headCid: null,
|
|
98
99
|
stateCid: null,
|
|
99
100
|
skills: { status: "skipped", count: 0, error: null },
|
|
101
|
+
typeSkills: { status: "skipped", count: 0, error: null },
|
|
100
102
|
templates: { status: "skipped", count: 0, error: null },
|
|
101
103
|
registry: { status: "skipped", count: 0, error: null },
|
|
102
104
|
};
|
|
@@ -639,6 +641,7 @@ tr.clickable:hover td{background:var(--surface-2)}
|
|
|
639
641
|
syncRow.append(
|
|
640
642
|
badge("Sync: " + s.sync.status, s.sync.status === "ok" ? "ok" : s.sync.status === "error" ? "err" : "muted"),
|
|
641
643
|
renderSyncPill("Skills", s.sync.skills),
|
|
644
|
+
renderSyncPill("Type Skills", s.sync.typeSkills),
|
|
642
645
|
renderSyncPill("Templates", s.sync.templates),
|
|
643
646
|
renderSyncPill("Registry", s.sync.registry),
|
|
644
647
|
);
|
package/src/doctor.ts
CHANGED
|
@@ -15,7 +15,10 @@ import { RESOURCE_ID_PATTERN, ScopeClient } from "@ipab/bundle/pointer/scope";
|
|
|
15
15
|
import { nodeError } from "./authoring.js";
|
|
16
16
|
import { accountIdentity, protectedPath, secureNew } from "./identity.js";
|
|
17
17
|
import {
|
|
18
|
+
LOCAL_SWARM_ALIAS,
|
|
18
19
|
effectiveConfig,
|
|
20
|
+
isLocalSwarm,
|
|
21
|
+
isReservedLocalHost,
|
|
19
22
|
swarmUrl,
|
|
20
23
|
validateUserConfig,
|
|
21
24
|
type ConfigKey,
|
|
@@ -684,17 +687,24 @@ async function inspect(
|
|
|
684
687
|
)
|
|
685
688
|
throw new Error("Invalid registry.");
|
|
686
689
|
const url = swarmUrl(row.cid);
|
|
687
|
-
if (
|
|
690
|
+
if (
|
|
691
|
+
url !== row.cid ||
|
|
692
|
+
urls.has(url) ||
|
|
693
|
+
isLocalSwarm(url) ||
|
|
694
|
+
isReservedLocalHost(url)
|
|
695
|
+
)
|
|
688
696
|
throw new Error("Invalid registry.");
|
|
689
697
|
urls.add(url);
|
|
690
698
|
if (row.alias !== null) {
|
|
691
699
|
swarmAlias(row.alias);
|
|
692
|
-
if (aliases.has(row.alias))
|
|
700
|
+
if (row.alias === LOCAL_SWARM_ALIAS || aliases.has(row.alias))
|
|
701
|
+
throw new Error("Duplicate alias.");
|
|
693
702
|
aliases.add(row.alias);
|
|
694
703
|
}
|
|
695
704
|
}
|
|
696
705
|
if (
|
|
697
706
|
typeof user["swarm.default"] === "string" &&
|
|
707
|
+
!isLocalSwarm(user["swarm.default"]) &&
|
|
698
708
|
!urls.has(user["swarm.default"])
|
|
699
709
|
)
|
|
700
710
|
throw new Error("Unregistered default.");
|
package/src/get.ts
CHANGED
|
@@ -65,7 +65,8 @@ export async function getBundle(
|
|
|
65
65
|
"Download destination must not cross a symlink or file.",
|
|
66
66
|
);
|
|
67
67
|
} catch (cause) {
|
|
68
|
-
if (!nodeError(cause, "ENOENT")
|
|
68
|
+
if (!nodeError(cause, "ENOENT") && !nodeError(cause, "ENOTDIR"))
|
|
69
|
+
throw cause;
|
|
69
70
|
}
|
|
70
71
|
if (dirname(current) === current) break;
|
|
71
72
|
}
|
package/src/history.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
IpfsStore,
|
|
3
|
+
type IpfsReadOptions,
|
|
4
|
+
type StagedBlock,
|
|
5
|
+
type StoreConfiguration,
|
|
6
|
+
} from "@ipab/ipfs-store";
|
|
7
|
+
import { CID } from "multiformats/cid";
|
|
2
8
|
import type { SQLInputValue } from "node:sqlite";
|
|
3
9
|
import { HostError, message, syntax } from "./errors.js";
|
|
4
10
|
import type { Hold, RunRecord, State } from "./state.js";
|
|
@@ -208,6 +214,25 @@ export class Ownership {
|
|
|
208
214
|
signal ? { signal } : {},
|
|
209
215
|
);
|
|
210
216
|
}
|
|
217
|
+
async importBlocks(
|
|
218
|
+
session: string,
|
|
219
|
+
blocks: readonly StagedBlock[],
|
|
220
|
+
root: CID | string,
|
|
221
|
+
options: IpfsReadOptions = {},
|
|
222
|
+
): Promise<string> {
|
|
223
|
+
const cid = CID.parse(root.toString()).toV1().toString();
|
|
224
|
+
await this.store.importBlocks(session, blocks, cid, this.owner, {
|
|
225
|
+
...options,
|
|
226
|
+
onRetained: () => {
|
|
227
|
+
const latest = this.state.hold(this.owner)!;
|
|
228
|
+
this.state.saveHold({
|
|
229
|
+
...latest,
|
|
230
|
+
roots: [...new Set([...latest.roots, cid])],
|
|
231
|
+
});
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
return cid;
|
|
235
|
+
}
|
|
211
236
|
async release(): Promise<void> {
|
|
212
237
|
const hold = this.state.hold(this.owner);
|
|
213
238
|
if (!hold) return;
|
package/src/kubo-topology.ts
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
import { object } from "./errors.js";
|
|
2
2
|
import type { PeeringPeer } from "./kubo-peering.js";
|
|
3
3
|
|
|
4
|
+
export function bootstrapAddresses(peers: readonly PeeringPeer[]): string[] {
|
|
5
|
+
return [
|
|
6
|
+
...new Set(
|
|
7
|
+
peers.flatMap(({ ID, Addrs }) =>
|
|
8
|
+
Addrs.map((address) => `${address}/p2p/${ID}`),
|
|
9
|
+
),
|
|
10
|
+
),
|
|
11
|
+
].sort();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function withoutBootstrap(
|
|
15
|
+
config: Record<string, unknown>,
|
|
16
|
+
): Record<string, unknown> {
|
|
17
|
+
const rest = { ...config };
|
|
18
|
+
delete rest.Bootstrap;
|
|
19
|
+
return rest;
|
|
20
|
+
}
|
|
21
|
+
|
|
4
22
|
export function topologyConfig(
|
|
5
23
|
config: Record<string, unknown>,
|
|
6
24
|
pivot: boolean,
|
|
@@ -8,17 +26,10 @@ export function topologyConfig(
|
|
|
8
26
|
loopback: boolean,
|
|
9
27
|
): Record<string, unknown> {
|
|
10
28
|
const swarm = object(config.Swarm, "Kubo Swarm configuration");
|
|
11
|
-
const addresses = peers
|
|
12
|
-
.flatMap(({ ID, Addrs }) => Addrs.map((address) => `${address}/p2p/${ID}`))
|
|
13
|
-
.sort();
|
|
14
29
|
return {
|
|
15
30
|
...config,
|
|
16
|
-
Bootstrap:
|
|
17
|
-
Peering: {
|
|
18
|
-
Peers: pivot
|
|
19
|
-
? peers.map(({ ID, Addrs }) => ({ ID, Addrs: [...Addrs] }))
|
|
20
|
-
: [],
|
|
21
|
-
},
|
|
31
|
+
Bootstrap: bootstrapAddresses(peers),
|
|
32
|
+
Peering: { Peers: [] },
|
|
22
33
|
AutoConf: { Enabled: false },
|
|
23
34
|
AutoTLS: { Enabled: false },
|
|
24
35
|
AutoNAT: { ServiceMode: "disabled" },
|
|
@@ -33,8 +44,7 @@ export function topologyConfig(
|
|
|
33
44
|
},
|
|
34
45
|
Internal: {
|
|
35
46
|
...object(config.Internal ?? {}, "Kubo Internal configuration"),
|
|
36
|
-
// Private swarms cannot use public AutoNAT
|
|
37
|
-
// This is a role declaration, not a verified Internet reachability claim.
|
|
47
|
+
// Private swarms cannot use public AutoNAT; keep static role declaration.
|
|
38
48
|
Libp2pForceReachability: pivot ? "public" : "private",
|
|
39
49
|
NonPublicAddrPublishing: true,
|
|
40
50
|
},
|
|
@@ -45,21 +55,14 @@ export function topologyConfig(
|
|
|
45
55
|
Discovery: { MDNS: { Enabled: false } },
|
|
46
56
|
Swarm: {
|
|
47
57
|
...swarm,
|
|
48
|
-
EnableHolePunching:
|
|
58
|
+
EnableHolePunching: false,
|
|
49
59
|
RelayClient: {
|
|
50
|
-
Enabled:
|
|
51
|
-
|
|
52
|
-
// One entry per ID avoids a three-minute wait for duplicate candidates;
|
|
53
|
-
// Bootstrap supplies the complete address set to the same peerstore.
|
|
54
|
-
StaticRelays: peers
|
|
55
|
-
.flatMap(({ ID, Addrs }) =>
|
|
56
|
-
Addrs[0] ? [`${Addrs[0]}/p2p/${ID}`] : [],
|
|
57
|
-
)
|
|
58
|
-
.sort(),
|
|
60
|
+
Enabled: false,
|
|
61
|
+
StaticRelays: [],
|
|
59
62
|
},
|
|
60
63
|
RelayService: {
|
|
61
64
|
...object(swarm.RelayService ?? {}, "Kubo relay service"),
|
|
62
|
-
Enabled:
|
|
65
|
+
Enabled: false,
|
|
63
66
|
},
|
|
64
67
|
},
|
|
65
68
|
};
|
package/src/kubo.ts
CHANGED
|
@@ -31,7 +31,11 @@ import {
|
|
|
31
31
|
import { HostError, object } from "./errors.js";
|
|
32
32
|
import { nodeError } from "./authoring.js";
|
|
33
33
|
import { peerArguments, type PeeringPeer } from "./kubo-peering.js";
|
|
34
|
-
import {
|
|
34
|
+
import {
|
|
35
|
+
bootstrapAddresses,
|
|
36
|
+
topologyConfig,
|
|
37
|
+
withoutBootstrap,
|
|
38
|
+
} from "./kubo-topology.js";
|
|
35
39
|
|
|
36
40
|
import { kuboBinary, withKuboProgram } from "./kubo-install.js";
|
|
37
41
|
export { kuboBinary };
|
|
@@ -405,9 +409,13 @@ async function rpc(
|
|
|
405
409
|
: AbortSignal.timeout(timeout),
|
|
406
410
|
});
|
|
407
411
|
}
|
|
408
|
-
async function ready(
|
|
412
|
+
async function ready(
|
|
413
|
+
node: KuboNode,
|
|
414
|
+
signal?: AbortSignal,
|
|
415
|
+
fetcher: typeof fetch = fetch,
|
|
416
|
+
): Promise<boolean> {
|
|
409
417
|
try {
|
|
410
|
-
const response = await rpc(node, "id", signal);
|
|
418
|
+
const response = await rpc(node, "id", signal, 5000, fetcher);
|
|
411
419
|
if (response.status === 401 || response.status === 403) {
|
|
412
420
|
await response.body?.cancel();
|
|
413
421
|
throw new HostError(
|
|
@@ -430,6 +438,66 @@ async function ready(node: KuboNode, signal?: AbortSignal): Promise<boolean> {
|
|
|
430
438
|
return false;
|
|
431
439
|
}
|
|
432
440
|
}
|
|
441
|
+
export async function nodeReady(
|
|
442
|
+
node: KuboNode,
|
|
443
|
+
signal?: AbortSignal,
|
|
444
|
+
fetcher: typeof fetch = fetch,
|
|
445
|
+
): Promise<boolean> {
|
|
446
|
+
return ready(node, signal, fetcher);
|
|
447
|
+
}
|
|
448
|
+
function normalizeAddresses(value: unknown): string[] | null {
|
|
449
|
+
if (value === null || value === undefined) return [];
|
|
450
|
+
if (!Array.isArray(value)) return null;
|
|
451
|
+
const items = value as unknown[];
|
|
452
|
+
if (!items.every((item) => typeof item === "string")) return null;
|
|
453
|
+
return [...new Set(items)].sort();
|
|
454
|
+
}
|
|
455
|
+
async function reconcileBootstrap(
|
|
456
|
+
node: KuboNode,
|
|
457
|
+
desired: readonly string[],
|
|
458
|
+
signal?: AbortSignal,
|
|
459
|
+
): Promise<void> {
|
|
460
|
+
const listResponse = await rpc(node, "bootstrap/list", signal, 5_000);
|
|
461
|
+
if (!listResponse.ok) {
|
|
462
|
+
await listResponse.body?.cancel();
|
|
463
|
+
throw new HostError(
|
|
464
|
+
`Owned Kubo bootstrap reconciliation failed (HTTP ${listResponse.status}); retry Swarm activation.`,
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
const listed = object(
|
|
468
|
+
JSON.parse(await boundedText(listResponse)) as unknown,
|
|
469
|
+
"owned Kubo bootstrap response",
|
|
470
|
+
);
|
|
471
|
+
const actual = normalizeAddresses(listed.Peers);
|
|
472
|
+
if (actual === null)
|
|
473
|
+
throw new HostError("Invalid owned Kubo bootstrap response.");
|
|
474
|
+
const actualSet = new Set(actual);
|
|
475
|
+
const desiredSet = new Set(desired);
|
|
476
|
+
const toRemove = actual.filter((address) => !desiredSet.has(address));
|
|
477
|
+
const toAdd = desired.filter((address) => !actualSet.has(address));
|
|
478
|
+
if (toRemove.length) {
|
|
479
|
+
const query = toRemove
|
|
480
|
+
.map((address) => `arg=${encodeURIComponent(address)}`)
|
|
481
|
+
.join("&");
|
|
482
|
+
const response = await rpc(node, `bootstrap/rm?${query}`, signal, 5_000);
|
|
483
|
+
await response.body?.cancel();
|
|
484
|
+
if (!response.ok)
|
|
485
|
+
throw new HostError(
|
|
486
|
+
`Owned Kubo bootstrap reconciliation failed (HTTP ${response.status}); retry Swarm activation.`,
|
|
487
|
+
);
|
|
488
|
+
}
|
|
489
|
+
if (toAdd.length) {
|
|
490
|
+
const query = toAdd
|
|
491
|
+
.map((address) => `arg=${encodeURIComponent(address)}`)
|
|
492
|
+
.join("&");
|
|
493
|
+
const response = await rpc(node, `bootstrap/add?${query}`, signal, 5_000);
|
|
494
|
+
await response.body?.cancel();
|
|
495
|
+
if (!response.ok)
|
|
496
|
+
throw new HostError(
|
|
497
|
+
`Owned Kubo bootstrap reconciliation failed (HTTP ${response.status}); retry Swarm activation.`,
|
|
498
|
+
);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
433
501
|
export async function stopNode(node: KuboNode): Promise<void> {
|
|
434
502
|
if (!(await ready(node))) return;
|
|
435
503
|
await (await rpc(node, "shutdown")).body?.cancel();
|
|
@@ -526,13 +594,29 @@ export async function startNode(
|
|
|
526
594
|
desired,
|
|
527
595
|
listen === "loopback",
|
|
528
596
|
);
|
|
529
|
-
|
|
597
|
+
const staticChanged = !isDeepStrictEqual(
|
|
598
|
+
withoutBootstrap(config),
|
|
599
|
+
withoutBootstrap(nextConfig),
|
|
600
|
+
);
|
|
601
|
+
const desiredBootstrap = bootstrapAddresses(desired);
|
|
602
|
+
const currentBootstrap = normalizeAddresses(config.Bootstrap);
|
|
603
|
+
const bootstrapChanged =
|
|
604
|
+
currentBootstrap === null ||
|
|
605
|
+
!isDeepStrictEqual(currentBootstrap, desiredBootstrap);
|
|
606
|
+
if (staticChanged) {
|
|
530
607
|
await invalidateTopology();
|
|
531
608
|
if (online) {
|
|
532
609
|
await stopNode(node);
|
|
533
610
|
online = false;
|
|
534
611
|
}
|
|
535
612
|
await writePrivate(node.repo, "config", nextConfig);
|
|
613
|
+
} else if (bootstrapChanged) {
|
|
614
|
+
await invalidateTopology();
|
|
615
|
+
if (online) {
|
|
616
|
+
await reconcileBootstrap(node, desiredBootstrap, signal);
|
|
617
|
+
} else {
|
|
618
|
+
await writePrivate(node.repo, "config", nextConfig);
|
|
619
|
+
}
|
|
536
620
|
}
|
|
537
621
|
const keyPath = join(node.repo, "swarm.key");
|
|
538
622
|
if (record.epoch === epoch) {
|
|
@@ -862,8 +946,9 @@ export interface KuboP2pListener {
|
|
|
862
946
|
export async function p2pList(
|
|
863
947
|
node: KuboNode,
|
|
864
948
|
signal?: AbortSignal,
|
|
949
|
+
fetcher: typeof fetch = fetch,
|
|
865
950
|
): Promise<KuboP2pListener[]> {
|
|
866
|
-
const response = await rpc(node, "p2p/ls", signal, 10_000);
|
|
951
|
+
const response = await rpc(node, "p2p/ls", signal, 10_000, fetcher);
|
|
867
952
|
if (!response.ok) {
|
|
868
953
|
await response.body?.cancel();
|
|
869
954
|
throw new HostError(`Owned Kubo p2p/ls failed (HTTP ${response.status}).`);
|
|
@@ -899,6 +984,7 @@ export async function p2pClose(
|
|
|
899
984
|
targetAddress?: string;
|
|
900
985
|
},
|
|
901
986
|
signal?: AbortSignal,
|
|
987
|
+
fetcher: typeof fetch = fetch,
|
|
902
988
|
): Promise<void> {
|
|
903
989
|
const query = new URLSearchParams();
|
|
904
990
|
if (options.protocol !== undefined) query.set("protocol", options.protocol);
|
|
@@ -912,6 +998,7 @@ export async function p2pClose(
|
|
|
912
998
|
qs ? `p2p/close?${qs}` : "p2p/close",
|
|
913
999
|
signal,
|
|
914
1000
|
10_000,
|
|
1001
|
+
fetcher,
|
|
915
1002
|
);
|
|
916
1003
|
if (!response.ok) {
|
|
917
1004
|
await response.body?.cancel();
|
|
@@ -927,23 +1014,30 @@ export async function p2pListen(
|
|
|
927
1014
|
protocol: string,
|
|
928
1015
|
targetAddress: string,
|
|
929
1016
|
signal?: AbortSignal,
|
|
930
|
-
|
|
1017
|
+
fetcher: typeof fetch = fetch,
|
|
1018
|
+
): Promise<boolean> {
|
|
931
1019
|
const selfListen = `/p2p/${node.peerId}`;
|
|
932
|
-
const existing = await p2pList(node, signal);
|
|
1020
|
+
const existing = await p2pList(node, signal, fetcher);
|
|
933
1021
|
const matching = existing.filter(
|
|
934
1022
|
(entry) =>
|
|
935
1023
|
entry.protocol === protocol && entry.listenAddress === selfListen,
|
|
936
1024
|
);
|
|
937
1025
|
if (matching.length === 1 && matching[0]!.targetAddress === targetAddress)
|
|
938
|
-
return;
|
|
1026
|
+
return false;
|
|
939
1027
|
if (matching.length > 0) {
|
|
940
|
-
await p2pClose(
|
|
1028
|
+
await p2pClose(
|
|
1029
|
+
node,
|
|
1030
|
+
{ protocol, listenAddress: selfListen },
|
|
1031
|
+
signal,
|
|
1032
|
+
fetcher,
|
|
1033
|
+
);
|
|
941
1034
|
}
|
|
942
1035
|
const response = await rpc(
|
|
943
1036
|
node,
|
|
944
1037
|
`p2p/listen?arg=${encodeURIComponent(protocol)}&arg=${encodeURIComponent(targetAddress)}`,
|
|
945
1038
|
signal,
|
|
946
1039
|
10_000,
|
|
1040
|
+
fetcher,
|
|
947
1041
|
);
|
|
948
1042
|
if (!response.ok) {
|
|
949
1043
|
const detail = await boundedText(response).catch(() => "");
|
|
@@ -952,6 +1046,7 @@ export async function p2pListen(
|
|
|
952
1046
|
);
|
|
953
1047
|
}
|
|
954
1048
|
await response.body?.cancel();
|
|
1049
|
+
return true;
|
|
955
1050
|
}
|
|
956
1051
|
|
|
957
1052
|
function parseLoopbackMultiaddr(address: string): {
|
|
@@ -1044,6 +1139,29 @@ export async function p2pForward(
|
|
|
1044
1139
|
};
|
|
1045
1140
|
}
|
|
1046
1141
|
|
|
1142
|
+
export async function isRecursivelyPinned(
|
|
1143
|
+
node: KuboNode,
|
|
1144
|
+
cid: string,
|
|
1145
|
+
signal?: AbortSignal,
|
|
1146
|
+
fetcher: typeof fetch = fetch,
|
|
1147
|
+
): Promise<boolean> {
|
|
1148
|
+
const response = await rpc(
|
|
1149
|
+
node,
|
|
1150
|
+
"pin/ls?type=recursive",
|
|
1151
|
+
signal,
|
|
1152
|
+
15_000,
|
|
1153
|
+
fetcher,
|
|
1154
|
+
);
|
|
1155
|
+
if (!response.ok)
|
|
1156
|
+
throw new HostError(`Owned Kubo pin/ls failed (HTTP ${response.status}).`);
|
|
1157
|
+
const data = object(JSON.parse(await boundedText(response)), "Kubo pins");
|
|
1158
|
+
const keys = object(data.Keys, "Kubo pin keys");
|
|
1159
|
+
return (
|
|
1160
|
+
Object.hasOwn(keys, cid) &&
|
|
1161
|
+
object(keys[cid], "Kubo pin").Type === "recursive"
|
|
1162
|
+
);
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1047
1165
|
export async function pinAdd(
|
|
1048
1166
|
node: KuboNode,
|
|
1049
1167
|
cid: string,
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { swarmUrl } from "./config.js";
|
|
2
|
+
import { HostError } from "./host-error.js";
|
|
3
|
+
import { relativePath } from "./space-path.js";
|
|
4
|
+
|
|
5
|
+
export function formalName(name: string): string {
|
|
6
|
+
relativePath(name);
|
|
7
|
+
if (name.length > 256 || name.startsWith("builtin:"))
|
|
8
|
+
throw new HostError("Invalid formal Name.");
|
|
9
|
+
return name;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function decodeNameComponent(
|
|
13
|
+
value: string,
|
|
14
|
+
part: "authority" | "path",
|
|
15
|
+
): string {
|
|
16
|
+
try {
|
|
17
|
+
return decodeURIComponent(value);
|
|
18
|
+
} catch {
|
|
19
|
+
throw new HostError(
|
|
20
|
+
`Malformed percent-encoding in IPAB URI ${part}; use valid UTF-8 escapes or copy the reference from ipab search.`,
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function parseNameReference(
|
|
26
|
+
reference: string,
|
|
27
|
+
): { swarm?: string; name: string } | undefined {
|
|
28
|
+
if (/^name:/i.test(reference))
|
|
29
|
+
throw new HostError("name: is unsupported; use ipab://ALIAS/PATH.");
|
|
30
|
+
if (!/^ipab:/i.test(reference)) return undefined;
|
|
31
|
+
if (/^ipab:\/\/https?:\/\//i.test(reference))
|
|
32
|
+
throw new HostError(
|
|
33
|
+
"Unencoded configuration URL in IPAB URI. Percent-encode the entire configuration URL and each Name path segment separately, or copy the reference from ipab search.",
|
|
34
|
+
);
|
|
35
|
+
const match = /^ipab:\/\/([^/]*)\/(.*)$/is.exec(reference);
|
|
36
|
+
if (!match)
|
|
37
|
+
throw new HostError(
|
|
38
|
+
"Invalid IPAB URI; percent-encode the configuration URL authority and each path segment.",
|
|
39
|
+
);
|
|
40
|
+
const authority = decodeNameComponent(match[1]!, "authority");
|
|
41
|
+
if (authority && !/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(authority)) {
|
|
42
|
+
if (!/^https?:\/\//i.test(authority))
|
|
43
|
+
throw new HostError(
|
|
44
|
+
"Invalid IPAB URI authority; use a registered alias or the percent-encoded configuration URL.",
|
|
45
|
+
);
|
|
46
|
+
swarmUrl(authority);
|
|
47
|
+
}
|
|
48
|
+
if (/[?#\s]/.test(match[2]!))
|
|
49
|
+
throw new HostError(
|
|
50
|
+
"Invalid IPAB URI path; percent-encode each Name path segment. Queries and fragments are not supported.",
|
|
51
|
+
);
|
|
52
|
+
const segments = match[2]!.split("/").map((segment) => {
|
|
53
|
+
const decoded = decodeNameComponent(segment, "path");
|
|
54
|
+
if (/[/\\]/.test(decoded))
|
|
55
|
+
throw new HostError(
|
|
56
|
+
"Invalid IPAB URI path separator; use literal / between Name segments, never an encoded slash or backslash.",
|
|
57
|
+
);
|
|
58
|
+
return decoded;
|
|
59
|
+
});
|
|
60
|
+
try {
|
|
61
|
+
return {
|
|
62
|
+
...(authority ? { swarm: authority } : {}),
|
|
63
|
+
name: match[2] === "" ? "" : formalName(segments.join("/")),
|
|
64
|
+
};
|
|
65
|
+
} catch (error) {
|
|
66
|
+
if (!(error instanceof HostError)) throw error;
|
|
67
|
+
throw new HostError(
|
|
68
|
+
"Invalid IPAB URI path; use a safe relative Name of at most 256 characters without empty, . or .. segments.",
|
|
69
|
+
error.exitCode,
|
|
70
|
+
error.code,
|
|
71
|
+
error.phase,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function formatNameReference(swarm: string, name: string): string {
|
|
77
|
+
const segment = (value: string) =>
|
|
78
|
+
encodeURIComponent(value).replace(
|
|
79
|
+
/[!'()*]/g,
|
|
80
|
+
(char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`,
|
|
81
|
+
);
|
|
82
|
+
return `ipab://${segment(swarm)}/${name.split("/").map(segment).join("/")}`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function templateName(name: string): string {
|
|
86
|
+
if (name.includes(":"))
|
|
87
|
+
throw new HostError(
|
|
88
|
+
"Template NAME must be a safe relative Name, not a URI.",
|
|
89
|
+
);
|
|
90
|
+
return formalName(name);
|
|
91
|
+
}
|