@libp2p/kad-dht 1.0.16 → 3.0.1
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.
- package/README.md +18 -22
- package/dist/src/content-fetching/index.d.ts +6 -6
- package/dist/src/content-fetching/index.d.ts.map +1 -1
- package/dist/src/content-fetching/index.js +1 -1
- package/dist/src/content-fetching/index.js.map +1 -1
- package/dist/src/content-routing/index.d.ts +3 -3
- package/dist/src/content-routing/index.d.ts.map +1 -1
- package/dist/src/content-routing/index.js +1 -1
- package/dist/src/content-routing/index.js.map +1 -1
- package/dist/src/dual-kad-dht.d.ts +11 -11
- package/dist/src/dual-kad-dht.d.ts.map +1 -1
- package/dist/src/dual-kad-dht.js +2 -2
- package/dist/src/dual-kad-dht.js.map +1 -1
- package/dist/src/index.d.ts +9 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/kad-dht.d.ts +16 -12
- package/dist/src/kad-dht.d.ts.map +1 -1
- package/dist/src/kad-dht.js +11 -4
- package/dist/src/kad-dht.js.map +1 -1
- package/dist/src/message/dht.d.ts +7 -6
- package/dist/src/message/dht.d.ts.map +1 -1
- package/dist/src/message/dht.js.map +1 -1
- package/dist/src/message/index.d.ts +4 -3
- package/dist/src/message/index.d.ts.map +1 -1
- package/dist/src/message/index.js.map +1 -1
- package/dist/src/network.d.ts +8 -7
- package/dist/src/network.d.ts.map +1 -1
- package/dist/src/network.js +3 -5
- package/dist/src/network.js.map +1 -1
- package/dist/src/peer-list/index.d.ts +1 -1
- package/dist/src/peer-list/index.d.ts.map +1 -1
- package/dist/src/peer-list/peer-distance-list.d.ts +1 -1
- package/dist/src/peer-list/peer-distance-list.d.ts.map +1 -1
- package/dist/src/peer-routing/index.d.ts +9 -9
- package/dist/src/peer-routing/index.d.ts.map +1 -1
- package/dist/src/peer-routing/index.js +1 -1
- package/dist/src/peer-routing/index.js.map +1 -1
- package/dist/src/providers.d.ts +2 -2
- package/dist/src/providers.d.ts.map +1 -1
- package/dist/src/providers.js +1 -1
- package/dist/src/providers.js.map +1 -1
- package/dist/src/query/events.d.ts +3 -3
- package/dist/src/query/events.d.ts.map +1 -1
- package/dist/src/query/manager.d.ts +4 -4
- package/dist/src/query/manager.d.ts.map +1 -1
- package/dist/src/query/manager.js +1 -1
- package/dist/src/query/manager.js.map +1 -1
- package/dist/src/query/query-path.d.ts +2 -2
- package/dist/src/query/query-path.d.ts.map +1 -1
- package/dist/src/query/types.d.ts +2 -2
- package/dist/src/query/types.d.ts.map +1 -1
- package/dist/src/query-self.d.ts +1 -1
- package/dist/src/query-self.d.ts.map +1 -1
- package/dist/src/query-self.js +1 -1
- package/dist/src/query-self.js.map +1 -1
- package/dist/src/routing-table/index.d.ts +2 -2
- package/dist/src/routing-table/index.d.ts.map +1 -1
- package/dist/src/routing-table/index.js +2 -2
- package/dist/src/routing-table/index.js.map +1 -1
- package/dist/src/routing-table/refresh.d.ts +2 -2
- package/dist/src/routing-table/refresh.d.ts.map +1 -1
- package/dist/src/rpc/handlers/add-provider.d.ts +2 -2
- package/dist/src/rpc/handlers/add-provider.d.ts.map +1 -1
- package/dist/src/rpc/handlers/find-node.d.ts +3 -3
- package/dist/src/rpc/handlers/find-node.d.ts.map +1 -1
- package/dist/src/rpc/handlers/find-node.js +1 -1
- package/dist/src/rpc/handlers/find-node.js.map +1 -1
- package/dist/src/rpc/handlers/get-providers.d.ts +3 -3
- package/dist/src/rpc/handlers/get-providers.d.ts.map +1 -1
- package/dist/src/rpc/handlers/get-providers.js +1 -1
- package/dist/src/rpc/handlers/get-providers.js.map +1 -1
- package/dist/src/rpc/handlers/get-value.d.ts +2 -2
- package/dist/src/rpc/handlers/get-value.d.ts.map +1 -1
- package/dist/src/rpc/handlers/get-value.js +1 -1
- package/dist/src/rpc/handlers/get-value.js.map +1 -1
- package/dist/src/rpc/handlers/ping.d.ts +2 -2
- package/dist/src/rpc/handlers/ping.d.ts.map +1 -1
- package/dist/src/rpc/handlers/put-value.d.ts +3 -3
- package/dist/src/rpc/handlers/put-value.d.ts.map +1 -1
- package/dist/src/rpc/handlers/put-value.js +1 -1
- package/dist/src/rpc/handlers/put-value.js.map +1 -1
- package/dist/src/rpc/index.d.ts +4 -4
- package/dist/src/rpc/index.d.ts.map +1 -1
- package/dist/src/topology-listener.d.ts +2 -2
- package/dist/src/topology-listener.d.ts.map +1 -1
- package/dist/src/topology-listener.js +1 -1
- package/dist/src/topology-listener.js.map +1 -1
- package/dist/src/utils.d.ts +2 -2
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +3 -3
- package/dist/src/utils.js.map +1 -1
- package/package.json +32 -16
- package/src/content-fetching/index.ts +2 -2
- package/src/content-routing/index.ts +3 -3
- package/src/dual-kad-dht.ts +5 -5
- package/src/index.ts +11 -1
- package/src/kad-dht.ts +20 -8
- package/src/message/dht.ts +7 -6
- package/src/message/index.ts +3 -2
- package/src/network.ts +9 -10
- package/src/peer-list/index.ts +1 -1
- package/src/peer-list/peer-distance-list.ts +1 -1
- package/src/peer-routing/index.ts +4 -4
- package/src/providers.ts +2 -2
- package/src/query/events.ts +3 -3
- package/src/query/manager.ts +3 -3
- package/src/query/query-path.ts +2 -2
- package/src/query/types.ts +2 -2
- package/src/query-self.ts +1 -1
- package/src/routing-table/index.ts +3 -3
- package/src/routing-table/refresh.ts +1 -1
- package/src/rpc/handlers/add-provider.ts +2 -2
- package/src/rpc/handlers/find-node.ts +4 -4
- package/src/rpc/handlers/get-providers.ts +3 -3
- package/src/rpc/handlers/get-value.ts +2 -2
- package/src/rpc/handlers/ping.ts +2 -2
- package/src/rpc/handlers/put-value.ts +3 -3
- package/src/rpc/index.ts +4 -4
- package/src/topology-listener.ts +2 -2
- package/src/utils.ts +5 -5
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
providerEvent
|
|
11
11
|
} from '../query/events.js'
|
|
12
12
|
import { logger } from '@libp2p/logger'
|
|
13
|
-
import type { QueryEvent, QueryOptions } from '@libp2p/
|
|
13
|
+
import type { QueryEvent, QueryOptions } from '@libp2p/interface-dht'
|
|
14
14
|
import type { PeerRouting } from '../peer-routing/index.js'
|
|
15
15
|
import type { QueryManager } from '../query/manager.js'
|
|
16
16
|
import type { RoutingTable } from '../routing-table/index.js'
|
|
@@ -21,8 +21,8 @@ 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 { PeerInfo } from '@libp2p/
|
|
25
|
-
import { Components, Initializable } from '@libp2p/
|
|
24
|
+
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
25
|
+
import { Components, Initializable } from '@libp2p/components'
|
|
26
26
|
|
|
27
27
|
export interface ContentRoutingInit {
|
|
28
28
|
network: Network
|
package/src/dual-kad-dht.ts
CHANGED
|
@@ -3,14 +3,14 @@ import errCode from 'err-code'
|
|
|
3
3
|
import merge from 'it-merge'
|
|
4
4
|
import { queryErrorEvent } from './query/events.js'
|
|
5
5
|
import type { KadDHT } from './kad-dht.js'
|
|
6
|
-
import type { DualDHT, QueryOptions } from '@libp2p/
|
|
6
|
+
import type { DualDHT, QueryOptions } from '@libp2p/interface-dht'
|
|
7
7
|
import type { AbortOptions } from '@libp2p/interfaces'
|
|
8
8
|
import { EventEmitter, CustomEvent } from '@libp2p/interfaces/events'
|
|
9
9
|
import type { CID } from 'multiformats'
|
|
10
|
-
import type { PeerId } from '@libp2p/
|
|
11
|
-
import type { PeerDiscoveryEvents } from '@libp2p/
|
|
12
|
-
import { Components, Initializable } from '@libp2p/
|
|
13
|
-
import { symbol } from '@libp2p/
|
|
10
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
11
|
+
import type { PeerDiscoveryEvents } from '@libp2p/interface-peer-discovery'
|
|
12
|
+
import { Components, Initializable } from '@libp2p/components'
|
|
13
|
+
import { symbol } from '@libp2p/interface-peer-discovery'
|
|
14
14
|
|
|
15
15
|
const log = logger('libp2p:kad-dht')
|
|
16
16
|
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { KadDHT as SingleKadDHT } from './kad-dht.js'
|
|
2
2
|
import { DualKadDHT } from './dual-kad-dht.js'
|
|
3
|
-
import type { Selectors, Validators } from '@libp2p/
|
|
3
|
+
import type { Selectors, Validators } from '@libp2p/interface-dht'
|
|
4
4
|
|
|
5
5
|
export interface KadDHTInit {
|
|
6
6
|
/**
|
|
@@ -45,6 +45,16 @@ export interface KadDHTInit {
|
|
|
45
45
|
* be evicted from the routing table or not (default 10)
|
|
46
46
|
*/
|
|
47
47
|
pingConcurrency?: number
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* How many parallel incoming streams to allow on the DHT protocol per-connection
|
|
51
|
+
*/
|
|
52
|
+
maxInboundStreams?: number
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* How many parallel outgoing streams to allow on the DHT protocol per-connection
|
|
56
|
+
*/
|
|
57
|
+
maxOutboundStreams?: number
|
|
48
58
|
}
|
|
49
59
|
|
|
50
60
|
export class KadDHT extends DualKadDHT {
|
package/src/kad-dht.ts
CHANGED
|
@@ -14,19 +14,22 @@ import {
|
|
|
14
14
|
removePublicAddresses
|
|
15
15
|
} from './utils.js'
|
|
16
16
|
import { Logger, logger } from '@libp2p/logger'
|
|
17
|
-
import type { QueryOptions, Validators, Selectors, DHT } from '@libp2p/
|
|
18
|
-
import type { PeerInfo } from '@libp2p/
|
|
17
|
+
import type { QueryOptions, Validators, Selectors, DHT } from '@libp2p/interface-dht'
|
|
18
|
+
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
19
19
|
import { CustomEvent, EventEmitter } from '@libp2p/interfaces/events'
|
|
20
|
-
import type { PeerId } from '@libp2p/
|
|
20
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
21
21
|
import type { CID } from 'multiformats/cid'
|
|
22
|
-
import type { PeerDiscoveryEvents } from '@libp2p/
|
|
23
|
-
import { Components, Initializable } from '@libp2p/
|
|
22
|
+
import type { PeerDiscoveryEvents } from '@libp2p/interface-peer-discovery'
|
|
23
|
+
import { Components, Initializable } from '@libp2p/components'
|
|
24
24
|
import type { KadDHTInit } from './index.js'
|
|
25
25
|
import { validators as recordValidators } from '@libp2p/record/validators'
|
|
26
26
|
import { selectors as recordSelectors } from '@libp2p/record/selectors'
|
|
27
|
-
import { symbol } from '@libp2p/
|
|
27
|
+
import { symbol } from '@libp2p/interface-peer-discovery'
|
|
28
28
|
import { PROTOCOL_DHT, PROTOCOL_PREFIX, LAN_PREFIX } from './constants.js'
|
|
29
29
|
|
|
30
|
+
export const DEFAULT_MAX_INBOUND_STREAMS = 32
|
|
31
|
+
export const DEFAULT_MAX_OUTBOUND_STREAMS = 64
|
|
32
|
+
|
|
30
33
|
export interface SingleKadDHTInit extends KadDHTInit {
|
|
31
34
|
/**
|
|
32
35
|
* Whether to start up in lan or wan mode
|
|
@@ -60,6 +63,8 @@ export class KadDHT extends EventEmitter<PeerDiscoveryEvents> implements DHT, In
|
|
|
60
63
|
private readonly rpc: RPC
|
|
61
64
|
private readonly topologyListener: TopologyListener
|
|
62
65
|
private readonly querySelf: QuerySelf
|
|
66
|
+
private readonly maxInboundStreams: number
|
|
67
|
+
private readonly maxOutboundStreams: number
|
|
63
68
|
|
|
64
69
|
/**
|
|
65
70
|
* Create a new KadDHT
|
|
@@ -76,7 +81,9 @@ export class KadDHT extends EventEmitter<PeerDiscoveryEvents> implements DHT, In
|
|
|
76
81
|
lan,
|
|
77
82
|
protocolPrefix,
|
|
78
83
|
pingTimeout,
|
|
79
|
-
pingConcurrency
|
|
84
|
+
pingConcurrency,
|
|
85
|
+
maxInboundStreams,
|
|
86
|
+
maxOutboundStreams
|
|
80
87
|
} = init
|
|
81
88
|
|
|
82
89
|
this.running = false
|
|
@@ -85,6 +92,8 @@ export class KadDHT extends EventEmitter<PeerDiscoveryEvents> implements DHT, In
|
|
|
85
92
|
this.protocol = `${protocolPrefix ?? PROTOCOL_PREFIX}${lan === true ? LAN_PREFIX : ''}${PROTOCOL_DHT}`
|
|
86
93
|
this.kBucketSize = kBucketSize ?? 20
|
|
87
94
|
this.clientMode = clientMode ?? true
|
|
95
|
+
this.maxInboundStreams = maxInboundStreams ?? DEFAULT_MAX_INBOUND_STREAMS
|
|
96
|
+
this.maxOutboundStreams = maxOutboundStreams ?? DEFAULT_MAX_OUTBOUND_STREAMS
|
|
88
97
|
this.routingTable = new RoutingTable({
|
|
89
98
|
kBucketSize,
|
|
90
99
|
lan: this.lan,
|
|
@@ -264,7 +273,10 @@ export class KadDHT extends EventEmitter<PeerDiscoveryEvents> implements DHT, In
|
|
|
264
273
|
} else {
|
|
265
274
|
this.log('enabling server mode')
|
|
266
275
|
this.clientMode = false
|
|
267
|
-
await this.components.getRegistrar().handle(this.protocol, this.rpc.onIncomingStream.bind(this.rpc)
|
|
276
|
+
await this.components.getRegistrar().handle(this.protocol, this.rpc.onIncomingStream.bind(this.rpc), {
|
|
277
|
+
maxInboundStreams: this.maxInboundStreams,
|
|
278
|
+
maxOutboundStreams: this.maxOutboundStreams
|
|
279
|
+
})
|
|
268
280
|
}
|
|
269
281
|
}
|
|
270
282
|
|
package/src/message/dht.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { encodeMessage, decodeMessage, message, bytes, string, enumeration, int32 } from 'protons-runtime'
|
|
5
5
|
import type { Codec } from 'protons-runtime'
|
|
6
|
+
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
6
7
|
|
|
7
8
|
export interface Record {
|
|
8
9
|
key?: Uint8Array
|
|
@@ -23,11 +24,11 @@ export namespace Record {
|
|
|
23
24
|
})
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
export const encode = (obj: Record):
|
|
27
|
+
export const encode = (obj: Record): Uint8ArrayList => {
|
|
27
28
|
return encodeMessage(obj, Record.codec())
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
export const decode = (buf: Uint8Array): Record => {
|
|
31
|
+
export const decode = (buf: Uint8Array | Uint8ArrayList): Record => {
|
|
31
32
|
return decodeMessage(buf, Record.codec())
|
|
32
33
|
}
|
|
33
34
|
}
|
|
@@ -101,11 +102,11 @@ export namespace Message {
|
|
|
101
102
|
})
|
|
102
103
|
}
|
|
103
104
|
|
|
104
|
-
export const encode = (obj: Peer):
|
|
105
|
+
export const encode = (obj: Peer): Uint8ArrayList => {
|
|
105
106
|
return encodeMessage(obj, Peer.codec())
|
|
106
107
|
}
|
|
107
108
|
|
|
108
|
-
export const decode = (buf: Uint8Array): Peer => {
|
|
109
|
+
export const decode = (buf: Uint8Array | Uint8ArrayList): Peer => {
|
|
109
110
|
return decodeMessage(buf, Peer.codec())
|
|
110
111
|
}
|
|
111
112
|
}
|
|
@@ -121,11 +122,11 @@ export namespace Message {
|
|
|
121
122
|
})
|
|
122
123
|
}
|
|
123
124
|
|
|
124
|
-
export const encode = (obj: Message):
|
|
125
|
+
export const encode = (obj: Message): Uint8ArrayList => {
|
|
125
126
|
return encodeMessage(obj, Message.codec())
|
|
126
127
|
}
|
|
127
128
|
|
|
128
|
-
export const decode = (buf: Uint8Array): Message => {
|
|
129
|
+
export const decode = (buf: Uint8Array | Uint8ArrayList): Message => {
|
|
129
130
|
return decodeMessage(buf, Message.codec())
|
|
130
131
|
}
|
|
131
132
|
}
|
package/src/message/index.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { peerIdFromBytes } from '@libp2p/peer-id'
|
|
|
2
2
|
import { Multiaddr } from '@multiformats/multiaddr'
|
|
3
3
|
import { Libp2pRecord } from '@libp2p/record'
|
|
4
4
|
import { Message as PBMessage } from './dht.js'
|
|
5
|
-
import type { PeerInfo } from '@libp2p/
|
|
5
|
+
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
6
|
+
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
6
7
|
|
|
7
8
|
export const MESSAGE_TYPE = PBMessage.MessageType
|
|
8
9
|
export const CONNECTION_TYPE = PBMessage.ConnectionType
|
|
@@ -71,7 +72,7 @@ export class Message {
|
|
|
71
72
|
/**
|
|
72
73
|
* Decode from protobuf
|
|
73
74
|
*/
|
|
74
|
-
static deserialize (raw: Uint8Array) {
|
|
75
|
+
static deserialize (raw: Uint8ArrayList | Uint8Array) {
|
|
75
76
|
const dec = PBMessage.decode(raw)
|
|
76
77
|
|
|
77
78
|
const msg = new Message(dec.type ?? PBMessage.MessageType.PUT_VALUE, dec.key ?? Uint8Array.from([]), dec.clusterLevelRaw ?? 0)
|
package/src/network.ts
CHANGED
|
@@ -12,15 +12,16 @@ import {
|
|
|
12
12
|
queryErrorEvent
|
|
13
13
|
} from './query/events.js'
|
|
14
14
|
import { logger } from '@libp2p/logger'
|
|
15
|
-
import type { PeerId } from '@libp2p/
|
|
15
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
16
16
|
import type { AbortOptions } from '@libp2p/interfaces'
|
|
17
17
|
import type { Startable } from '@libp2p/interfaces/startable'
|
|
18
18
|
import type { Logger } from '@libp2p/logger'
|
|
19
19
|
import type { Duplex } from 'it-stream-types'
|
|
20
|
-
import type { PeerInfo } from '@libp2p/
|
|
21
|
-
import { Components, Initializable } from '@libp2p/
|
|
22
|
-
import type { Stream } from '@libp2p/
|
|
20
|
+
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
21
|
+
import { Components, Initializable } from '@libp2p/components'
|
|
22
|
+
import type { Stream } from '@libp2p/interface-connection'
|
|
23
23
|
import { abortableDuplex } from 'abortable-iterator'
|
|
24
|
+
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
24
25
|
|
|
25
26
|
export interface NetworkInit {
|
|
26
27
|
protocol: string
|
|
@@ -97,8 +98,7 @@ export class Network extends EventEmitter<NetworkEvents> implements Startable, I
|
|
|
97
98
|
|
|
98
99
|
try {
|
|
99
100
|
const connection = await this.components.getConnectionManager().openConnection(to, options)
|
|
100
|
-
const
|
|
101
|
-
stream = streamData.stream
|
|
101
|
+
const stream = await connection.newStream(this.protocol, options)
|
|
102
102
|
|
|
103
103
|
const response = await this._writeReadMessage(stream, msg.serialize(), options)
|
|
104
104
|
|
|
@@ -134,8 +134,7 @@ export class Network extends EventEmitter<NetworkEvents> implements Startable, I
|
|
|
134
134
|
|
|
135
135
|
try {
|
|
136
136
|
const connection = await this.components.getConnectionManager().openConnection(to, options)
|
|
137
|
-
const
|
|
138
|
-
stream = data.stream
|
|
137
|
+
const stream = await connection.newStream(this.protocol, options)
|
|
139
138
|
|
|
140
139
|
await this._writeMessage(stream, msg.serialize(), options)
|
|
141
140
|
|
|
@@ -152,7 +151,7 @@ export class Network extends EventEmitter<NetworkEvents> implements Startable, I
|
|
|
152
151
|
/**
|
|
153
152
|
* Write a message to the given stream
|
|
154
153
|
*/
|
|
155
|
-
async _writeMessage (stream: Duplex<Uint8Array>, msg: Uint8Array, options: AbortOptions) {
|
|
154
|
+
async _writeMessage (stream: Duplex<Uint8Array>, msg: Uint8Array | Uint8ArrayList, options: AbortOptions) {
|
|
156
155
|
if (options.signal != null) {
|
|
157
156
|
stream = abortableDuplex(stream, options.signal)
|
|
158
157
|
}
|
|
@@ -170,7 +169,7 @@ export class Network extends EventEmitter<NetworkEvents> implements Startable, I
|
|
|
170
169
|
* If no response is received after the specified timeout
|
|
171
170
|
* this will error out.
|
|
172
171
|
*/
|
|
173
|
-
async _writeReadMessage (stream: Duplex<Uint8Array>, msg: Uint8Array, options: AbortOptions) {
|
|
172
|
+
async _writeReadMessage (stream: Duplex<Uint8Array>, msg: Uint8Array | Uint8ArrayList, options: AbortOptions) {
|
|
174
173
|
if (options.signal != null) {
|
|
175
174
|
stream = abortableDuplex(stream, options.signal)
|
|
176
175
|
}
|
package/src/peer-list/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as utils from '../utils.js'
|
|
2
2
|
import { compare as uint8ArrayCompare } from 'uint8arrays/compare'
|
|
3
3
|
import { xor as uint8ArrayXor } from 'uint8arrays/xor'
|
|
4
|
-
import type { PeerId } from '@libp2p/
|
|
4
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
5
5
|
|
|
6
6
|
interface PeerDistance {
|
|
7
7
|
peerId: PeerId
|
|
@@ -13,16 +13,16 @@ import { Libp2pRecord } from '@libp2p/record'
|
|
|
13
13
|
import { logger } from '@libp2p/logger'
|
|
14
14
|
import { keys } from '@libp2p/crypto'
|
|
15
15
|
import { peerIdFromKeys } from '@libp2p/peer-id'
|
|
16
|
-
import type { DHTRecord, QueryOptions, Validators } from '@libp2p/
|
|
16
|
+
import type { DHTRecord, QueryOptions, Validators } from '@libp2p/interface-dht'
|
|
17
17
|
import type { RoutingTable } from '../routing-table/index.js'
|
|
18
18
|
import type { QueryManager } from '../query/manager.js'
|
|
19
19
|
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 { PeerInfo } from '@libp2p/
|
|
24
|
-
import type { PeerId } from '@libp2p/
|
|
25
|
-
import { Components, Initializable } from '@libp2p/
|
|
23
|
+
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
24
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
25
|
+
import { Components, Initializable } from '@libp2p/components'
|
|
26
26
|
|
|
27
27
|
export interface PeerRoutingInit {
|
|
28
28
|
routingTable: RoutingTable
|
package/src/providers.ts
CHANGED
|
@@ -14,8 +14,8 @@ import { peerIdFromString } from '@libp2p/peer-id'
|
|
|
14
14
|
import type { Datastore } from 'interface-datastore'
|
|
15
15
|
import type { Startable } from '@libp2p/interfaces/startable'
|
|
16
16
|
import type { CID } from 'multiformats'
|
|
17
|
-
import type { PeerId } from '@libp2p/
|
|
18
|
-
import { Components, Initializable } from '@libp2p/
|
|
17
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
18
|
+
import { Components, Initializable } from '@libp2p/components'
|
|
19
19
|
|
|
20
20
|
const log = logger('libp2p:kad-dht:providers')
|
|
21
21
|
|
package/src/query/events.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { MESSAGE_TYPE_LOOKUP } from '../message/index.js'
|
|
2
2
|
import type { Message } from '../message/dht.js'
|
|
3
|
-
import type { SendingQueryEvent, PeerResponseEvent, DialingPeerEvent, AddingPeerEvent, ValueEvent, ProviderEvent, QueryErrorEvent, FinalPeerEvent } from '@libp2p/
|
|
4
|
-
import type { PeerInfo } from '@libp2p/
|
|
5
|
-
import type { PeerId } from '@libp2p/
|
|
3
|
+
import type { SendingQueryEvent, PeerResponseEvent, DialingPeerEvent, AddingPeerEvent, ValueEvent, ProviderEvent, QueryErrorEvent, FinalPeerEvent } from '@libp2p/interface-dht'
|
|
4
|
+
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
5
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
6
6
|
import type { Libp2pRecord } from '@libp2p/record'
|
|
7
7
|
|
|
8
8
|
export interface QueryEventFields {
|
package/src/query/manager.ts
CHANGED
|
@@ -9,11 +9,11 @@ import merge from 'it-merge'
|
|
|
9
9
|
import { setMaxListeners } from 'events'
|
|
10
10
|
import { EventEmitter, CustomEvent } from '@libp2p/interfaces/events'
|
|
11
11
|
import { logger } from '@libp2p/logger'
|
|
12
|
-
import type { PeerId } from '@libp2p/
|
|
12
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
13
13
|
import type { Startable } from '@libp2p/interfaces/startable'
|
|
14
14
|
import type { QueryFunc } from './types.js'
|
|
15
|
-
import type { QueryOptions } from '@libp2p/
|
|
16
|
-
import { Components, Initializable } from '@libp2p/
|
|
15
|
+
import type { QueryOptions } from '@libp2p/interface-dht'
|
|
16
|
+
import { Components, Initializable } from '@libp2p/components'
|
|
17
17
|
|
|
18
18
|
const METRIC_RUNNING_QUERIES = 'running-queries'
|
|
19
19
|
|
package/src/query/query-path.ts
CHANGED
|
@@ -7,12 +7,12 @@ import { convertPeerId, convertBuffer } from '../utils.js'
|
|
|
7
7
|
import { TimeoutController } from 'timeout-abort-controller'
|
|
8
8
|
import { anySignal } from 'any-signal'
|
|
9
9
|
import { queryErrorEvent } from './events.js'
|
|
10
|
-
import type { PeerId } from '@libp2p/
|
|
10
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
11
11
|
import type { EventEmitter } from '@libp2p/interfaces/events'
|
|
12
12
|
import type { CleanUpEvents } from './manager.js'
|
|
13
13
|
import type { Logger } from '@libp2p/logger'
|
|
14
14
|
import type { QueryFunc } from '../query/types.js'
|
|
15
|
-
import type { QueryEvent } from '@libp2p/
|
|
15
|
+
import type { QueryEvent } from '@libp2p/interface-dht'
|
|
16
16
|
|
|
17
17
|
const MAX_XOR = BigInt('0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF')
|
|
18
18
|
|
package/src/query/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { PeerId } from '@libp2p/
|
|
2
|
-
import type { QueryEvent } from '@libp2p/
|
|
1
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
2
|
+
import type { QueryEvent } from '@libp2p/interface-dht'
|
|
3
3
|
|
|
4
4
|
export interface QueryContext {
|
|
5
5
|
// the key we are looking up
|
package/src/query-self.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { logger, Logger } from '@libp2p/logger'
|
|
|
8
8
|
import type { PeerRouting } from './peer-routing/index.js'
|
|
9
9
|
import type { Startable } from '@libp2p/interfaces/startable'
|
|
10
10
|
import { pipe } from 'it-pipe'
|
|
11
|
-
import { Components, Initializable } from '@libp2p/
|
|
11
|
+
import { Components, Initializable } from '@libp2p/components'
|
|
12
12
|
|
|
13
13
|
export interface QuerySelfInit {
|
|
14
14
|
lan: boolean
|
|
@@ -4,10 +4,10 @@ import * as utils from '../utils.js'
|
|
|
4
4
|
import Queue from 'p-queue'
|
|
5
5
|
import { TimeoutController } from 'timeout-abort-controller'
|
|
6
6
|
import { logger } from '@libp2p/logger'
|
|
7
|
-
import type { PeerId } from '@libp2p/
|
|
7
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
8
8
|
import type { Startable } from '@libp2p/interfaces/startable'
|
|
9
9
|
import type { Logger } from '@libp2p/logger'
|
|
10
|
-
import { Components, Initializable } from '@libp2p/
|
|
10
|
+
import { Components, Initializable } from '@libp2p/components'
|
|
11
11
|
|
|
12
12
|
export interface KBucketPeer {
|
|
13
13
|
id: Uint8Array
|
|
@@ -158,7 +158,7 @@ export class RoutingTable implements Startable, Initializable {
|
|
|
158
158
|
|
|
159
159
|
this.log('pinging old contact %p', oldContact.peer)
|
|
160
160
|
const connection = await this.components.getConnectionManager().openConnection(oldContact.peer, options)
|
|
161
|
-
const
|
|
161
|
+
const stream = await connection.newStream(this.protocol, options)
|
|
162
162
|
stream.close()
|
|
163
163
|
responded++
|
|
164
164
|
} catch (err: any) {
|
|
@@ -10,7 +10,7 @@ import { TABLE_REFRESH_INTERVAL, TABLE_REFRESH_QUERY_TIMEOUT } from '../constant
|
|
|
10
10
|
import type { RoutingTable } from './index.js'
|
|
11
11
|
import type { Logger } from '@libp2p/logger'
|
|
12
12
|
import type { PeerRouting } from '../peer-routing/index.js'
|
|
13
|
-
import type { Components, Initializable } from '@libp2p/
|
|
13
|
+
import type { Components, Initializable } from '@libp2p/components'
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Cannot generate random KadIds longer than this + 1
|
|
@@ -2,10 +2,10 @@ import { CID } from 'multiformats/cid'
|
|
|
2
2
|
import errcode from 'err-code'
|
|
3
3
|
import { logger } from '@libp2p/logger'
|
|
4
4
|
import type { Providers } from '../../providers'
|
|
5
|
-
import type { PeerId } from '@libp2p/
|
|
5
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
6
6
|
import type { DHTMessageHandler } from '../index.js'
|
|
7
7
|
import type { Message } from '../../message/index.js'
|
|
8
|
-
import type { Initializable } from '@libp2p/
|
|
8
|
+
import type { Initializable } from '@libp2p/components'
|
|
9
9
|
|
|
10
10
|
const log = logger('libp2p:kad-dht:rpc:handlers:add-provider')
|
|
11
11
|
|
|
@@ -5,13 +5,13 @@ import {
|
|
|
5
5
|
removePublicAddresses
|
|
6
6
|
} from '../../utils.js'
|
|
7
7
|
import { equals as uint8ArrayEquals } from 'uint8arrays'
|
|
8
|
-
import { Components } from '@libp2p/
|
|
8
|
+
import { Components } from '@libp2p/components'
|
|
9
9
|
import { protocols } from '@multiformats/multiaddr'
|
|
10
|
-
import type { Initializable } from '@libp2p/
|
|
11
|
-
import type { PeerInfo } from '@libp2p/
|
|
10
|
+
import type { Initializable } from '@libp2p/components'
|
|
11
|
+
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
12
12
|
import type { DHTMessageHandler } from '../index.js'
|
|
13
13
|
import type { PeerRouting } from '../../peer-routing/index.js'
|
|
14
|
-
import type { PeerId } from '@libp2p/
|
|
14
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
15
15
|
|
|
16
16
|
const log = logger('libp2p:kad-dht:rpc:handlers:find-node')
|
|
17
17
|
|
|
@@ -9,9 +9,9 @@ import { logger } from '@libp2p/logger'
|
|
|
9
9
|
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
|
-
import type { PeerId } from '@libp2p/
|
|
13
|
-
import type { PeerInfo } from '@libp2p/
|
|
14
|
-
import { Components, Initializable } from '@libp2p/
|
|
12
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
13
|
+
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
14
|
+
import { Components, Initializable } from '@libp2p/components'
|
|
15
15
|
|
|
16
16
|
const log = logger('libp2p:kad-dht:rpc:handlers:get-providers')
|
|
17
17
|
|
|
@@ -7,9 +7,9 @@ import {
|
|
|
7
7
|
import { bufferToRecordKey, isPublicKeyKey, fromPublicKeyKey } from '../../utils.js'
|
|
8
8
|
import { logger } from '@libp2p/logger'
|
|
9
9
|
import type { DHTMessageHandler } from '../index.js'
|
|
10
|
-
import type { PeerId } from '@libp2p/
|
|
10
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
11
11
|
import type { PeerRouting } from '../../peer-routing/index.js'
|
|
12
|
-
import { Components, Initializable } from '@libp2p/
|
|
12
|
+
import { Components, Initializable } from '@libp2p/components'
|
|
13
13
|
|
|
14
14
|
const log = logger('libp2p:kad-dht:rpc:handlers:get-value')
|
|
15
15
|
|
package/src/rpc/handlers/ping.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { logger } from '@libp2p/logger'
|
|
2
2
|
import type { Message } from '../../message/index.js'
|
|
3
3
|
import type { DHTMessageHandler } from '../index.js'
|
|
4
|
-
import type { PeerId } from '@libp2p/
|
|
5
|
-
import type { Initializable } from '@libp2p/
|
|
4
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
5
|
+
import type { Initializable } from '@libp2p/components'
|
|
6
6
|
|
|
7
7
|
const log = logger('libp2p:kad-dht:rpc:handlers:ping')
|
|
8
8
|
|
|
@@ -3,10 +3,10 @@ import errcode from 'err-code'
|
|
|
3
3
|
import { verifyRecord } from '@libp2p/record/validators'
|
|
4
4
|
import { Logger, logger } from '@libp2p/logger'
|
|
5
5
|
import type { DHTMessageHandler } from '../index.js'
|
|
6
|
-
import type { Validators } from '@libp2p/
|
|
7
|
-
import type { PeerId } from '@libp2p/
|
|
6
|
+
import type { Validators } from '@libp2p/interface-dht'
|
|
7
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
8
8
|
import type { Message } from '../../message/index.js'
|
|
9
|
-
import { Components, Initializable } from '@libp2p/
|
|
9
|
+
import { Components, Initializable } from '@libp2p/components'
|
|
10
10
|
|
|
11
11
|
export interface PutValueHandlerInit {
|
|
12
12
|
validators: Validators
|
package/src/rpc/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { pipe } from 'it-pipe'
|
|
|
2
2
|
import * as lp from 'it-length-prefixed'
|
|
3
3
|
import { Logger, logger } from '@libp2p/logger'
|
|
4
4
|
import type { RoutingTable } from '../routing-table'
|
|
5
|
-
import type { PeerId } from '@libp2p/
|
|
5
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
6
6
|
import { Message, MESSAGE_TYPE } from '../message/index.js'
|
|
7
7
|
import { AddProviderHandler } from './handlers/add-provider.js'
|
|
8
8
|
import { FindNodeHandler } from './handlers/find-node.js'
|
|
@@ -10,11 +10,11 @@ import { GetProvidersHandler } from './handlers/get-providers.js'
|
|
|
10
10
|
import { GetValueHandler } from './handlers/get-value.js'
|
|
11
11
|
import { PingHandler } from './handlers/ping.js'
|
|
12
12
|
import { PutValueHandler } from './handlers/put-value.js'
|
|
13
|
-
import type { IncomingStreamData } from '@libp2p/
|
|
13
|
+
import type { IncomingStreamData } from '@libp2p/interface-registrar'
|
|
14
14
|
import type { Providers } from '../providers'
|
|
15
15
|
import type { PeerRouting } from '../peer-routing'
|
|
16
|
-
import type { Validators } from '@libp2p/
|
|
17
|
-
import type { Components, Initializable } from '@libp2p/
|
|
16
|
+
import type { Validators } from '@libp2p/interface-dht'
|
|
17
|
+
import type { Components, Initializable } from '@libp2p/components'
|
|
18
18
|
|
|
19
19
|
export interface DHTMessageHandler extends Initializable {
|
|
20
20
|
handle: (peerId: PeerId, msg: Message) => Promise<Message | undefined>
|
package/src/topology-listener.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { CustomEvent, EventEmitter } from '@libp2p/interfaces/events'
|
|
|
3
3
|
import { logger } from '@libp2p/logger'
|
|
4
4
|
import type { Logger } from '@libp2p/logger'
|
|
5
5
|
import type { Startable } from '@libp2p/interfaces/startable'
|
|
6
|
-
import type { PeerId } from '@libp2p/
|
|
7
|
-
import { Components, Initializable } from '@libp2p/
|
|
6
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
7
|
+
import { Components, Initializable } from '@libp2p/components'
|
|
8
8
|
|
|
9
9
|
export interface TopologyListenerInit {
|
|
10
10
|
protocol: string
|
package/src/utils.ts
CHANGED
|
@@ -5,9 +5,9 @@ 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 { PeerInfo } from '@libp2p/
|
|
8
|
+
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
9
9
|
import { peerIdFromBytes } from '@libp2p/peer-id'
|
|
10
|
-
import type { PeerId } from '@libp2p/
|
|
10
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
11
11
|
import { RECORD_KEY_PREFIX } from './constants.js'
|
|
12
12
|
|
|
13
13
|
// const IPNS_PREFIX = uint8ArrayFromString('/ipns/')
|
|
@@ -92,15 +92,15 @@ export function keyForPublicKey (peer: PeerId) {
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
export function isPublicKeyKey (key: Uint8Array) {
|
|
95
|
-
return uint8ArrayToString(key.
|
|
95
|
+
return uint8ArrayToString(key.subarray(0, 4)) === '/pk/'
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
export function isIPNSKey (key: Uint8Array) {
|
|
99
|
-
return uint8ArrayToString(key.
|
|
99
|
+
return uint8ArrayToString(key.subarray(0, 4)) === '/ipns/'
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
export function fromPublicKeyKey (key: Uint8Array) {
|
|
103
|
-
return peerIdFromBytes(key.
|
|
103
|
+
return peerIdFromBytes(key.subarray(4))
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
/**
|