From 09fa8a0447c470de0b2bc71843ca619b21d83431 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Thu, 22 Apr 2021 10:39:05 +1000 Subject: [PATCH] Must pass filter.all to connect to ip4 ws peer --- src/lib/waku.ts | 10 ++++++++++ src/types/types.d.ts | 1 + web-chat/src/App.tsx | 16 +++++----------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/lib/waku.ts b/src/lib/waku.ts index 459874a483..7ef89a9123 100644 --- a/src/lib/waku.ts +++ b/src/lib/waku.ts @@ -3,12 +3,15 @@ import Mplex from 'libp2p-mplex'; import { bytes } from 'libp2p-noise/dist/src/@types/basic'; import { Noise } from 'libp2p-noise/dist/src/noise'; import Websockets from 'libp2p-websockets'; +import filters from 'libp2p-websockets/src/filters'; import { Multiaddr } from 'multiaddr'; import PeerId from 'peer-id'; import { RelayCodec, WakuRelay } from './waku_relay'; import { StoreCodec, WakuStore } from './waku_store'; +const transportKey = Websockets.prototype[Symbol.toStringTag]; + export interface CreateOptions { listenAddresses: string[]; staticNoiseKey: bytes | undefined; @@ -70,6 +73,13 @@ export default class Waku { // @ts-ignore: Type needs update pubsub: WakuRelay, }, + config: { + transport: { + [transportKey]: { + filter: filters.all, + }, + }, + }, }); const wakuStore = new WakuStore(libp2p); diff --git a/src/types/types.d.ts b/src/types/types.d.ts index 673adc8b5b..32d9bbda39 100644 --- a/src/types/types.d.ts +++ b/src/types/types.d.ts @@ -14,3 +14,4 @@ declare module 'libp2p-secio' { export = Secio; } declare module 'libp2p-websockets'; +declare module 'libp2p-websockets/src/filters'; diff --git a/web-chat/src/App.tsx b/web-chat/src/App.tsx index 29df21e892..c7e78be74a 100644 --- a/web-chat/src/App.tsx +++ b/web-chat/src/App.tsx @@ -12,15 +12,12 @@ import { WakuContext } from './WakuContext'; export const ChatContentTopic = 'dingpu'; -interface Props { -} - interface State { messages: string[], waku?: Waku } -export default function App () { +export default function App() { let [state, setState] = useState({ messages: [] }); @@ -44,12 +41,9 @@ export default function App () { } }); - try { - await waku.dial('/ip4/127.0.0.1/tcp/7777/ws/p2p/QmUJKveCpfwA4cY1zRybMEt5z64FRtMHLFFQwndWrSfMmf'); - console.log('Remote node dialed'); - } catch (e) { - console.log('Error when dialing peer ', e); - } + waku.libp2p.peerStore.addressBook.add( + PeerId.createFromB58String('QmbEnEniueE2Cetej6UkYAtvHuXuare4fSEeyvm43kdmfq'), + [multiaddr('/ip4/127.0.0.1/tcp/7777/ws')]); } catch (e) { console.log('Issue starting waku ', e); } @@ -61,7 +55,7 @@ export default function App () { .then(() => console.log('Waku init done')) .catch((e) => console.log('Waku init failed ', e)); } - }, [state.waku]); + }); return (