mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-05 23:33:08 +00:00
Merge pull request #1134 from waku-org/chore/remove-peer-exchange-dep
This commit is contained in:
commit
f2f3cdc2a7
2
package-lock.json
generated
2
package-lock.json
generated
@ -26317,7 +26317,6 @@
|
|||||||
"@waku/byte-utils": "*",
|
"@waku/byte-utils": "*",
|
||||||
"@waku/interfaces": "*",
|
"@waku/interfaces": "*",
|
||||||
"@waku/libp2p-utils": "*",
|
"@waku/libp2p-utils": "*",
|
||||||
"@waku/peer-exchange": "*",
|
|
||||||
"@waku/proto": "*",
|
"@waku/proto": "*",
|
||||||
"debug": "^4.3.4",
|
"debug": "^4.3.4",
|
||||||
"it-all": "^1.0.6",
|
"it-all": "^1.0.6",
|
||||||
@ -29834,7 +29833,6 @@
|
|||||||
"@waku/byte-utils": "*",
|
"@waku/byte-utils": "*",
|
||||||
"@waku/interfaces": "*",
|
"@waku/interfaces": "*",
|
||||||
"@waku/libp2p-utils": "*",
|
"@waku/libp2p-utils": "*",
|
||||||
"@waku/peer-exchange": "*",
|
|
||||||
"@waku/proto": "*",
|
"@waku/proto": "*",
|
||||||
"app-root-path": "^3.0.0",
|
"app-root-path": "^3.0.0",
|
||||||
"chai": "^4.3.4",
|
"chai": "^4.3.4",
|
||||||
|
|||||||
@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- `multicodec` property from protocol interfaces.
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
|
||||||
|
- Dependency on `@waku/peer-exchange`.
|
||||||
|
|
||||||
## [@waku/core@0.0.10] - 2023-01-25
|
## [@waku/core@0.0.10] - 2023-01-25
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|||||||
@ -91,7 +91,6 @@
|
|||||||
"@waku/byte-utils": "*",
|
"@waku/byte-utils": "*",
|
||||||
"@waku/interfaces": "*",
|
"@waku/interfaces": "*",
|
||||||
"@waku/libp2p-utils": "*",
|
"@waku/libp2p-utils": "*",
|
||||||
"@waku/peer-exchange": "*",
|
|
||||||
"@waku/proto": "*",
|
"@waku/proto": "*",
|
||||||
"debug": "^4.3.4",
|
"debug": "^4.3.4",
|
||||||
"it-all": "^1.0.6",
|
"it-all": "^1.0.6",
|
||||||
|
|||||||
@ -65,6 +65,7 @@ export type UnsubscribeFunction = () => Promise<void>;
|
|||||||
* - https://github.com/status-im/nwaku/issues/948
|
* - https://github.com/status-im/nwaku/issues/948
|
||||||
*/
|
*/
|
||||||
class Filter implements IFilter {
|
class Filter implements IFilter {
|
||||||
|
multicodec: string;
|
||||||
pubSubTopic: string;
|
pubSubTopic: string;
|
||||||
private subscriptions: Map<string, Callback<any>>;
|
private subscriptions: Map<string, Callback<any>>;
|
||||||
private decoders: Map<
|
private decoders: Map<
|
||||||
@ -73,6 +74,7 @@ class Filter implements IFilter {
|
|||||||
>;
|
>;
|
||||||
|
|
||||||
constructor(public components: FilterComponents, options?: CreateOptions) {
|
constructor(public components: FilterComponents, options?: CreateOptions) {
|
||||||
|
this.multicodec = FilterCodec;
|
||||||
this.subscriptions = new Map();
|
this.subscriptions = new Map();
|
||||||
this.decoders = new Map();
|
this.decoders = new Map();
|
||||||
this.pubSubTopic = options?.pubSubTopic ?? DefaultPubSubTopic;
|
this.pubSubTopic = options?.pubSubTopic ?? DefaultPubSubTopic;
|
||||||
|
|||||||
@ -52,9 +52,11 @@ export interface CreateOptions {
|
|||||||
* Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
|
* Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
|
||||||
*/
|
*/
|
||||||
class LightPush implements ILightPush {
|
class LightPush implements ILightPush {
|
||||||
|
multicodec: string;
|
||||||
pubSubTopic: string;
|
pubSubTopic: string;
|
||||||
|
|
||||||
constructor(public components: LightPushComponents, options?: CreateOptions) {
|
constructor(public components: LightPushComponents, options?: CreateOptions) {
|
||||||
|
this.multicodec = LightPushCodec;
|
||||||
this.pubSubTopic = options?.pubSubTopic ?? DefaultPubSubTopic;
|
this.pubSubTopic = options?.pubSubTopic ?? DefaultPubSubTopic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -105,9 +105,11 @@ export interface QueryOptions {
|
|||||||
* The Waku Store protocol can be used to retrieved historical messages.
|
* The Waku Store protocol can be used to retrieved historical messages.
|
||||||
*/
|
*/
|
||||||
class Store implements IStore {
|
class Store implements IStore {
|
||||||
|
multicodec: string;
|
||||||
pubSubTopic: string;
|
pubSubTopic: string;
|
||||||
|
|
||||||
constructor(public components: StoreComponents, options?: CreateOptions) {
|
constructor(public components: StoreComponents, options?: CreateOptions) {
|
||||||
|
this.multicodec = StoreCodec;
|
||||||
this.pubSubTopic = options?.pubSubTopic ?? DefaultPubSubTopic;
|
this.pubSubTopic = options?.pubSubTopic ?? DefaultPubSubTopic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,14 +1,9 @@
|
|||||||
import { PeerProtocolsChangeData } from "@libp2p/interface-peer-store";
|
import { PeerProtocolsChangeData } from "@libp2p/interface-peer-store";
|
||||||
import type { IRelay, PointToPointProtocol, Waku } from "@waku/interfaces";
|
import type { IRelay, PointToPointProtocol, Waku } from "@waku/interfaces";
|
||||||
import { Protocols } from "@waku/interfaces";
|
import { Protocols } from "@waku/interfaces";
|
||||||
import { PeerExchangeCodec } from "@waku/peer-exchange";
|
|
||||||
import debug from "debug";
|
import debug from "debug";
|
||||||
import { pEvent } from "p-event";
|
import { pEvent } from "p-event";
|
||||||
|
|
||||||
import { FilterCodec } from "./filter/index.js";
|
|
||||||
import { LightPushCodec } from "./light_push/index.js";
|
|
||||||
import { StoreCodec } from "./store/index.js";
|
|
||||||
|
|
||||||
const log = debug("waku:wait-for-remote-peer");
|
const log = debug("waku:wait-for-remote-peer");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,19 +45,19 @@ export async function waitForRemotePeer(
|
|||||||
if (protocols.includes(Protocols.Store)) {
|
if (protocols.includes(Protocols.Store)) {
|
||||||
if (!waku.store)
|
if (!waku.store)
|
||||||
throw new Error("Cannot wait for Store peer: protocol not mounted");
|
throw new Error("Cannot wait for Store peer: protocol not mounted");
|
||||||
promises.push(waitForConnectedPeer(waku.store, [StoreCodec]));
|
promises.push(waitForConnectedPeer(waku.store));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (protocols.includes(Protocols.LightPush)) {
|
if (protocols.includes(Protocols.LightPush)) {
|
||||||
if (!waku.lightPush)
|
if (!waku.lightPush)
|
||||||
throw new Error("Cannot wait for LightPush peer: protocol not mounted");
|
throw new Error("Cannot wait for LightPush peer: protocol not mounted");
|
||||||
promises.push(waitForConnectedPeer(waku.lightPush, [LightPushCodec]));
|
promises.push(waitForConnectedPeer(waku.lightPush));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (protocols.includes(Protocols.Filter)) {
|
if (protocols.includes(Protocols.Filter)) {
|
||||||
if (!waku.filter)
|
if (!waku.filter)
|
||||||
throw new Error("Cannot wait for Filter peer: protocol not mounted");
|
throw new Error("Cannot wait for Filter peer: protocol not mounted");
|
||||||
promises.push(waitForConnectedPeer(waku.filter, [FilterCodec]));
|
promises.push(waitForConnectedPeer(waku.filter));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (protocols.includes(Protocols.PeerExchange)) {
|
if (protocols.includes(Protocols.PeerExchange)) {
|
||||||
@ -70,7 +65,7 @@ export async function waitForRemotePeer(
|
|||||||
throw new Error(
|
throw new Error(
|
||||||
"Cannot wait for Peer Exchange peer: protocol not mounted"
|
"Cannot wait for Peer Exchange peer: protocol not mounted"
|
||||||
);
|
);
|
||||||
promises.push(waitForConnectedPeer(waku.peerExchange, [PeerExchangeCodec]));
|
promises.push(waitForConnectedPeer(waku.peerExchange));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timeoutMs) {
|
if (timeoutMs) {
|
||||||
@ -88,28 +83,25 @@ export async function waitForRemotePeer(
|
|||||||
* Wait for a peer with the given protocol to be connected.
|
* Wait for a peer with the given protocol to be connected.
|
||||||
*/
|
*/
|
||||||
async function waitForConnectedPeer(
|
async function waitForConnectedPeer(
|
||||||
waku: PointToPointProtocol,
|
protocol: PointToPointProtocol
|
||||||
codecs: string[]
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const peers = await waku.peers();
|
const codec = protocol.multicodec;
|
||||||
|
const peers = await protocol.peers();
|
||||||
|
|
||||||
if (peers.length) {
|
if (peers.length) {
|
||||||
log(`${codecs} peer found: `, peers[0].id.toString());
|
log(`${codec} peer found: `, peers[0].id.toString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await new Promise<void>((resolve) => {
|
await new Promise<void>((resolve) => {
|
||||||
const cb = (evt: CustomEvent<PeerProtocolsChangeData>): void => {
|
const cb = (evt: CustomEvent<PeerProtocolsChangeData>): void => {
|
||||||
for (const codec of codecs) {
|
if (evt.detail.protocols.includes(codec)) {
|
||||||
if (evt.detail.protocols.includes(codec)) {
|
log("Resolving for", codec, evt.detail.protocols);
|
||||||
log("Resolving for", codec, evt.detail.protocols);
|
protocol.peerStore.removeEventListener("change:protocols", cb);
|
||||||
waku.peerStore.removeEventListener("change:protocols", cb);
|
resolve();
|
||||||
resolve();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
waku.peerStore.addEventListener("change:protocols", cb);
|
protocol.peerStore.addEventListener("change:protocols", cb);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,16 +12,15 @@ import type {
|
|||||||
Waku,
|
Waku,
|
||||||
} from "@waku/interfaces";
|
} from "@waku/interfaces";
|
||||||
import { Protocols } from "@waku/interfaces";
|
import { Protocols } from "@waku/interfaces";
|
||||||
import { PeerExchangeCodec } from "@waku/peer-exchange";
|
|
||||||
import debug from "debug";
|
import debug from "debug";
|
||||||
import type { Libp2p } from "libp2p";
|
import type { Libp2p } from "libp2p";
|
||||||
|
|
||||||
import { FilterCodec, FilterComponents } from "./filter/index.js";
|
import { FilterComponents } from "./filter/index.js";
|
||||||
import { LightPushCodec, LightPushComponents } from "./light_push/index.js";
|
import { LightPushComponents } from "./light_push/index.js";
|
||||||
import { createEncoder } from "./message/version_0.js";
|
import { createEncoder } from "./message/version_0.js";
|
||||||
import * as relayConstants from "./relay/constants.js";
|
import * as relayConstants from "./relay/constants.js";
|
||||||
import { RelayCodecs, RelayPingContentTopic } from "./relay/constants.js";
|
import { RelayPingContentTopic } from "./relay/constants.js";
|
||||||
import { StoreCodec, StoreComponents } from "./store/index.js";
|
import { StoreComponents } from "./store/index.js";
|
||||||
|
|
||||||
export const DefaultPingKeepAliveValueSecs = 0;
|
export const DefaultPingKeepAliveValueSecs = 0;
|
||||||
export const DefaultRelayKeepAliveValueSecs = 5 * 60;
|
export const DefaultRelayKeepAliveValueSecs = 5 * 60;
|
||||||
@ -165,20 +164,50 @@ export class WakuNode implements Waku {
|
|||||||
|
|
||||||
const codecs: string[] = [];
|
const codecs: string[] = [];
|
||||||
if (_protocols.includes(Protocols.Relay)) {
|
if (_protocols.includes(Protocols.Relay)) {
|
||||||
RelayCodecs.forEach((codec) => codecs.push(codec));
|
if (this.relay) {
|
||||||
|
this.relay.multicodecs.forEach((codec) => codecs.push(codec));
|
||||||
|
} else {
|
||||||
|
log(
|
||||||
|
"Relay codec not included in dial codec: protocol not mounted locally"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (_protocols.includes(Protocols.Store)) {
|
if (_protocols.includes(Protocols.Store)) {
|
||||||
codecs.push(StoreCodec);
|
if (this.store) {
|
||||||
|
codecs.push(this.store.multicodec);
|
||||||
|
} else {
|
||||||
|
log(
|
||||||
|
"Store codec not included in dial codec: protocol not mounted locally"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (_protocols.includes(Protocols.LightPush)) {
|
if (_protocols.includes(Protocols.LightPush)) {
|
||||||
codecs.push(LightPushCodec);
|
if (this.lightPush) {
|
||||||
|
codecs.push(this.lightPush.multicodec);
|
||||||
|
} else {
|
||||||
|
log(
|
||||||
|
"Light Push codec not included in dial codec: protocol not mounted locally"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (_protocols.includes(Protocols.Filter)) {
|
if (_protocols.includes(Protocols.Filter)) {
|
||||||
codecs.push(FilterCodec);
|
if (this.filter) {
|
||||||
|
codecs.push(this.filter.multicodec);
|
||||||
|
} else {
|
||||||
|
log(
|
||||||
|
"Filter codec not included in dial codec: protocol not mounted locally"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_protocols.includes(Protocols.PeerExchange)) {
|
if (_protocols.includes(Protocols.PeerExchange)) {
|
||||||
codecs.push(PeerExchangeCodec);
|
if (this.peerExchange) {
|
||||||
|
codecs.push(this.peerExchange.multicodec);
|
||||||
|
} else {
|
||||||
|
log(
|
||||||
|
"Peer Exchange codec not included in dial codec: protocol not mounted locally"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log(`Dialing to ${peer.toString()} with protocols ${_protocols}`);
|
log(`Dialing to ${peer.toString()} with protocols ${_protocols}`);
|
||||||
|
|||||||
@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- `multicodec` property on protocol interfaces.
|
||||||
|
|
||||||
## [0.0.7] - 2023-01-18
|
## [0.0.7] - 2023-01-18
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@ -12,6 +12,7 @@ export enum Protocols {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface PointToPointProtocol {
|
export interface PointToPointProtocol {
|
||||||
|
multicodec: string;
|
||||||
peerStore: PeerStore;
|
peerStore: PeerStore;
|
||||||
peers: () => Promise<Peer[]>;
|
peers: () => Promise<Peer[]>;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,6 +30,7 @@ const log = debug("waku:peer-exchange");
|
|||||||
* Implementation of the Peer Exchange protocol (https://rfc.vac.dev/spec/34/)
|
* Implementation of the Peer Exchange protocol (https://rfc.vac.dev/spec/34/)
|
||||||
*/
|
*/
|
||||||
export class WakuPeerExchange implements IPeerExchange {
|
export class WakuPeerExchange implements IPeerExchange {
|
||||||
|
multicodec: string;
|
||||||
private callback:
|
private callback:
|
||||||
| ((response: PeerExchangeResponse) => Promise<void>)
|
| ((response: PeerExchangeResponse) => Promise<void>)
|
||||||
| undefined;
|
| undefined;
|
||||||
@ -42,6 +43,7 @@ export class WakuPeerExchange implements IPeerExchange {
|
|||||||
public components: PeerExchangeComponents,
|
public components: PeerExchangeComponents,
|
||||||
public createOptions?: ProtocolOptions
|
public createOptions?: ProtocolOptions
|
||||||
) {
|
) {
|
||||||
|
this.multicodec = PeerExchangeCodec;
|
||||||
this.components.registrar
|
this.components.registrar
|
||||||
.handle(PeerExchangeCodec, this.handler.bind(this))
|
.handle(PeerExchangeCodec, this.handler.bind(this))
|
||||||
.catch((e) => log("Failed to register peer exchange protocol", e));
|
.catch((e) => log("Failed to register peer exchange protocol", e));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user