mirror of
https://github.com/waku-org/js-waku.git
synced 2025-01-27 12:45:21 +00:00
Merge pull request #1067 from waku-org/refactor/multiaddr-to-peer-info
This commit is contained in:
commit
c0ee7bf015
@ -59,6 +59,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@waku/enr": "*",
|
"@waku/enr": "*",
|
||||||
"@waku/byte-utils": "*",
|
"@waku/byte-utils": "*",
|
||||||
|
"@waku/libp2p-utils": "*",
|
||||||
"hi-base32": "^0.5.1",
|
"hi-base32": "^0.5.1",
|
||||||
"debug": "^4.3.4",
|
"debug": "^4.3.4",
|
||||||
"dns-query": "^0.11.2",
|
"dns-query": "^0.11.2",
|
||||||
|
@ -6,10 +6,10 @@ import { symbol } from "@libp2p/interface-peer-discovery";
|
|||||||
import type { PeerInfo } from "@libp2p/interface-peer-info";
|
import type { PeerInfo } from "@libp2p/interface-peer-info";
|
||||||
import { CustomEvent, EventEmitter } from "@libp2p/interfaces/events";
|
import { CustomEvent, EventEmitter } from "@libp2p/interfaces/events";
|
||||||
import { ENR } from "@waku/enr";
|
import { ENR } from "@waku/enr";
|
||||||
|
import { multiaddrsToPeerInfo } from "@waku/libp2p-utils";
|
||||||
import debug from "debug";
|
import debug from "debug";
|
||||||
|
|
||||||
import { DnsNodeDiscovery, NodeCapabilityCount } from "./dns.js";
|
import { DnsNodeDiscovery, NodeCapabilityCount } from "./dns.js";
|
||||||
import { multiaddrsToPeerInfo } from "./multiaddr_to_peer_info.js";
|
|
||||||
|
|
||||||
const log = debug("waku:peer-discovery-dns");
|
const log = debug("waku:peer-discovery-dns");
|
||||||
|
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
import { PeerInfo } from "@libp2p/interface-peer-info";
|
|
||||||
import { peerIdFromString } from "@libp2p/peer-id";
|
|
||||||
import { Multiaddr } from "@multiformats/multiaddr";
|
|
||||||
|
|
||||||
export function multiaddrsToPeerInfo(mas: Multiaddr[]): PeerInfo[] {
|
|
||||||
return mas
|
|
||||||
.map((ma) => {
|
|
||||||
const peerIdStr = ma.getPeerId();
|
|
||||||
const protocols: string[] = [];
|
|
||||||
return {
|
|
||||||
id: peerIdStr ? peerIdFromString(peerIdStr) : null,
|
|
||||||
multiaddrs: [ma.decapsulateCode(421)],
|
|
||||||
protocols,
|
|
||||||
};
|
|
||||||
})
|
|
||||||
.filter((peerInfo): peerInfo is PeerInfo => peerInfo.id !== null);
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user