Can receive message over internet

This commit is contained in:
Franck Royer 2021-03-26 12:10:26 +11:00
parent 2b450cf2dd
commit d2f1995f3e
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
2 changed files with 28 additions and 10 deletions

View File

@ -3,18 +3,11 @@ import { TOPIC } from '../build/main/lib/waku_relay';
import { Message } from '../build/main/lib/waku_message';
import readline from 'readline';
import { delay } from '../build/main/test_utils/delay';
;(async function() {
const waku = await Waku.create();
console.log('Waku started');
await waku.dial('/ip4/134.209.139.210/tcp/30303/p2p/16Uiu2HAmPLe7Mzm8TsYUubgCAW1aJoeFScxrLj8ppHFivPo97bUZ');
// await waku.dial('/ip4/134.209.113.86/tcp/9000/p2p/16Uiu2HAmVVi6Q4j7MAKVibquW8aA27UNrA4Q8Wkz9EetGViu8ZF1');
console.log('Static node has been dialed');
// TODO: Automatically subscribe
await waku.relay.subscribe();
console.log('Subscribed to waku relay');
// TODO: Bubble event to waku, infere topic, decode msg
waku.libp2p.pubsub.on(TOPIC, event => {
@ -22,6 +15,31 @@ import readline from 'readline';
console.log(msg.utf8Payload());
});
console.log('Waku started');
// Status static node
await waku.dial('/ip4/134.209.139.210/tcp/30303/p2p/16Uiu2HAmPLe7Mzm8TsYUubgCAW1aJoeFScxrLj8ppHFivPo97bUZ');
// Richard's node
// await waku.dial('/ip4/134.209.113.86/tcp/9000/p2p/16Uiu2HAmVVi6Q4j7MAKVibquW8aA27UNrA4Q8Wkz9EetGViu8ZF1');
// await waku.dial('/ip4/0.0.0.0/tcp/60000/p2p/16Uiu2HAmDVYacyxN4t1SYBhRSTDr6nmYwuY6qWWTgagZm558rFA6')
await delay(100);
console.log('Static node has been dialed');
await new Promise((resolve) =>
waku.libp2p.pubsub.once('gossipsub:heartbeat', resolve)
);
// TODO: Automatically subscribe
await waku.relay.subscribe();
console.log('Subscribed to waku relay');
await new Promise((resolve) =>
waku.libp2p.pubsub.once('gossipsub:heartbeat', resolve)
);
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
@ -31,7 +49,7 @@ import readline from 'readline';
rl.prompt();
rl.on('line', async (line) => {
rl.prompt();
const msg = Message.fromUtf8String(line);
const msg = Message.fromUtf8String('(js-chat) ' + line);
await waku.relay.publish(msg);
});

View File

@ -20,7 +20,7 @@ export default class Waku {
static async create(staticNoiseKey?: bytes): Promise<Waku> {
const libp2p = await Libp2p.create({
addresses: {
listen: ['/ip4/0.0.0.0/tcp/0'],
listen: ['/ip4/0.0.0.0/tcp/55123'],
},
modules: {
transport: [TCP],