From 2def2bdcd2cf60daeb36da94c041361cc2e683cb Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Thu, 24 Mar 2022 06:59:39 +0000 Subject: [PATCH] fix: update interfaces (#305) --- package.json | 6 +++--- src/content-routing/index.ts | 4 ++-- src/kad-dht.ts | 4 ++-- src/message/index.ts | 8 ++++---- src/network.ts | 4 ++-- src/peer-list/index.ts | 2 +- src/peer-routing/index.ts | 4 ++-- src/query/events.ts | 10 +++++----- src/rpc/handlers/get-providers.ts | 4 ++-- src/utils.ts | 6 +++--- test/rpc/handlers/get-providers.spec.ts | 6 +++--- 11 files changed, 29 insertions(+), 29 deletions(-) diff --git a/package.json b/package.json index d5bbd659..ddc52c49 100644 --- a/package.json +++ b/package.json @@ -137,7 +137,7 @@ }, "dependencies": { "@libp2p/crypto": "^0.22.9", - "@libp2p/interfaces": "^1.3.14", + "@libp2p/interfaces": "^1.3.18", "@libp2p/logger": "^1.1.2", "@libp2p/peer-id": "^1.1.8", "@libp2p/record": "^1.0.0", @@ -172,9 +172,9 @@ "varint": "^6.0.0" }, "devDependencies": { - "@libp2p/interface-compliance-tests": "^1.1.16", + "@libp2p/interface-compliance-tests": "^1.1.20", "@libp2p/peer-id-factory": "^1.0.8", - "@libp2p/peer-store": "^1.0.6", + "@libp2p/peer-store": "^1.0.7", "@types/lodash.random": "^3.2.6", "@types/lodash.range": "^3.2.6", "@types/node": "^16.11.26", diff --git a/src/content-routing/index.ts b/src/content-routing/index.ts index 464776c6..9cd31053 100644 --- a/src/content-routing/index.ts +++ b/src/content-routing/index.ts @@ -21,7 +21,7 @@ import type { QueryFunc } from '../query/types.js' import type { CID } from 'multiformats/cid' import type { AbortOptions } from '@libp2p/interfaces' import type { Multiaddr } from '@multiformats/multiaddr' -import type { PeerData } from '@libp2p/interfaces/peer-data' +import type { PeerInfo } from '@libp2p/interfaces/peer-info' import { Components, Initializable } from '@libp2p/interfaces/components' export interface ContentRoutingInit { @@ -139,7 +139,7 @@ export class ContentRouting implements Initializable { // yield values if we have some, also slice because maybe we got lucky and already have too many? if (provs.length > 0) { - const providers: PeerData[] = [] + const providers: PeerInfo[] = [] for (const peerId of provs.slice(0, toFind)) { providers.push({ diff --git a/src/kad-dht.ts b/src/kad-dht.ts index 7860a39e..f8005bf8 100644 --- a/src/kad-dht.ts +++ b/src/kad-dht.ts @@ -15,7 +15,7 @@ import { } from './utils.js' import { Logger, logger } from '@libp2p/logger' import type { QueryOptions, Validators, Selectors, DHT } from '@libp2p/interfaces/dht' -import type { PeerData } from '@libp2p/interfaces/peer-data' +import type { PeerInfo } from '@libp2p/interfaces/peer-info' import { CustomEvent, EventEmitter } from '@libp2p/interfaces' import type { PeerId } from '@libp2p/interfaces/peer-id' import type { CID } from 'multiformats/cid' @@ -195,7 +195,7 @@ export class KadDHT extends EventEmitter implements DHT, In this.querySelf.init(components) } - async onPeerConnect (peerData: PeerData) { + async onPeerConnect (peerData: PeerInfo) { this.log('peer %p connected', peerData.id) if (this.lan) { diff --git a/src/message/index.ts b/src/message/index.ts index 1ac591ae..4f1f0afa 100644 --- a/src/message/index.ts +++ b/src/message/index.ts @@ -2,7 +2,7 @@ import { peerIdFromBytes } from '@libp2p/peer-id' import { Multiaddr } from '@multiformats/multiaddr' import { Libp2pRecord } from '@libp2p/record' import Proto from './dht.js' -import type { PeerData } from '@libp2p/interfaces/peer-data' +import type { PeerInfo } from '@libp2p/interfaces/peer-info' export const MESSAGE_TYPE = Proto.Message.MessageType export const CONNECTION_TYPE = Proto.Message.ConnectionType @@ -23,8 +23,8 @@ export class Message { public type: Proto.Message.MessageType public key: Uint8Array private clusterLevelRaw: number - public closerPeers: PeerData[] - public providerPeers: PeerData[] + public closerPeers: PeerInfo[] + public providerPeers: PeerInfo[] public record?: Libp2pRecord constructor (type: Proto.Message.MessageType, key: Uint8Array, level: number) { @@ -88,7 +88,7 @@ export class Message { } } -function toPbPeer (peer: PeerData) { +function toPbPeer (peer: PeerInfo) { const output: PBPeer = { id: peer.id.toBytes(), addrs: (peer.multiaddrs ?? []).map((m) => m.bytes), diff --git a/src/network.ts b/src/network.ts index dfb8ec9b..03c10f4a 100644 --- a/src/network.ts +++ b/src/network.ts @@ -16,7 +16,7 @@ import type { PeerId } from '@libp2p/interfaces/peer-id' import type { AbortOptions, Startable } from '@libp2p/interfaces' import type { Logger } from '@libp2p/logger' import type { Duplex } from 'it-stream-types' -import type { PeerData } from '@libp2p/interfaces/peer-data' +import type { PeerInfo } from '@libp2p/interfaces/peer-info' import { Components, Initializable } from '@libp2p/interfaces/components' export interface NetworkInit { @@ -25,7 +25,7 @@ export interface NetworkInit { } interface NetworkEvents { - 'peer': CustomEvent + 'peer': CustomEvent } /** diff --git a/src/peer-list/index.ts b/src/peer-list/index.ts index 6062cc03..d9d6d73e 100644 --- a/src/peer-list/index.ts +++ b/src/peer-list/index.ts @@ -24,7 +24,7 @@ export class PeerList { } /** - * Check if this PeerData is already in here + * Check if this PeerInfo is already in here */ has (peerId: PeerId) { const match = this.list.find((i) => i.equals(peerId)) diff --git a/src/peer-routing/index.ts b/src/peer-routing/index.ts index 30addd4c..d6f7726c 100644 --- a/src/peer-routing/index.ts +++ b/src/peer-routing/index.ts @@ -20,7 +20,7 @@ import type { Network } from '../network.js' import type { Logger } from '@libp2p/logger' import type { AbortOptions } from '@libp2p/interfaces' import type { QueryFunc } from '../query/types.js' -import type { PeerData } from '@libp2p/interfaces/peer-data' +import type { PeerInfo } from '@libp2p/interfaces/peer-info' import type { PeerId } from '@libp2p/interfaces/peer-id' import { Components, Initializable } from '@libp2p/interfaces/components' @@ -296,7 +296,7 @@ export class PeerRouting implements Initializable { async getCloserPeersOffline (key: Uint8Array, closerThan: PeerId) { const id = await utils.convertBuffer(key) const ids = this.routingTable.closestPeers(id) - const output: PeerData[] = [] + const output: PeerInfo[] = [] for (const peerId of ids) { if (peerId.equals(closerThan)) { diff --git a/src/query/events.ts b/src/query/events.ts index afd734c2..fbaa73f2 100644 --- a/src/query/events.ts +++ b/src/query/events.ts @@ -1,6 +1,6 @@ import { MESSAGE_TYPE_LOOKUP } from '../message/index.js' import type { SendingQueryEvent, PeerResponseEvent, MessageType, DialingPeerEvent, AddingPeerEvent, ValueEvent, ProviderEvent, QueryErrorEvent, FinalPeerEvent } from '@libp2p/interfaces/dht' -import type { PeerData } from '@libp2p/interfaces/peer-data' +import type { PeerInfo } from '@libp2p/interfaces/peer-info' import type { PeerId } from '@libp2p/interfaces/peer-id' import type { Libp2pRecord } from '@libp2p/record' @@ -32,8 +32,8 @@ export function sendingQueryEvent (fields: QueryEventFields): SendingQueryEvent export interface PeerResponseEventField { from: PeerId messageType: MessageType - closer?: PeerData[] - providers?: PeerData[] + closer?: PeerInfo[] + providers?: PeerInfo[] record?: Libp2pRecord } @@ -51,7 +51,7 @@ export function peerResponseEvent (fields: PeerResponseEventField): PeerResponse export interface FinalPeerEventFields { from: PeerId - peer: PeerData + peer: PeerInfo } export function finalPeerEvent (fields: FinalPeerEventFields): FinalPeerEvent { @@ -77,7 +77,7 @@ export function queryErrorEvent (fields: ErrorEventFields): QueryErrorEvent { export interface ProviderEventFields { from: PeerId - providers: PeerData[] + providers: PeerInfo[] } export function providerEvent (fields: ProviderEventFields): ProviderEvent { diff --git a/src/rpc/handlers/get-providers.ts b/src/rpc/handlers/get-providers.ts index 1d2049a5..7c0422b0 100644 --- a/src/rpc/handlers/get-providers.ts +++ b/src/rpc/handlers/get-providers.ts @@ -10,7 +10,7 @@ import type { DHTMessageHandler } from '../index.js' import type { Providers } from '../../providers.js' import type { PeerRouting } from '../../peer-routing/index.js' import type { PeerId } from '@libp2p/interfaces/peer-id' -import type { PeerData } from '@libp2p/interfaces/peer-data' +import type { PeerInfo } from '@libp2p/interfaces/peer-info' import { Components, Initializable } from '@libp2p/interfaces/components' const log = logger('libp2p:kad-dht:rpc:handlers:get-providers') @@ -77,7 +77,7 @@ export class GetProvidersHandler implements DHTMessageHandler, Initializable { } async _getPeers (peerIds: PeerId[]) { - const output: PeerData[] = [] + const output: PeerInfo[] = [] const addrFilter = this.lan ? removePublicAddresses : removePrivateAddresses for (const peerId of peerIds) { diff --git a/src/utils.ts b/src/utils.ts index 3576f413..920a7c78 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -5,7 +5,7 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' import { concat as uint8ArrayConcat } from 'uint8arrays/concat' import isPrivateIp from 'private-ip' -import type { PeerData } from '@libp2p/interfaces/peer-data' +import type { PeerInfo } from '@libp2p/interfaces/peer-info' import { peerIdFromBytes } from '@libp2p/peer-id' import type { PeerId } from '@libp2p/interfaces/peer-id' import { RECORD_KEY_PREFIX } from './constants.js' @@ -13,7 +13,7 @@ import { RECORD_KEY_PREFIX } from './constants.js' // const IPNS_PREFIX = uint8ArrayFromString('/ipns/') const PK_PREFIX = uint8ArrayFromString('/pk/') -export function removePrivateAddresses (peer: PeerData): PeerData { +export function removePrivateAddresses (peer: PeerInfo): PeerInfo { return { ...peer, multiaddrs: peer.multiaddrs.filter(multiaddr => { @@ -29,7 +29,7 @@ export function removePrivateAddresses (peer: PeerData): PeerData { } } -export function removePublicAddresses (peer: PeerData): PeerData { +export function removePublicAddresses (peer: PeerInfo): PeerInfo { return { ...peer, multiaddrs: peer.multiaddrs.filter(multiaddr => { diff --git a/test/rpc/handlers/get-providers.spec.ts b/test/rpc/handlers/get-providers.spec.ts index 2400e476..9496218d 100644 --- a/test/rpc/handlers/get-providers.spec.ts +++ b/test/rpc/handlers/get-providers.spec.ts @@ -14,7 +14,7 @@ import { PeerRouting } from '../../../src/peer-routing/index.js' import type { PeerId } from '@libp2p/interfaces/peer-id' import { PersistentPeerStore } from '@libp2p/peer-store' import { MemoryDatastore } from 'datastore-core' -import type { PeerData } from '@libp2p/interfaces/peer-data' +import type { PeerInfo } from '@libp2p/interfaces/peer-info' import { Components } from '@libp2p/interfaces/components' const T = MESSAGE_TYPE.GET_PROVIDERS @@ -64,7 +64,7 @@ describe('rpc - handlers - GetProviders', () => { const v = values[0] const msg = new Message(T, v.cid.bytes, 0) - const closer: PeerData[] = [{ + const closer: PeerInfo[] = [{ id: closerPeer, multiaddrs: [ new Multiaddr('/ip4/127.0.0.1/tcp/4002'), @@ -74,7 +74,7 @@ describe('rpc - handlers - GetProviders', () => { protocols: [] }] - const provider: PeerData[] = [{ + const provider: PeerInfo[] = [{ id: providerPeer, multiaddrs: [ new Multiaddr('/ip4/127.0.0.1/tcp/4002'),