mirror of https://github.com/waku-org/js-waku.git
chore: bump libp2p to next (0.38.0 rc)
This commit is contained in:
parent
c346361940
commit
4eeca93d47
File diff suppressed because it is too large
Load Diff
|
@ -87,7 +87,7 @@
|
||||||
"it-length-prefixed": "^7.0.1",
|
"it-length-prefixed": "^7.0.1",
|
||||||
"it-pipe": "^2.0.3",
|
"it-pipe": "^2.0.3",
|
||||||
"js-sha3": "^0.8.0",
|
"js-sha3": "^0.8.0",
|
||||||
"libp2p": "^0.37.3",
|
"libp2p": "next",
|
||||||
"multiformats": "^9.6.5",
|
"multiformats": "^9.6.5",
|
||||||
"protons-runtime": "^1.0.4",
|
"protons-runtime": "^1.0.4",
|
||||||
"uint8arrays": "^3.0.0",
|
"uint8arrays": "^3.0.0",
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { Noise } from "@chainsafe/libp2p-noise";
|
import { Noise } from "@chainsafe/libp2p-noise";
|
||||||
|
import type { Stream } from "@libp2p/interface-connection";
|
||||||
import type { PeerId } from "@libp2p/interface-peer-id";
|
import type { PeerId } from "@libp2p/interface-peer-id";
|
||||||
import { PeerProtocolsChangeData } from "@libp2p/interface-peer-store";
|
import { PeerProtocolsChangeData } from "@libp2p/interface-peer-store";
|
||||||
import { Mplex } from "@libp2p/mplex";
|
import { Mplex } from "@libp2p/mplex";
|
||||||
|
@ -175,9 +176,10 @@ export class Waku {
|
||||||
* @param peer The peer to dial
|
* @param peer The peer to dial
|
||||||
* @param protocols Waku protocols we expect from the peer; Default to Relay
|
* @param protocols Waku protocols we expect from the peer; Default to Relay
|
||||||
*/
|
*/
|
||||||
// TODO: Any to be removed once libp2p uses @libp2p/interface-connection for
|
async dial(
|
||||||
// dialProtocol
|
peer: PeerId | Multiaddr,
|
||||||
async dial(peer: PeerId | Multiaddr, protocols?: Protocols[]): Promise<any> {
|
protocols?: Protocols[]
|
||||||
|
): Promise<Stream> {
|
||||||
const _protocols = protocols ?? [Protocols.Relay];
|
const _protocols = protocols ?? [Protocols.Relay];
|
||||||
|
|
||||||
const codecs: string[] = [];
|
const codecs: string[] = [];
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
|
import type { Stream } from "@libp2p/interface-connection";
|
||||||
import type { PeerId } from "@libp2p/interface-peer-id";
|
import type { PeerId } from "@libp2p/interface-peer-id";
|
||||||
import type { Peer } from "@libp2p/interface-peer-store";
|
import type { Peer } from "@libp2p/interface-peer-store";
|
||||||
|
import type { IncomingStreamData } from "@libp2p/interface-registrar";
|
||||||
import debug from "debug";
|
import debug from "debug";
|
||||||
import all from "it-all";
|
import all from "it-all";
|
||||||
import * as lp from "it-length-prefixed";
|
import * as lp from "it-length-prefixed";
|
||||||
import { pipe } from "it-pipe";
|
import { pipe } from "it-pipe";
|
||||||
import { Libp2p } from "libp2p";
|
import type { Libp2p } from "libp2p";
|
||||||
|
|
||||||
import { WakuMessage as WakuMessageProto } from "../../proto/message";
|
import { WakuMessage as WakuMessageProto } from "../../proto/message";
|
||||||
import { DefaultPubSubTopic } from "../constants";
|
import { DefaultPubSubTopic } from "../constants";
|
||||||
|
@ -116,11 +118,10 @@ export class WakuFilter {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// `any` can be removed at the next libp2p release >0.37.3
|
private onRequest(streamData: IncomingStreamData): void {
|
||||||
private onRequest({ stream }: any): void {
|
|
||||||
log("Receiving message push");
|
log("Receiving message push");
|
||||||
try {
|
try {
|
||||||
pipe(stream, lp.decode(), async (source) => {
|
pipe(streamData.stream, lp.decode(), async (source) => {
|
||||||
for await (const bytes of source) {
|
for await (const bytes of source) {
|
||||||
const res = FilterRPC.decode(bytes.slice());
|
const res = FilterRPC.decode(bytes.slice());
|
||||||
if (res.requestId && res.push?.messages?.length) {
|
if (res.requestId && res.push?.messages?.length) {
|
||||||
|
@ -201,15 +202,14 @@ export class WakuFilter {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should be able to remove any at next libp2p release >0.37.3
|
// Should be able to remove any at next libp2p release >0.37.3
|
||||||
private async newStream(peer: Peer): Promise<any> {
|
private async newStream(peer: Peer): Promise<Stream> {
|
||||||
const connections = this.libp2p.connectionManager.getConnections(peer.id);
|
const connections = this.libp2p.connectionManager.getConnections(peer.id);
|
||||||
if (!connections) {
|
if (!connections) {
|
||||||
throw new Error("Failed to get a connection to the peer");
|
throw new Error("Failed to get a connection to the peer");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Appropriate connection selection
|
// TODO: Appropriate connection selection
|
||||||
const { stream } = await connections[0].newStream(FilterCodec);
|
return connections[0].newStream(FilterCodec);
|
||||||
return stream;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getPeer(peerId?: PeerId): Promise<Peer> {
|
private async getPeer(peerId?: PeerId): Promise<Peer> {
|
||||||
|
|
|
@ -66,7 +66,7 @@ export class WakuLightPush {
|
||||||
if (!connections) throw "Failed to get a connection to the peer";
|
if (!connections) throw "Failed to get a connection to the peer";
|
||||||
|
|
||||||
// TODO: Appropriate connection management
|
// TODO: Appropriate connection management
|
||||||
const { stream } = await connections[0].newStream(LightPushCodec);
|
const stream = await connections[0].newStream(LightPushCodec);
|
||||||
try {
|
try {
|
||||||
const pubSubTopic = opts?.pubSubTopic
|
const pubSubTopic = opts?.pubSubTopic
|
||||||
? opts.pubSubTopic
|
? opts.pubSubTopic
|
||||||
|
|
|
@ -201,7 +201,7 @@ export class WakuStore {
|
||||||
let cursor = undefined;
|
let cursor = undefined;
|
||||||
while (true) {
|
while (true) {
|
||||||
// TODO: Some connection selection logic?
|
// TODO: Some connection selection logic?
|
||||||
const { stream } = await connections[0].newStream(storeCodec);
|
const stream = await connections[0].newStream(storeCodec);
|
||||||
const queryOpts = Object.assign(opts, { cursor });
|
const queryOpts = Object.assign(opts, { cursor });
|
||||||
const historyRpcQuery = HistoryRPC.createQuery(queryOpts);
|
const historyRpcQuery = HistoryRPC.createQuery(queryOpts);
|
||||||
dbg("Querying store peer", connections[0].remoteAddr.toString());
|
dbg("Querying store peer", connections[0].remoteAddr.toString());
|
||||||
|
|
Loading…
Reference in New Issue