chore: use filter as IReceiver for noise (#239)
* update noise examples * use latest waku
This commit is contained in:
parent
d7bb3016ff
commit
cb8fbe854b
|
@ -1,7 +1,6 @@
|
|||
import { createLightNode } from "@waku/create";
|
||||
import * as utils from "@waku/utils/bytes";
|
||||
import { waitForRemotePeer } from "@waku/core";
|
||||
import { Protocols } from "@waku/interfaces";
|
||||
import * as noise from "@waku/noise";
|
||||
import protobuf from "protobufjs";
|
||||
import QRCode from "qrcode";
|
||||
|
@ -25,17 +24,16 @@ async function main() {
|
|||
|
||||
try {
|
||||
await node.start();
|
||||
await waitForRemotePeer(node, [Protocols.Filter, Protocols.LightPush]);
|
||||
await waitForRemotePeer(node, ["filter", "lightpush"]);
|
||||
|
||||
ui.waku.connected();
|
||||
|
||||
const responder = getResponder(node);
|
||||
const myStaticKey = noise.generateX25519KeyPair();
|
||||
const urlPairingInfo = getPairingInfoFromURL();
|
||||
|
||||
const pairingObj = new noise.WakuPairing(
|
||||
node.lightPush,
|
||||
responder,
|
||||
node.filter,
|
||||
myStaticKey,
|
||||
urlPairingInfo || new noise.ResponderParameters()
|
||||
);
|
||||
|
@ -117,59 +115,6 @@ function getPairingInfoFromURL() {
|
|||
);
|
||||
}
|
||||
|
||||
function getResponder(node) {
|
||||
const msgQueue = new Array();
|
||||
const subscriptions = new Map();
|
||||
const intervals = new Map();
|
||||
|
||||
const responder = {
|
||||
async subscribe(decoder) {
|
||||
const subscription = await node.filter.subscribe(
|
||||
[decoder],
|
||||
(wakuMessage) => {
|
||||
msgQueue.push(wakuMessage);
|
||||
}
|
||||
);
|
||||
subscriptions.set(decoder.contentTopic, subscription);
|
||||
},
|
||||
async nextMessage(contentTopic) {
|
||||
if (msgQueue.length != 0) {
|
||||
const oldestMsg = msgQueue.shift();
|
||||
if (oldestMsg.contentTopic === contentTopic) {
|
||||
return oldestMsg;
|
||||
}
|
||||
}
|
||||
|
||||
return new Promise((resolve) => {
|
||||
const interval = setInterval(() => {
|
||||
if (msgQueue.length != 0) {
|
||||
clearInterval(interval);
|
||||
const oldestMsg = msgQueue.shift();
|
||||
if (oldestMsg.contentTopic === contentTopic) {
|
||||
resolve(oldestMsg);
|
||||
}
|
||||
}
|
||||
}, 100);
|
||||
intervals.set(contentTopic, interval);
|
||||
});
|
||||
},
|
||||
async stop(contentTopic) {
|
||||
if (intervals.has(contentTopic)) {
|
||||
clearInterval(intervals.get(contentTopic));
|
||||
intervals.delete(contentTopic);
|
||||
}
|
||||
if (subscriptions.has(contentTopic)) {
|
||||
await subscriptions.get(contentTopic)();
|
||||
subscriptions.delete(contentTopic);
|
||||
} else {
|
||||
console.log("Subscriptipon doesnt exist");
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
return responder;
|
||||
}
|
||||
|
||||
async function scheduleHandshakeAuthConfirmation(pairingObj, ui) {
|
||||
const authCode = await pairingObj.getAuthCode();
|
||||
ui.handshake.connecting();
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -9,11 +9,10 @@
|
|||
"start": "webpack-dev-server"
|
||||
},
|
||||
"dependencies": {
|
||||
"@waku/core": "0.0.16",
|
||||
"@waku/create": "0.0.12",
|
||||
"@waku/interfaces": "0.0.11",
|
||||
"@waku/noise": "0.0.3",
|
||||
"@waku/utils": "0.0.4",
|
||||
"@waku/core": "0.0.19",
|
||||
"@waku/create": "0.0.15",
|
||||
"@waku/noise": "0.0.3-31510da",
|
||||
"@waku/utils": "0.0.6",
|
||||
"protobufjs": "^7.1.2",
|
||||
"qrcode": "^1.5.1"
|
||||
},
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { createLightNode } from "@waku/create";
|
||||
import * as utils from "@waku/utils/bytes";
|
||||
import { waitForRemotePeer } from "@waku/core";
|
||||
import { Protocols } from "@waku/interfaces";
|
||||
import * as noise from "@waku/noise";
|
||||
import protobuf from "protobufjs";
|
||||
import QRCode from "qrcode";
|
||||
|
@ -22,17 +21,16 @@ async function main() {
|
|||
|
||||
try {
|
||||
await node.start();
|
||||
await waitForRemotePeer(node, [Protocols.Filter, Protocols.LightPush]);
|
||||
await waitForRemotePeer(node, ["filter", "lightpush"]);
|
||||
|
||||
ui.waku.connected();
|
||||
|
||||
const responder = getResponder(node);
|
||||
const myStaticKey = noise.generateX25519KeyPair();
|
||||
const urlPairingInfo = getPairingInfoFromURL();
|
||||
|
||||
const pairingObj = new noise.WakuPairing(
|
||||
node.lightPush,
|
||||
responder,
|
||||
node.filter,
|
||||
myStaticKey,
|
||||
urlPairingInfo || new noise.ResponderParameters()
|
||||
);
|
||||
|
@ -212,59 +210,6 @@ function getPairingInfoFromURL() {
|
|||
);
|
||||
}
|
||||
|
||||
function getResponder(node) {
|
||||
const msgQueue = new Array();
|
||||
const subscriptions = new Map();
|
||||
const intervals = new Map();
|
||||
|
||||
const responder = {
|
||||
async subscribe(decoder) {
|
||||
const subscription = await node.filter.subscribe(
|
||||
[decoder],
|
||||
(wakuMessage) => {
|
||||
msgQueue.push(wakuMessage);
|
||||
}
|
||||
);
|
||||
subscriptions.set(decoder.contentTopic, subscription);
|
||||
},
|
||||
async nextMessage(contentTopic) {
|
||||
if (msgQueue.length != 0) {
|
||||
const oldestMsg = msgQueue.shift();
|
||||
if (oldestMsg.contentTopic === contentTopic) {
|
||||
return oldestMsg;
|
||||
}
|
||||
}
|
||||
|
||||
return new Promise((resolve) => {
|
||||
const interval = setInterval(() => {
|
||||
if (msgQueue.length != 0) {
|
||||
clearInterval(interval);
|
||||
const oldestMsg = msgQueue.shift();
|
||||
if (oldestMsg.contentTopic === contentTopic) {
|
||||
resolve(oldestMsg);
|
||||
}
|
||||
}
|
||||
}, 100);
|
||||
intervals.set(contentTopic, interval);
|
||||
});
|
||||
},
|
||||
async stop(contentTopic) {
|
||||
if (intervals.has(contentTopic)) {
|
||||
clearInterval(intervals.get(contentTopic));
|
||||
intervals.delete(contentTopic);
|
||||
}
|
||||
if (subscriptions.has(contentTopic)) {
|
||||
await subscriptions.get(contentTopic)();
|
||||
subscriptions.delete(contentTopic);
|
||||
} else {
|
||||
console.log("Subscriptipon doesnt exist");
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
return responder;
|
||||
}
|
||||
|
||||
async function scheduleHandshakeAuthConfirmation(pairingObj, ui) {
|
||||
const authCode = await pairingObj.getAuthCode();
|
||||
ui.handshake.connecting();
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -9,11 +9,10 @@
|
|||
"start": "webpack-dev-server"
|
||||
},
|
||||
"dependencies": {
|
||||
"@waku/core": "0.0.16",
|
||||
"@waku/create": "0.0.12",
|
||||
"@waku/interfaces": "0.0.11",
|
||||
"@waku/noise": "0.0.3",
|
||||
"@waku/utils": "0.0.4",
|
||||
"@waku/core": "0.0.19",
|
||||
"@waku/create": "0.0.15",
|
||||
"@waku/noise": "0.0.3-31510da",
|
||||
"@waku/utils": "0.0.6",
|
||||
"protobufjs": "^7.1.2",
|
||||
"qrcode": "^1.5.1"
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue