135: Log more around usage of waku store + connect to second node r=D4nte a=D4nte

Resolves #134

Co-authored-by: Franck Royer <franck@status.im>
This commit is contained in:
bors[bot] 2021-05-07 00:42:25 +00:00 committed by GitHub
commit 3f43e8be79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 16 deletions

View File

@ -64,22 +64,27 @@ export default function App() {
{ peerId, protocols }: { peerId: PeerId; protocols: string[] }
) => {
if (protocols.includes(StoreCodec)) {
console.log(
`Retrieving archived messages from ${peerId.toB58String()}`
);
const response = await waku.store.queryHistory(peerId, [
ChatContentTopic,
]);
if (response) {
const messages = response
.map((wakuMsg) => wakuMsg.payload)
.filter((payload) => !!payload)
.map((payload) => WakuChatMessage.decode(payload as Uint8Array))
.map((wakuChatMessage) =>
ChatMessage.fromWakuChatMessage(wakuChatMessage)
);
setArchivedMessages(messages);
console.log(`${peerId.toB58String()}: retrieving archived messages}`);
try {
const response = await waku.store.queryHistory(peerId, [
ChatContentTopic,
]);
console.log(`${peerId.toB58String()}: messages retrieved:`, response);
if (response) {
const messages = response
.map((wakuMsg) => wakuMsg.payload)
.filter((payload) => !!payload)
.map((payload) => WakuChatMessage.decode(payload as Uint8Array))
.map((wakuChatMessage) =>
ChatMessage.fromWakuChatMessage(wakuChatMessage)
);
setArchivedMessages(messages);
}
} catch (e) {
console.log(
`${peerId.toB58String()}: error encountered when retrieving archived messages`,
e
);
}
}
};
@ -158,6 +163,12 @@ async function initWaku(setter: (waku: Waku) => void) {
),
[multiaddr('/dns4/node-01.do-ams3.jdev.misc.statusim.net/tcp/7010/wss')]
);
waku.libp2p.peerStore.addressBook.add(
PeerId.createFromB58String(
'16Uiu2HAmSyrYVycqBCWcHyNVQS6zYQcdQbwyov1CDijboVRsQS37'
),
[multiaddr('/dns4/node-01.do-ams3.jdev.misc.statusim.net/tcp/7009/wss')]
);
} catch (e) {
console.log('Issue starting waku ', e);
}

View File

@ -61,6 +61,7 @@ export class WakuStore {
if (!response.messages || !response.messages.length) {
// No messages left (or stored)
console.log('No messages present in HistoryRPC response');
return messages;
}