Enable dialing several nodes

This commit is contained in:
Franck Royer 2021-05-14 10:58:33 +10:00
parent 35fcb4d880
commit c6ce32dc54
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
1 changed files with 9 additions and 9 deletions

View File

@ -49,10 +49,12 @@ export default async function startChat(): Promise<void> {
[ChatContentTopic] [ChatContentTopic]
); );
if (opts.staticNode) { await Promise.all(
console.log(`Dialing ${opts.staticNode}`); opts.staticNodes.map((addr) => {
await waku.dial(opts.staticNode); console.log(`Dialing ${addr}`);
} return waku.dial(addr);
})
);
// If we connect to a peer with WakuStore, we run the protocol // If we connect to a peer with WakuStore, we run the protocol
// TODO: Instead of doing it `once` it should always be done but // TODO: Instead of doing it `once` it should always be done but
@ -89,22 +91,20 @@ export default async function startChat(): Promise<void> {
} }
interface Options { interface Options {
staticNode?: Multiaddr; staticNodes: Multiaddr[];
listenAddr: string; listenAddr: string;
} }
function processArguments(): Options { function processArguments(): Options {
const passedArgs = process.argv.slice(2); const passedArgs = process.argv.slice(2);
let opts: Options = { listenAddr: '/ip4/0.0.0.0/tcp/0' }; let opts: Options = { listenAddr: '/ip4/0.0.0.0/tcp/0', staticNodes: [] };
while (passedArgs.length) { while (passedArgs.length) {
const arg = passedArgs.shift(); const arg = passedArgs.shift();
switch (arg) { switch (arg) {
case '--staticNode': case '--staticNode':
opts = Object.assign(opts, { opts.staticNodes.push(multiaddr(passedArgs.shift()!));
staticNode: multiaddr(passedArgs.shift()!),
});
break; break;
case '--listenAddr': case '--listenAddr':
opts = Object.assign(opts, { listenAddr: passedArgs.shift() }); opts = Object.assign(opts, { listenAddr: passedArgs.shift() });