@constl/utils-tests 1.6.15 → 2.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/.aegir.js +2 -2
- package/dist/attente.d.ts +8 -30
- package/dist/attente.js +101 -141
- package/dist/attente.js.map +1 -1
- package/dist/config.d.ts +4 -1
- package/dist/config.js +4 -4
- package/dist/config.js.map +1 -1
- package/dist/constellation.d.ts +14 -10
- package/dist/constellation.js +24 -42
- package/dist/constellation.js.map +1 -1
- package/dist/dossiers.d.ts +1 -1
- package/dist/dossiers.js +19 -5
- package/dist/dossiers.js.map +1 -1
- package/dist/h/303/251lia.d.ts +11 -0
- package/dist/h/303/251lia.js +38 -0
- package/dist/h/303/251lia.js.map +1 -0
- package/dist/index.d.ts +8 -8
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/libp2p/config.d.ts +25 -0
- package/dist/{libp2p.js → libp2p/config.js} +47 -56
- package/dist/libp2p/config.js.map +1 -0
- package/dist/libp2p/index.d.ts +3 -0
- package/dist/libp2p/index.js +4 -0
- package/dist/libp2p/index.js.map +1 -0
- package/dist/libp2p/libp2p.d.ts +9 -0
- package/dist/libp2p/libp2p.js +21 -0
- package/dist/libp2p/libp2p.js.map +1 -0
- package/dist/libp2p/utils.d.ts +10 -0
- package/dist/libp2p/utils.js +41 -0
- package/dist/libp2p/utils.js.map +1 -0
- package/dist/orbite.d.ts +7 -21
- package/dist/orbite.js +31 -156
- package/dist/orbite.js.map +1 -1
- package/dist/{scripts/relai.js → relai/bin.js} +12 -17
- package/dist/relai/bin.js.map +1 -0
- package/dist/relai/consts.d.ts +3 -0
- package/dist/relai/consts.js +4 -0
- package/dist/relai/consts.js.map +1 -0
- package/dist/relai/index.d.ts +3 -0
- package/dist/relai/index.js +4 -0
- package/dist/relai/index.js.map +1 -0
- package/dist/relai/relai.d.ts +5 -0
- package/dist/relai/relai.js +29 -0
- package/dist/relai/relai.js.map +1 -0
- package/dist/relai/utils.d.ts +4 -0
- package/dist/relai/utils.js +6 -0
- package/dist/relai/utils.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +5 -0
- package/dist/utils.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +43 -43
- package/renovate.json +10 -4
- package/src/attente.ts +129 -156
- package/src/config.ts +10 -4
- package/src/constellation.ts +38 -58
- package/src/dossiers.ts +18 -6
- package/src/h/303/251lia.ts +61 -0
- package/src/index.ts +24 -8
- package/src/libp2p/config.ts +115 -0
- package/src/libp2p/index.ts +9 -0
- package/src/libp2p/libp2p.ts +41 -0
- package/src/libp2p/utils.ts +59 -0
- package/src/orbite.ts +43 -223
- package/src/{scripts/relai.ts → relai/bin.ts} +11 -17
- package/src/relai/consts.ts +5 -0
- package/src/relai/index.ts +3 -0
- package/src/relai/relai.ts +40 -0
- package/src/relai/utils.ts +14 -0
- package/src/utils.ts +5 -0
- package/src/version.ts +1 -1
- package/dist/libp2p.d.ts +0 -26
- package/dist/libp2p.js.map +0 -1
- package/dist/scripts/relai.js.map +0 -1
- package/dist/sfip.d.ts +0 -13
- package/dist/sfip.js +0 -89
- package/dist/sfip.js.map +0 -1
- package/src/libp2p.ts +0 -112
- package/src/sfip.ts +0 -127
- /package/dist/{scripts/relai.d.ts → relai/bin.d.ts} +0 -0
|
@@ -29,31 +29,26 @@ import { createLibp2p } from "libp2p";
|
|
|
29
29
|
import { noise } from "@chainsafe/libp2p-noise";
|
|
30
30
|
import { circuitRelayServer } from "@libp2p/circuit-relay-v2";
|
|
31
31
|
import { webSockets } from "@libp2p/websockets";
|
|
32
|
-
import * as filters from "@libp2p/websockets/filters";
|
|
33
32
|
import { identify } from "@libp2p/identify";
|
|
34
33
|
import { keys } from "@libp2p/crypto";
|
|
35
34
|
import { fromString as uint8ArrayFromString } from "uint8arrays/from-string";
|
|
36
35
|
import { FaultTolerance } from "@libp2p/interface";
|
|
36
|
+
import { CLEF_PRIVÉE_RELAI, PORT_DÉFAUT_RELAI } from "./consts.js";
|
|
37
37
|
|
|
38
|
-
//
|
|
39
|
-
const privateKeyString =
|
|
40
|
-
"08011240821cb6bc3d4547fcccb513e82e4d718089f8a166b23ffcd4a436754b6b0774cf07447d1693cd10ce11ef950d7517bad6e9472b41a927cd17fc3fb23f8c70cd99";
|
|
41
|
-
// L'identité de pair qui correspond à la clef privée ci-dessus
|
|
42
|
-
// const relayId = '12D3KooWAJjbRkp8FPF5MKgMU53aUTxWkqvDrs4zc1VMbwRwfsbE'
|
|
38
|
+
// produit par: console.log(server.peerId.privateKey.toString('hex'))
|
|
39
|
+
const privateKeyString = process.env.CLEF_PRIVÉE_RELAI || CLEF_PRIVÉE_RELAI;
|
|
43
40
|
|
|
44
|
-
const
|
|
45
|
-
const
|
|
41
|
+
const chiffrée = uint8ArrayFromString(privateKeyString, "hex");
|
|
42
|
+
const clefPrivée = keys.privateKeyFromProtobuf(chiffrée);
|
|
46
43
|
|
|
47
44
|
const relai = await createLibp2p({
|
|
48
|
-
privateKey,
|
|
45
|
+
privateKey: clefPrivée,
|
|
49
46
|
addresses: {
|
|
50
|
-
listen: [
|
|
47
|
+
listen: [
|
|
48
|
+
`/ip4/0.0.0.0/tcp/${process.env.PORT_DÉFAUT_RELAI || PORT_DÉFAUT_RELAI}/ws`,
|
|
49
|
+
],
|
|
51
50
|
},
|
|
52
|
-
transports: [
|
|
53
|
-
webSockets({
|
|
54
|
-
filter: filters.all,
|
|
55
|
-
}),
|
|
56
|
-
],
|
|
51
|
+
transports: [webSockets()],
|
|
57
52
|
transportManager: {
|
|
58
53
|
faultTolerance: FaultTolerance.NO_FATAL,
|
|
59
54
|
},
|
|
@@ -64,7 +59,6 @@ const relai = await createLibp2p({
|
|
|
64
59
|
relay: circuitRelayServer({
|
|
65
60
|
reservations: {
|
|
66
61
|
maxReservations: 5000,
|
|
67
|
-
reservationTtl: 1000,
|
|
68
62
|
defaultDataLimit: BigInt(1024 * 1024 * 1024),
|
|
69
63
|
},
|
|
70
64
|
}),
|
|
@@ -89,4 +83,4 @@ console.log(
|
|
|
89
83
|
"p2p addr: ",
|
|
90
84
|
relai.getMultiaddrs().map((ma) => ma.toString()),
|
|
91
85
|
);
|
|
92
|
-
//
|
|
86
|
+
// génère une adresse prédéterminée : /ip4/127.0.0.1/tcp/54321/ws/p2p/12D3KooWAJjbRkp8FPF5MKgMU53aUTxWkqvDrs4zc1VMbwRwfsbE
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export const PORT_DÉFAUT_RELAI = 54321;
|
|
2
|
+
export const CLEF_PRIVÉE_RELAI =
|
|
3
|
+
"08011240821cb6bc3d4547fcccb513e82e4d718089f8a166b23ffcd4a436754b6b0774cf07447d1693cd10ce11ef950d7517bad6e9472b41a927cd17fc3fb23f8c70cd99";
|
|
4
|
+
export const ID_DÉFAUT_RELAI =
|
|
5
|
+
"12D3KooWAJjbRkp8FPF5MKgMU53aUTxWkqvDrs4zc1VMbwRwfsbE";
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export const obtenirFichierRelai = async (): Promise<string> => {
|
|
2
|
+
const path = await import("path");
|
|
3
|
+
const url = await import("url");
|
|
4
|
+
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
|
|
5
|
+
|
|
6
|
+
const fichierRelai = path.join(__dirname, "./bin.js");
|
|
7
|
+
return fichierRelai;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const lancerRelai = async ({
|
|
11
|
+
portDéfautRelai,
|
|
12
|
+
clefPrivéeRelai,
|
|
13
|
+
}: {
|
|
14
|
+
portDéfautRelai?: string;
|
|
15
|
+
clefPrivéeRelai?: string;
|
|
16
|
+
} = {}) => {
|
|
17
|
+
const { execa } = await import("execa");
|
|
18
|
+
|
|
19
|
+
const fichierRelai = await obtenirFichierRelai();
|
|
20
|
+
|
|
21
|
+
const relai = execa({
|
|
22
|
+
env: {
|
|
23
|
+
...process.env,
|
|
24
|
+
PORT_DÉFAUT_RELAI: portDéfautRelai,
|
|
25
|
+
CLEF_PRIVÉE_RELAI: clefPrivéeRelai,
|
|
26
|
+
},
|
|
27
|
+
})`node ${fichierRelai} &`;
|
|
28
|
+
|
|
29
|
+
relai.catch((e) => {
|
|
30
|
+
// Ignorer l'erreur causée par la termination du processus par notre code
|
|
31
|
+
if (e.signal !== "SIGTERM") throw new Error(e);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
relai.stdout.on("data", (x) => {
|
|
35
|
+
const texte = new TextDecoder().decode(x);
|
|
36
|
+
console.log(texte);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return () => relai.kill();
|
|
40
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ID_DÉFAUT_RELAI, PORT_DÉFAUT_RELAI } from "./consts.js";
|
|
2
|
+
|
|
3
|
+
export const obtenirAdresseRelai = (
|
|
4
|
+
{
|
|
5
|
+
portRelai,
|
|
6
|
+
idRelai,
|
|
7
|
+
}: {
|
|
8
|
+
portRelai: number;
|
|
9
|
+
idRelai: string;
|
|
10
|
+
} = {
|
|
11
|
+
portRelai: PORT_DÉFAUT_RELAI,
|
|
12
|
+
idRelai: ID_DÉFAUT_RELAI,
|
|
13
|
+
},
|
|
14
|
+
) => `/ip4/127.0.0.1/tcp/${portRelai}/ws/p2p/${idRelai}`;
|
package/src/utils.ts
ADDED
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = "
|
|
2
|
+
export const version = "2.0.0";
|
package/dist/libp2p.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Identify } from "@libp2p/identify";
|
|
2
|
-
import { type GossipsubEvents } from "@chainsafe/libp2p-gossipsub";
|
|
3
|
-
import type { PrivateKey, PubSub } from "@libp2p/interface";
|
|
4
|
-
import type { Libp2pOptions } from "libp2p";
|
|
5
|
-
/**
|
|
6
|
-
* A basic Libp2p configuration for Node.js nodes.
|
|
7
|
-
*/
|
|
8
|
-
export declare const DefaultLibp2pOptions: Libp2pOptions<ServicesLibp2pConstlTest>;
|
|
9
|
-
/**
|
|
10
|
-
* A basic Libp2p configuration for browser nodes.
|
|
11
|
-
*/
|
|
12
|
-
export declare const DefaultLibp2pBrowserOptions: Libp2pOptions<ServicesLibp2pConstlTest>;
|
|
13
|
-
interface ComposantesServiceClefPrivée {
|
|
14
|
-
privateKey: PrivateKey;
|
|
15
|
-
}
|
|
16
|
-
export type ServicesLibp2pConstlTest = {
|
|
17
|
-
identify: Identify;
|
|
18
|
-
pubsub: PubSub<GossipsubEvents>;
|
|
19
|
-
obtClefPrivée: ServiceClefPrivée;
|
|
20
|
-
};
|
|
21
|
-
export declare class ServiceClefPrivée {
|
|
22
|
-
privateKey: PrivateKey;
|
|
23
|
-
constructor(components: ComposantesServiceClefPrivée);
|
|
24
|
-
obtenirClef(): PrivateKey;
|
|
25
|
-
}
|
|
26
|
-
export {};
|
package/dist/libp2p.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"libp2p.js","sourceRoot":"","sources":["../src/libp2p.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;EAwBE;AAEF,OAAO,EAAY,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,GAAG,EAAE,MAAM,4BAA4B,CAAC;AACjD,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAwB,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC9E,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAIjE;;GAEG;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AE,CAAC,QAAQ,EAAE,CAAC,CACjD,CAAC;AACF,0HAA0H"}
|
package/dist/sfip.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { sfip } from "@constl/ipa";
|
|
2
|
-
import { DefaultLibp2pServices, type HeliaLibp2p } from "helia";
|
|
3
|
-
import { Libp2p } from "libp2p";
|
|
4
|
-
export declare const créerHéliaTest: ({ dossier, }?: {
|
|
5
|
-
dossier?: string;
|
|
6
|
-
}) => Promise<HeliaLibp2p<Libp2p<sfip.ServicesLibp2p>>>;
|
|
7
|
-
export declare const connecterPairs: <T extends Libp2p = Libp2p<DefaultLibp2pServices>>(sfip1: HeliaLibp2p<T>, sfip2: HeliaLibp2p<T>, options?: {
|
|
8
|
-
filtre: () => boolean;
|
|
9
|
-
}) => Promise<void>;
|
|
10
|
-
export declare const toutesConnectées: (sfips: HeliaLibp2p<Libp2p<sfip.ServicesLibp2p>>[]) => Promise<void>;
|
|
11
|
-
export declare const constObtFichierRelai: () => Promise<string>;
|
|
12
|
-
export declare const lancerRelai: () => Promise<() => boolean>;
|
|
13
|
-
export declare const adresseRelai = "/ip4/127.0.0.1/tcp/54321/ws/p2p/12D3KooWAJjbRkp8FPF5MKgMU53aUTxWkqvDrs4zc1VMbwRwfsbE";
|
package/dist/sfip.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { createHelia } from "helia";
|
|
2
|
-
import { bitswap } from "@helia/block-brokers";
|
|
3
|
-
import { createLibp2p } from "libp2p";
|
|
4
|
-
import { MemoryBlockstore } from "blockstore-core";
|
|
5
|
-
import { LevelBlockstore } from "blockstore-level";
|
|
6
|
-
import { multiaddr } from "@multiformats/multiaddr";
|
|
7
|
-
import { WebRTC } from "@multiformats/multiaddr-matcher";
|
|
8
|
-
import { isBrowser, isElectronRenderer } from "wherearewe";
|
|
9
|
-
import { DefaultLibp2pBrowserOptions, DefaultLibp2pOptions } from "./libp2p.js";
|
|
10
|
-
export const créerHéliaTest = async ({ dossier, } = {}) => {
|
|
11
|
-
const options = isBrowser || isElectronRenderer
|
|
12
|
-
? DefaultLibp2pBrowserOptions
|
|
13
|
-
: DefaultLibp2pOptions;
|
|
14
|
-
const libp2p = (await createLibp2p({
|
|
15
|
-
...options,
|
|
16
|
-
}));
|
|
17
|
-
const blockstore = dossier
|
|
18
|
-
? new LevelBlockstore(`${dossier}/blocks`)
|
|
19
|
-
: new MemoryBlockstore();
|
|
20
|
-
const heliaOptions = {
|
|
21
|
-
blockstore,
|
|
22
|
-
libp2p,
|
|
23
|
-
blockBrokers: [bitswap()],
|
|
24
|
-
};
|
|
25
|
-
return createHelia({ ...heliaOptions });
|
|
26
|
-
};
|
|
27
|
-
const filtreParDéfaut = () => true;
|
|
28
|
-
export const connecterPairs = async (sfip1, sfip2, options = {
|
|
29
|
-
filtre: filtreParDéfaut,
|
|
30
|
-
}) => {
|
|
31
|
-
if (isBrowser || isElectronRenderer) {
|
|
32
|
-
const idRelai = "12D3KooWAJjbRkp8FPF5MKgMU53aUTxWkqvDrs4zc1VMbwRwfsbE";
|
|
33
|
-
await sfip1.libp2p.dial(multiaddr(`/ip4/127.0.0.1/tcp/54321/ws/p2p/${idRelai}`));
|
|
34
|
-
const adresse1 = await new Promise((resolve) => {
|
|
35
|
-
const testConnecté = () => {
|
|
36
|
-
const adresse = sfip1.libp2p
|
|
37
|
-
.getMultiaddrs()
|
|
38
|
-
.filter((ma) => WebRTC.matches(ma))
|
|
39
|
-
.pop();
|
|
40
|
-
if (adresse != null) {
|
|
41
|
-
clearInterval(interval);
|
|
42
|
-
resolve(adresse);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
const interval = setInterval(testConnecté, 100);
|
|
46
|
-
testConnecté();
|
|
47
|
-
});
|
|
48
|
-
await sfip2.libp2p.dial(adresse1);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
await sfip2.libp2p.peerStore.save(sfip1.libp2p.peerId, {
|
|
52
|
-
multiaddrs: sfip1.libp2p.getMultiaddrs().filter(options.filtre),
|
|
53
|
-
});
|
|
54
|
-
await sfip2.libp2p.dial(sfip1.libp2p.peerId);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
export const toutesConnectées = async (sfips) => {
|
|
58
|
-
const connectés = [];
|
|
59
|
-
for (const sfip of sfips) {
|
|
60
|
-
for (const autre of connectés) {
|
|
61
|
-
await connecterPairs(sfip, autre);
|
|
62
|
-
}
|
|
63
|
-
connectés.push(sfip);
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
export const constObtFichierRelai = async () => {
|
|
67
|
-
const path = await import("path");
|
|
68
|
-
const url = await import("url");
|
|
69
|
-
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
|
|
70
|
-
const fichierRelai = path.join(__dirname, "./scripts/relai.js");
|
|
71
|
-
return fichierRelai;
|
|
72
|
-
};
|
|
73
|
-
export const lancerRelai = async () => {
|
|
74
|
-
const { $ } = await import("execa");
|
|
75
|
-
const fichierRelai = await constObtFichierRelai();
|
|
76
|
-
const relai = $ `node ${fichierRelai} &`;
|
|
77
|
-
relai.catch((e) => {
|
|
78
|
-
// Ignorer l'erreur causée par la termination du processus par notre code
|
|
79
|
-
if (e.signal !== "SIGTERM")
|
|
80
|
-
throw new Error(e);
|
|
81
|
-
});
|
|
82
|
-
relai.stdout.on("data", (x) => {
|
|
83
|
-
const texte = new TextDecoder().decode(x);
|
|
84
|
-
console.log(texte);
|
|
85
|
-
});
|
|
86
|
-
return () => relai.kill();
|
|
87
|
-
};
|
|
88
|
-
export const adresseRelai = "/ip4/127.0.0.1/tcp/54321/ws/p2p/12D3KooWAJjbRkp8FPF5MKgMU53aUTxWkqvDrs4zc1VMbwRwfsbE";
|
|
89
|
-
//# sourceMappingURL=sfip.js.map
|
package/dist/sfip.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sfip.js","sourceRoot":"","sources":["../src/sfip.ts"],"names":[],"mappings":"AAGA,OAAO,EA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K,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAC1C,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC,CAAC,CAAC;IAEH,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;AAC5B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GACvB,sFAAsF,CAAC"}
|
package/src/libp2p.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Certaines parties de ce fichier proviennent de @orbitdb/quickstart
|
|
3
|
-
|
|
4
|
-
MIT License
|
|
5
|
-
|
|
6
|
-
Copyright (c) 2024 OrbitDB Community
|
|
7
|
-
|
|
8
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
-
in the Software without restriction, including without limitation the rights
|
|
11
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
-
furnished to do so, subject to the following conditions:
|
|
14
|
-
|
|
15
|
-
The above copyright notice and this permission notice shall be included in all
|
|
16
|
-
copies or substantial portions of the Software.
|
|
17
|
-
|
|
18
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
-
SOFTWARE.
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
import { Identify, identify } from "@libp2p/identify";
|
|
28
|
-
import { webSockets } from "@libp2p/websockets";
|
|
29
|
-
import { webRTC } from "@libp2p/webrtc";
|
|
30
|
-
import { all } from "@libp2p/websockets/filters";
|
|
31
|
-
import { noise } from "@chainsafe/libp2p-noise";
|
|
32
|
-
import { yamux } from "@chainsafe/libp2p-yamux";
|
|
33
|
-
import { type GossipsubEvents, gossipsub } from "@chainsafe/libp2p-gossipsub";
|
|
34
|
-
import { circuitRelayTransport } from "@libp2p/circuit-relay-v2";
|
|
35
|
-
import type { PrivateKey, PubSub } from "@libp2p/interface";
|
|
36
|
-
import type { Libp2pOptions } from "libp2p";
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* A basic Libp2p configuration for Node.js nodes.
|
|
40
|
-
*/
|
|
41
|
-
export const DefaultLibp2pOptions: Libp2pOptions<ServicesLibp2pConstlTest> = {
|
|
42
|
-
addresses: {
|
|
43
|
-
listen: ["/ip4/0.0.0.0/tcp/0/ws", "/p2p-circuit"],
|
|
44
|
-
},
|
|
45
|
-
transports: [
|
|
46
|
-
webSockets({
|
|
47
|
-
filter: all,
|
|
48
|
-
}),
|
|
49
|
-
webRTC(),
|
|
50
|
-
circuitRelayTransport(),
|
|
51
|
-
],
|
|
52
|
-
connectionEncrypters: [noise()],
|
|
53
|
-
streamMuxers: [yamux()],
|
|
54
|
-
connectionGater: {
|
|
55
|
-
denyDialMultiaddr: () => false,
|
|
56
|
-
},
|
|
57
|
-
services: {
|
|
58
|
-
identify: identify(),
|
|
59
|
-
pubsub: gossipsub({ allowPublishToZeroTopicPeers: true }),
|
|
60
|
-
obtClefPrivée: (components: ComposantesServiceClefPrivée) =>
|
|
61
|
-
new ServiceClefPrivée(components),
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* A basic Libp2p configuration for browser nodes.
|
|
67
|
-
*/
|
|
68
|
-
export const DefaultLibp2pBrowserOptions: Libp2pOptions<ServicesLibp2pConstlTest> =
|
|
69
|
-
{
|
|
70
|
-
addresses: {
|
|
71
|
-
listen: ["/webrtc", "/p2p-circuit"],
|
|
72
|
-
},
|
|
73
|
-
transports: [
|
|
74
|
-
webSockets({
|
|
75
|
-
filter: all,
|
|
76
|
-
}),
|
|
77
|
-
webRTC(),
|
|
78
|
-
circuitRelayTransport(),
|
|
79
|
-
],
|
|
80
|
-
connectionEncrypters: [noise()],
|
|
81
|
-
streamMuxers: [yamux()],
|
|
82
|
-
connectionGater: {
|
|
83
|
-
denyDialMultiaddr: () => false,
|
|
84
|
-
},
|
|
85
|
-
services: {
|
|
86
|
-
identify: identify(),
|
|
87
|
-
pubsub: gossipsub({ allowPublishToZeroTopicPeers: true }),
|
|
88
|
-
obtClefPrivée: (components: ComposantesServiceClefPrivée) =>
|
|
89
|
-
new ServiceClefPrivée(components),
|
|
90
|
-
},
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
interface ComposantesServiceClefPrivée {
|
|
94
|
-
privateKey: PrivateKey;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export type ServicesLibp2pConstlTest = {
|
|
98
|
-
identify: Identify;
|
|
99
|
-
pubsub: PubSub<GossipsubEvents>;
|
|
100
|
-
obtClefPrivée: ServiceClefPrivée;
|
|
101
|
-
};
|
|
102
|
-
export class ServiceClefPrivée {
|
|
103
|
-
privateKey: PrivateKey;
|
|
104
|
-
|
|
105
|
-
constructor(components: ComposantesServiceClefPrivée) {
|
|
106
|
-
this.privateKey = components.privateKey;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
obtenirClef(): PrivateKey {
|
|
110
|
-
return this.privateKey;
|
|
111
|
-
}
|
|
112
|
-
}
|
package/src/sfip.ts
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import type { Multiaddr } from "@multiformats/multiaddr";
|
|
2
|
-
import type { sfip } from "@constl/ipa";
|
|
3
|
-
|
|
4
|
-
import { DefaultLibp2pServices, createHelia, type HeliaLibp2p } from "helia";
|
|
5
|
-
import { bitswap } from "@helia/block-brokers";
|
|
6
|
-
import { createLibp2p, Libp2p } from "libp2p";
|
|
7
|
-
import { MemoryBlockstore } from "blockstore-core";
|
|
8
|
-
import { LevelBlockstore } from "blockstore-level";
|
|
9
|
-
import { multiaddr } from "@multiformats/multiaddr";
|
|
10
|
-
import { WebRTC } from "@multiformats/multiaddr-matcher";
|
|
11
|
-
import {} from "@libp2p/interface";
|
|
12
|
-
|
|
13
|
-
import { isBrowser, isElectronRenderer } from "wherearewe";
|
|
14
|
-
|
|
15
|
-
import { DefaultLibp2pBrowserOptions, DefaultLibp2pOptions } from "./libp2p.js";
|
|
16
|
-
|
|
17
|
-
export const créerHéliaTest = async ({
|
|
18
|
-
dossier,
|
|
19
|
-
}: {
|
|
20
|
-
dossier?: string;
|
|
21
|
-
} = {}): Promise<HeliaLibp2p<Libp2p<sfip.ServicesLibp2p>>> => {
|
|
22
|
-
const options =
|
|
23
|
-
isBrowser || isElectronRenderer
|
|
24
|
-
? DefaultLibp2pBrowserOptions
|
|
25
|
-
: DefaultLibp2pOptions;
|
|
26
|
-
|
|
27
|
-
const libp2p = (await createLibp2p({
|
|
28
|
-
...options,
|
|
29
|
-
})) as unknown as Libp2p<sfip.ServicesLibp2p>;
|
|
30
|
-
|
|
31
|
-
const blockstore = dossier
|
|
32
|
-
? new LevelBlockstore(`${dossier}/blocks`)
|
|
33
|
-
: new MemoryBlockstore();
|
|
34
|
-
|
|
35
|
-
const heliaOptions = {
|
|
36
|
-
blockstore,
|
|
37
|
-
libp2p,
|
|
38
|
-
blockBrokers: [bitswap()],
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
return createHelia({ ...heliaOptions });
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const filtreParDéfaut = () => true;
|
|
45
|
-
|
|
46
|
-
export const connecterPairs = async <
|
|
47
|
-
T extends Libp2p = Libp2p<DefaultLibp2pServices>,
|
|
48
|
-
>(
|
|
49
|
-
sfip1: HeliaLibp2p<T>,
|
|
50
|
-
sfip2: HeliaLibp2p<T>,
|
|
51
|
-
options = {
|
|
52
|
-
filtre: filtreParDéfaut,
|
|
53
|
-
},
|
|
54
|
-
) => {
|
|
55
|
-
if (isBrowser || isElectronRenderer) {
|
|
56
|
-
const idRelai = "12D3KooWAJjbRkp8FPF5MKgMU53aUTxWkqvDrs4zc1VMbwRwfsbE";
|
|
57
|
-
|
|
58
|
-
await sfip1.libp2p.dial(
|
|
59
|
-
multiaddr(`/ip4/127.0.0.1/tcp/54321/ws/p2p/${idRelai}`),
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
const adresse1 = await new Promise<Multiaddr>((resolve) => {
|
|
63
|
-
const testConnecté = () => {
|
|
64
|
-
const adresse = sfip1.libp2p
|
|
65
|
-
.getMultiaddrs()
|
|
66
|
-
.filter((ma) => WebRTC.matches(ma))
|
|
67
|
-
.pop();
|
|
68
|
-
if (adresse != null) {
|
|
69
|
-
clearInterval(interval);
|
|
70
|
-
resolve(adresse);
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
const interval = setInterval(testConnecté, 100);
|
|
74
|
-
testConnecté();
|
|
75
|
-
});
|
|
76
|
-
await sfip2.libp2p.dial(adresse1);
|
|
77
|
-
} else {
|
|
78
|
-
await sfip2.libp2p.peerStore.save(sfip1.libp2p.peerId, {
|
|
79
|
-
multiaddrs: sfip1.libp2p.getMultiaddrs().filter(options.filtre),
|
|
80
|
-
});
|
|
81
|
-
await sfip2.libp2p.dial(sfip1.libp2p.peerId);
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
export const toutesConnectées = async (
|
|
86
|
-
sfips: HeliaLibp2p<Libp2p<sfip.ServicesLibp2p>>[],
|
|
87
|
-
) => {
|
|
88
|
-
const connectés: HeliaLibp2p<Libp2p<sfip.ServicesLibp2p>>[] = [];
|
|
89
|
-
for (const sfip of sfips) {
|
|
90
|
-
for (const autre of connectés) {
|
|
91
|
-
await connecterPairs(sfip, autre);
|
|
92
|
-
}
|
|
93
|
-
connectés.push(sfip);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
export const constObtFichierRelai = async (): Promise<string> => {
|
|
98
|
-
const path = await import("path");
|
|
99
|
-
const url = await import("url");
|
|
100
|
-
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
|
|
101
|
-
|
|
102
|
-
const fichierRelai = path.join(__dirname, "./scripts/relai.js");
|
|
103
|
-
return fichierRelai;
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
export const lancerRelai = async () => {
|
|
107
|
-
const { $ } = await import("execa");
|
|
108
|
-
|
|
109
|
-
const fichierRelai = await constObtFichierRelai();
|
|
110
|
-
|
|
111
|
-
const relai = $`node ${fichierRelai} &`;
|
|
112
|
-
|
|
113
|
-
relai.catch((e) => {
|
|
114
|
-
// Ignorer l'erreur causée par la termination du processus par notre code
|
|
115
|
-
if (e.signal !== "SIGTERM") throw new Error(e);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
relai.stdout.on("data", (x) => {
|
|
119
|
-
const texte = new TextDecoder().decode(x);
|
|
120
|
-
console.log(texte);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
return () => relai.kill();
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
export const adresseRelai =
|
|
127
|
-
"/ip4/127.0.0.1/tcp/54321/ws/p2p/12D3KooWAJjbRkp8FPF5MKgMU53aUTxWkqvDrs4zc1VMbwRwfsbE";
|
|
File without changes
|