@libp2p/kad-dht 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@ import { Network } from './network.js';
3
3
  import { PeerRouting } from './peer-routing/index.js';
4
4
  import { Providers } from './providers.js';
5
5
  import type { QueryOptions, DHT } from '@libp2p/interfaces/dht';
6
- import type { PeerData } from '@libp2p/interfaces/peer-data';
6
+ import type { PeerInfo } from '@libp2p/interfaces/peer-info';
7
7
  import { EventEmitter } from '@libp2p/interfaces';
8
8
  import type { PeerId } from '@libp2p/interfaces/peer-id';
9
9
  import type { CID } from 'multiformats/cid';
@@ -40,7 +40,7 @@ export declare class KadDHT extends EventEmitter<PeerDiscoveryEvents> implements
40
40
  */
41
41
  constructor(init: KadDHTInit);
42
42
  init(components: Components): void;
43
- onPeerConnect(peerData: PeerData): Promise<void>;
43
+ onPeerConnect(peerData: PeerInfo): Promise<void>;
44
44
  /**
45
45
  * Is this DHT running.
46
46
  */
@@ -1,6 +1,6 @@
1
1
  import { Libp2pRecord } from '@libp2p/record';
2
2
  import Proto from './dht.js';
3
- import type { PeerData } from '@libp2p/interfaces/peer-data';
3
+ import type { PeerInfo } from '@libp2p/interfaces/peer-info';
4
4
  export declare const MESSAGE_TYPE: typeof Proto.Message.MessageType;
5
5
  export declare const CONNECTION_TYPE: typeof Proto.Message.ConnectionType;
6
6
  export declare const MESSAGE_TYPE_LOOKUP: string[];
@@ -11,8 +11,8 @@ export declare class Message {
11
11
  type: Proto.Message.MessageType;
12
12
  key: Uint8Array;
13
13
  private clusterLevelRaw;
14
- closerPeers: PeerData[];
15
- providerPeers: PeerData[];
14
+ closerPeers: PeerInfo[];
15
+ providerPeers: PeerInfo[];
16
16
  record?: Libp2pRecord;
17
17
  constructor(type: Proto.Message.MessageType, key: Uint8Array, level: number);
18
18
  /**
@@ -3,14 +3,14 @@ import { EventEmitter } from '@libp2p/interfaces';
3
3
  import type { PeerId } from '@libp2p/interfaces/peer-id';
4
4
  import type { AbortOptions, Startable } from '@libp2p/interfaces';
5
5
  import type { Duplex } from 'it-stream-types';
6
- import type { PeerData } from '@libp2p/interfaces/peer-data';
6
+ import type { PeerInfo } from '@libp2p/interfaces/peer-info';
7
7
  import { Components, Initializable } from '@libp2p/interfaces/components';
8
8
  export interface NetworkInit {
9
9
  protocol: string;
10
10
  lan: boolean;
11
11
  }
12
12
  interface NetworkEvents {
13
- 'peer': CustomEvent<PeerData>;
13
+ 'peer': CustomEvent<PeerInfo>;
14
14
  }
15
15
  /**
16
16
  * Handle network operations for the dht
@@ -10,7 +10,7 @@ export declare class PeerList {
10
10
  */
11
11
  push(peerId: PeerId): boolean;
12
12
  /**
13
- * Check if this PeerData is already in here
13
+ * Check if this PeerInfo is already in here
14
14
  */
15
15
  has(peerId: PeerId): boolean;
16
16
  /**
@@ -16,7 +16,7 @@ export class PeerList {
16
16
  return false;
17
17
  }
18
18
  /**
19
- * Check if this PeerData is already in here
19
+ * Check if this PeerInfo is already in here
20
20
  */
21
21
  has(peerId) {
22
22
  const match = this.list.find((i) => i.equals(peerId));
@@ -3,7 +3,7 @@ import type { RoutingTable } from '../routing-table/index.js';
3
3
  import type { QueryManager } from '../query/manager.js';
4
4
  import type { Network } from '../network.js';
5
5
  import type { AbortOptions } from '@libp2p/interfaces';
6
- import type { PeerData } from '@libp2p/interfaces/peer-data';
6
+ import type { PeerInfo } from '@libp2p/interfaces/peer-info';
7
7
  import type { PeerId } from '@libp2p/interfaces/peer-id';
8
8
  import { Components, Initializable } from '@libp2p/interfaces/components';
9
9
  export interface PeerRoutingInit {
@@ -64,6 +64,6 @@ export declare class PeerRouting implements Initializable {
64
64
  * Get the nearest peers to the given query, but if closer
65
65
  * than self
66
66
  */
67
- getCloserPeersOffline(key: Uint8Array, closerThan: PeerId): Promise<PeerData[]>;
67
+ getCloserPeersOffline(key: Uint8Array, closerThan: PeerId): Promise<PeerInfo[]>;
68
68
  }
69
69
  //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import type { SendingQueryEvent, PeerResponseEvent, MessageType, DialingPeerEvent, AddingPeerEvent, ValueEvent, ProviderEvent, QueryErrorEvent, FinalPeerEvent } from '@libp2p/interfaces/dht';
2
- import type { PeerData } from '@libp2p/interfaces/peer-data';
2
+ import type { PeerInfo } from '@libp2p/interfaces/peer-info';
3
3
  import type { PeerId } from '@libp2p/interfaces/peer-id';
4
4
  import type { Libp2pRecord } from '@libp2p/record';
5
5
  export interface QueryEventFields {
@@ -10,14 +10,14 @@ export declare function sendingQueryEvent(fields: QueryEventFields): SendingQuer
10
10
  export interface PeerResponseEventField {
11
11
  from: PeerId;
12
12
  messageType: MessageType;
13
- closer?: PeerData[];
14
- providers?: PeerData[];
13
+ closer?: PeerInfo[];
14
+ providers?: PeerInfo[];
15
15
  record?: Libp2pRecord;
16
16
  }
17
17
  export declare function peerResponseEvent(fields: PeerResponseEventField): PeerResponseEvent;
18
18
  export interface FinalPeerEventFields {
19
19
  from: PeerId;
20
- peer: PeerData;
20
+ peer: PeerInfo;
21
21
  }
22
22
  export declare function finalPeerEvent(fields: FinalPeerEventFields): FinalPeerEvent;
23
23
  export interface ErrorEventFields {
@@ -27,7 +27,7 @@ export interface ErrorEventFields {
27
27
  export declare function queryErrorEvent(fields: ErrorEventFields): QueryErrorEvent;
28
28
  export interface ProviderEventFields {
29
29
  from: PeerId;
30
- providers: PeerData[];
30
+ providers: PeerInfo[];
31
31
  }
32
32
  export declare function providerEvent(fields: ProviderEventFields): ProviderEvent;
33
33
  export interface ValueEventFields {
@@ -3,7 +3,7 @@ import type { DHTMessageHandler } from '../index.js';
3
3
  import type { Providers } from '../../providers.js';
4
4
  import type { PeerRouting } from '../../peer-routing/index.js';
5
5
  import type { PeerId } from '@libp2p/interfaces/peer-id';
6
- import type { PeerData } from '@libp2p/interfaces/peer-data';
6
+ import type { PeerInfo } from '@libp2p/interfaces/peer-info';
7
7
  import { Components, Initializable } from '@libp2p/interfaces/components';
8
8
  export interface GetProvidersHandlerInit {
9
9
  peerRouting: PeerRouting;
@@ -19,6 +19,6 @@ export declare class GetProvidersHandler implements DHTMessageHandler, Initializ
19
19
  init(components: Components): void;
20
20
  handle(peerId: PeerId, msg: Message): Promise<Message>;
21
21
  _getAddresses(peerId: PeerId): Promise<import("@multiformats/multiaddr/dist/src").Multiaddr[]>;
22
- _getPeers(peerIds: PeerId[]): Promise<PeerData[]>;
22
+ _getPeers(peerIds: PeerId[]): Promise<PeerInfo[]>;
23
23
  }
24
24
  //# sourceMappingURL=get-providers.d.ts.map
@@ -1,8 +1,8 @@
1
1
  import { Key } from 'interface-datastore/key';
2
- import type { PeerData } from '@libp2p/interfaces/peer-data';
2
+ import type { PeerInfo } from '@libp2p/interfaces/peer-info';
3
3
  import type { PeerId } from '@libp2p/interfaces/peer-id';
4
- export declare function removePrivateAddresses(peer: PeerData): PeerData;
5
- export declare function removePublicAddresses(peer: PeerData): PeerData;
4
+ export declare function removePrivateAddresses(peer: PeerInfo): PeerInfo;
5
+ export declare function removePublicAddresses(peer: PeerInfo): PeerInfo;
6
6
  /**
7
7
  * Creates a DHT ID by hashing a given Uint8Array
8
8
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/kad-dht",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "JavaScript implementation of the Kad-DHT for libp2p",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p-kad-dht#readme",
@@ -137,7 +137,7 @@
137
137
  },
138
138
  "dependencies": {
139
139
  "@libp2p/crypto": "^0.22.9",
140
- "@libp2p/interfaces": "^1.3.14",
140
+ "@libp2p/interfaces": "^1.3.18",
141
141
  "@libp2p/logger": "^1.1.2",
142
142
  "@libp2p/peer-id": "^1.1.8",
143
143
  "@libp2p/record": "^1.0.0",
@@ -172,9 +172,9 @@
172
172
  "varint": "^6.0.0"
173
173
  },
174
174
  "devDependencies": {
175
- "@libp2p/interface-compliance-tests": "^1.1.16",
175
+ "@libp2p/interface-compliance-tests": "^1.1.20",
176
176
  "@libp2p/peer-id-factory": "^1.0.8",
177
- "@libp2p/peer-store": "^1.0.6",
177
+ "@libp2p/peer-store": "^1.0.7",
178
178
  "@types/lodash.random": "^3.2.6",
179
179
  "@types/lodash.range": "^3.2.6",
180
180
  "@types/node": "^16.11.26",
@@ -21,7 +21,7 @@ import type { QueryFunc } from '../query/types.js'
21
21
  import type { CID } from 'multiformats/cid'
22
22
  import type { AbortOptions } from '@libp2p/interfaces'
23
23
  import type { Multiaddr } from '@multiformats/multiaddr'
24
- import type { PeerData } from '@libp2p/interfaces/peer-data'
24
+ import type { PeerInfo } from '@libp2p/interfaces/peer-info'
25
25
  import { Components, Initializable } from '@libp2p/interfaces/components'
26
26
 
27
27
  export interface ContentRoutingInit {
@@ -139,7 +139,7 @@ export class ContentRouting implements Initializable {
139
139
 
140
140
  // yield values if we have some, also slice because maybe we got lucky and already have too many?
141
141
  if (provs.length > 0) {
142
- const providers: PeerData[] = []
142
+ const providers: PeerInfo[] = []
143
143
 
144
144
  for (const peerId of provs.slice(0, toFind)) {
145
145
  providers.push({
package/src/kad-dht.ts CHANGED
@@ -15,7 +15,7 @@ import {
15
15
  } from './utils.js'
16
16
  import { Logger, logger } from '@libp2p/logger'
17
17
  import type { QueryOptions, Validators, Selectors, DHT } from '@libp2p/interfaces/dht'
18
- import type { PeerData } from '@libp2p/interfaces/peer-data'
18
+ import type { PeerInfo } from '@libp2p/interfaces/peer-info'
19
19
  import { CustomEvent, EventEmitter } from '@libp2p/interfaces'
20
20
  import type { PeerId } from '@libp2p/interfaces/peer-id'
21
21
  import type { CID } from 'multiformats/cid'
@@ -195,7 +195,7 @@ export class KadDHT extends EventEmitter<PeerDiscoveryEvents> implements DHT, In
195
195
  this.querySelf.init(components)
196
196
  }
197
197
 
198
- async onPeerConnect (peerData: PeerData) {
198
+ async onPeerConnect (peerData: PeerInfo) {
199
199
  this.log('peer %p connected', peerData.id)
200
200
 
201
201
  if (this.lan) {
@@ -2,7 +2,7 @@ import { peerIdFromBytes } from '@libp2p/peer-id'
2
2
  import { Multiaddr } from '@multiformats/multiaddr'
3
3
  import { Libp2pRecord } from '@libp2p/record'
4
4
  import Proto from './dht.js'
5
- import type { PeerData } from '@libp2p/interfaces/peer-data'
5
+ import type { PeerInfo } from '@libp2p/interfaces/peer-info'
6
6
 
7
7
  export const MESSAGE_TYPE = Proto.Message.MessageType
8
8
  export const CONNECTION_TYPE = Proto.Message.ConnectionType
@@ -23,8 +23,8 @@ export class Message {
23
23
  public type: Proto.Message.MessageType
24
24
  public key: Uint8Array
25
25
  private clusterLevelRaw: number
26
- public closerPeers: PeerData[]
27
- public providerPeers: PeerData[]
26
+ public closerPeers: PeerInfo[]
27
+ public providerPeers: PeerInfo[]
28
28
  public record?: Libp2pRecord
29
29
 
30
30
  constructor (type: Proto.Message.MessageType, key: Uint8Array, level: number) {
@@ -88,7 +88,7 @@ export class Message {
88
88
  }
89
89
  }
90
90
 
91
- function toPbPeer (peer: PeerData) {
91
+ function toPbPeer (peer: PeerInfo) {
92
92
  const output: PBPeer = {
93
93
  id: peer.id.toBytes(),
94
94
  addrs: (peer.multiaddrs ?? []).map((m) => m.bytes),
package/src/network.ts CHANGED
@@ -16,7 +16,7 @@ import type { PeerId } from '@libp2p/interfaces/peer-id'
16
16
  import type { AbortOptions, Startable } from '@libp2p/interfaces'
17
17
  import type { Logger } from '@libp2p/logger'
18
18
  import type { Duplex } from 'it-stream-types'
19
- import type { PeerData } from '@libp2p/interfaces/peer-data'
19
+ import type { PeerInfo } from '@libp2p/interfaces/peer-info'
20
20
  import { Components, Initializable } from '@libp2p/interfaces/components'
21
21
 
22
22
  export interface NetworkInit {
@@ -25,7 +25,7 @@ export interface NetworkInit {
25
25
  }
26
26
 
27
27
  interface NetworkEvents {
28
- 'peer': CustomEvent<PeerData>
28
+ 'peer': CustomEvent<PeerInfo>
29
29
  }
30
30
 
31
31
  /**
@@ -24,7 +24,7 @@ export class PeerList {
24
24
  }
25
25
 
26
26
  /**
27
- * Check if this PeerData is already in here
27
+ * Check if this PeerInfo is already in here
28
28
  */
29
29
  has (peerId: PeerId) {
30
30
  const match = this.list.find((i) => i.equals(peerId))
@@ -20,7 +20,7 @@ import type { Network } from '../network.js'
20
20
  import type { Logger } from '@libp2p/logger'
21
21
  import type { AbortOptions } from '@libp2p/interfaces'
22
22
  import type { QueryFunc } from '../query/types.js'
23
- import type { PeerData } from '@libp2p/interfaces/peer-data'
23
+ import type { PeerInfo } from '@libp2p/interfaces/peer-info'
24
24
  import type { PeerId } from '@libp2p/interfaces/peer-id'
25
25
  import { Components, Initializable } from '@libp2p/interfaces/components'
26
26
 
@@ -296,7 +296,7 @@ export class PeerRouting implements Initializable {
296
296
  async getCloserPeersOffline (key: Uint8Array, closerThan: PeerId) {
297
297
  const id = await utils.convertBuffer(key)
298
298
  const ids = this.routingTable.closestPeers(id)
299
- const output: PeerData[] = []
299
+ const output: PeerInfo[] = []
300
300
 
301
301
  for (const peerId of ids) {
302
302
  if (peerId.equals(closerThan)) {
@@ -1,6 +1,6 @@
1
1
  import { MESSAGE_TYPE_LOOKUP } from '../message/index.js'
2
2
  import type { SendingQueryEvent, PeerResponseEvent, MessageType, DialingPeerEvent, AddingPeerEvent, ValueEvent, ProviderEvent, QueryErrorEvent, FinalPeerEvent } from '@libp2p/interfaces/dht'
3
- import type { PeerData } from '@libp2p/interfaces/peer-data'
3
+ import type { PeerInfo } from '@libp2p/interfaces/peer-info'
4
4
  import type { PeerId } from '@libp2p/interfaces/peer-id'
5
5
  import type { Libp2pRecord } from '@libp2p/record'
6
6
 
@@ -32,8 +32,8 @@ export function sendingQueryEvent (fields: QueryEventFields): SendingQueryEvent
32
32
  export interface PeerResponseEventField {
33
33
  from: PeerId
34
34
  messageType: MessageType
35
- closer?: PeerData[]
36
- providers?: PeerData[]
35
+ closer?: PeerInfo[]
36
+ providers?: PeerInfo[]
37
37
  record?: Libp2pRecord
38
38
  }
39
39
 
@@ -51,7 +51,7 @@ export function peerResponseEvent (fields: PeerResponseEventField): PeerResponse
51
51
 
52
52
  export interface FinalPeerEventFields {
53
53
  from: PeerId
54
- peer: PeerData
54
+ peer: PeerInfo
55
55
  }
56
56
 
57
57
  export function finalPeerEvent (fields: FinalPeerEventFields): FinalPeerEvent {
@@ -77,7 +77,7 @@ export function queryErrorEvent (fields: ErrorEventFields): QueryErrorEvent {
77
77
 
78
78
  export interface ProviderEventFields {
79
79
  from: PeerId
80
- providers: PeerData[]
80
+ providers: PeerInfo[]
81
81
  }
82
82
 
83
83
  export function providerEvent (fields: ProviderEventFields): ProviderEvent {
@@ -10,7 +10,7 @@ import type { DHTMessageHandler } from '../index.js'
10
10
  import type { Providers } from '../../providers.js'
11
11
  import type { PeerRouting } from '../../peer-routing/index.js'
12
12
  import type { PeerId } from '@libp2p/interfaces/peer-id'
13
- import type { PeerData } from '@libp2p/interfaces/peer-data'
13
+ import type { PeerInfo } from '@libp2p/interfaces/peer-info'
14
14
  import { Components, Initializable } from '@libp2p/interfaces/components'
15
15
 
16
16
  const log = logger('libp2p:kad-dht:rpc:handlers:get-providers')
@@ -77,7 +77,7 @@ export class GetProvidersHandler implements DHTMessageHandler, Initializable {
77
77
  }
78
78
 
79
79
  async _getPeers (peerIds: PeerId[]) {
80
- const output: PeerData[] = []
80
+ const output: PeerInfo[] = []
81
81
  const addrFilter = this.lan ? removePublicAddresses : removePrivateAddresses
82
82
 
83
83
  for (const peerId of peerIds) {
package/src/utils.ts CHANGED
@@ -5,7 +5,7 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
5
5
  import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
6
6
  import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
7
7
  import isPrivateIp from 'private-ip'
8
- import type { PeerData } from '@libp2p/interfaces/peer-data'
8
+ import type { PeerInfo } from '@libp2p/interfaces/peer-info'
9
9
  import { peerIdFromBytes } from '@libp2p/peer-id'
10
10
  import type { PeerId } from '@libp2p/interfaces/peer-id'
11
11
  import { RECORD_KEY_PREFIX } from './constants.js'
@@ -13,7 +13,7 @@ import { RECORD_KEY_PREFIX } from './constants.js'
13
13
  // const IPNS_PREFIX = uint8ArrayFromString('/ipns/')
14
14
  const PK_PREFIX = uint8ArrayFromString('/pk/')
15
15
 
16
- export function removePrivateAddresses (peer: PeerData): PeerData {
16
+ export function removePrivateAddresses (peer: PeerInfo): PeerInfo {
17
17
  return {
18
18
  ...peer,
19
19
  multiaddrs: peer.multiaddrs.filter(multiaddr => {
@@ -29,7 +29,7 @@ export function removePrivateAddresses (peer: PeerData): PeerData {
29
29
  }
30
30
  }
31
31
 
32
- export function removePublicAddresses (peer: PeerData): PeerData {
32
+ export function removePublicAddresses (peer: PeerInfo): PeerInfo {
33
33
  return {
34
34
  ...peer,
35
35
  multiaddrs: peer.multiaddrs.filter(multiaddr => {