chore: bump libp2p to next (0.38.0 rc)

This commit is contained in:
Franck Royer 2022-07-22 15:26:43 +10:00 committed by fryorcraken.eth
parent c346361940
commit 4eeca93d47
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
6 changed files with 927 additions and 1151 deletions

2048
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -87,7 +87,7 @@
"it-length-prefixed": "^7.0.1",
"it-pipe": "^2.0.3",
"js-sha3": "^0.8.0",
"libp2p": "^0.37.3",
"libp2p": "next",
"multiformats": "^9.6.5",
"protons-runtime": "^1.0.4",
"uint8arrays": "^3.0.0",

View File

@ -1,4 +1,5 @@
import { Noise } from "@chainsafe/libp2p-noise";
import type { Stream } from "@libp2p/interface-connection";
import type { PeerId } from "@libp2p/interface-peer-id";
import { PeerProtocolsChangeData } from "@libp2p/interface-peer-store";
import { Mplex } from "@libp2p/mplex";
@ -175,9 +176,10 @@ export class Waku {
* @param peer The peer to dial
* @param protocols Waku protocols we expect from the peer; Default to Relay
*/
// TODO: Any to be removed once libp2p uses @libp2p/interface-connection for
// dialProtocol
async dial(peer: PeerId | Multiaddr, protocols?: Protocols[]): Promise<any> {
async dial(
peer: PeerId | Multiaddr,
protocols?: Protocols[]
): Promise<Stream> {
const _protocols = protocols ?? [Protocols.Relay];
const codecs: string[] = [];

View File

@ -1,10 +1,12 @@
import type { Stream } from "@libp2p/interface-connection";
import type { PeerId } from "@libp2p/interface-peer-id";
import type { Peer } from "@libp2p/interface-peer-store";
import type { IncomingStreamData } from "@libp2p/interface-registrar";
import debug from "debug";
import all from "it-all";
import * as lp from "it-length-prefixed";
import { pipe } from "it-pipe";
import { Libp2p } from "libp2p";
import type { Libp2p } from "libp2p";
import { WakuMessage as WakuMessageProto } from "../../proto/message";
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({ stream }: any): void {
private onRequest(streamData: IncomingStreamData): void {
log("Receiving message push");
try {
pipe(stream, lp.decode(), async (source) => {
pipe(streamData.stream, lp.decode(), async (source) => {
for await (const bytes of source) {
const res = FilterRPC.decode(bytes.slice());
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
private async newStream(peer: Peer): Promise<any> {
private async newStream(peer: Peer): Promise<Stream> {
const connections = this.libp2p.connectionManager.getConnections(peer.id);
if (!connections) {
throw new Error("Failed to get a connection to the peer");
}
// TODO: Appropriate connection selection
const { stream } = await connections[0].newStream(FilterCodec);
return stream;
return connections[0].newStream(FilterCodec);
}
private async getPeer(peerId?: PeerId): Promise<Peer> {

View File

@ -66,7 +66,7 @@ export class WakuLightPush {
if (!connections) throw "Failed to get a connection to the peer";
// TODO: Appropriate connection management
const { stream } = await connections[0].newStream(LightPushCodec);
const stream = await connections[0].newStream(LightPushCodec);
try {
const pubSubTopic = opts?.pubSubTopic
? opts.pubSubTopic

View File

@ -201,7 +201,7 @@ export class WakuStore {
let cursor = undefined;
while (true) {
// 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 historyRpcQuery = HistoryRPC.createQuery(queryOpts);
dbg("Querying store peer", connections[0].remoteAddr.toString());