@libp2p/kad-dht 9.3.8 → 10.0.0
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 +6 -4
- package/dist/index.min.js +19 -19
- package/dist/src/content-fetching/index.d.ts +2 -2
- package/dist/src/content-fetching/index.d.ts.map +1 -1
- package/dist/src/content-fetching/index.js +4 -4
- package/dist/src/content-fetching/index.js.map +1 -1
- package/dist/src/dual-kad-dht.d.ts +5 -5
- package/dist/src/dual-kad-dht.d.ts.map +1 -1
- package/dist/src/dual-kad-dht.js +5 -5
- package/dist/src/dual-kad-dht.js.map +1 -1
- package/dist/src/index.d.ts +9 -10
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/kad-dht.d.ts +4 -4
- package/dist/src/kad-dht.d.ts.map +1 -1
- package/dist/src/kad-dht.js +3 -3
- package/dist/src/kad-dht.js.map +1 -1
- package/dist/src/message/index.d.ts +2 -2
- package/dist/src/message/index.d.ts.map +1 -1
- package/dist/src/message/index.js +1 -1
- package/dist/src/message/index.js.map +1 -1
- package/dist/src/network.d.ts +5 -5
- package/dist/src/network.d.ts.map +1 -1
- package/dist/src/network.js +4 -4
- package/dist/src/network.js.map +1 -1
- package/dist/src/peer-list/index.d.ts +1 -1
- package/dist/src/peer-list/peer-distance-list.d.ts +1 -1
- package/dist/src/peer-routing/index.d.ts +3 -3
- package/dist/src/peer-routing/index.d.ts.map +1 -1
- package/dist/src/peer-routing/index.js +3 -3
- 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/query/events.d.ts +3 -3
- package/dist/src/query/events.d.ts.map +1 -1
- package/dist/src/query/events.js +1 -1
- package/dist/src/query/events.js.map +1 -1
- package/dist/src/query/manager.d.ts +3 -3
- package/dist/src/query/manager.d.ts.map +1 -1
- package/dist/src/query/manager.js +2 -2
- 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/query-path.js +1 -1
- package/dist/src/query/query-path.js.map +1 -1
- package/dist/src/query/types.d.ts +1 -1
- package/dist/src/query-self.d.ts +2 -2
- package/dist/src/query-self.d.ts.map +1 -1
- package/dist/src/record/index.d.ts +22 -0
- package/dist/src/record/index.d.ts.map +1 -0
- package/dist/src/record/index.js +53 -0
- package/dist/src/record/index.js.map +1 -0
- package/dist/src/record/record.d.ts +13 -0
- package/dist/src/record/record.d.ts.map +1 -0
- package/dist/src/record/record.js +67 -0
- package/dist/src/record/record.js.map +1 -0
- package/dist/src/record/selectors.d.ts +7 -0
- package/dist/src/record/selectors.d.ts.map +1 -0
- package/dist/src/record/selectors.js +38 -0
- package/dist/src/record/selectors.js.map +1 -0
- package/dist/src/record/utils.d.ts +11 -0
- package/dist/src/record/utils.d.ts.map +1 -0
- package/dist/src/record/utils.js +41 -0
- package/dist/src/record/utils.js.map +1 -0
- package/dist/src/record/validators.d.ts +10 -0
- package/dist/src/record/validators.d.ts.map +1 -0
- package/dist/src/record/validators.js +54 -0
- package/dist/src/record/validators.js.map +1 -0
- package/dist/src/routing-table/index.d.ts +6 -6
- 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/k-bucket.d.ts +2 -2
- package/dist/src/routing-table/k-bucket.d.ts.map +1 -1
- package/dist/src/routing-table/k-bucket.js +1 -1
- package/dist/src/routing-table/k-bucket.js.map +1 -1
- package/dist/src/routing-table/refresh.d.ts +1 -1
- package/dist/src/rpc/handlers/add-provider.d.ts +1 -1
- package/dist/src/rpc/handlers/add-provider.js +1 -1
- package/dist/src/rpc/handlers/add-provider.js.map +1 -1
- package/dist/src/rpc/handlers/find-node.d.ts +2 -2
- package/dist/src/rpc/handlers/find-node.d.ts.map +1 -1
- package/dist/src/rpc/handlers/get-providers.d.ts +3 -3
- 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 +3 -3
- package/dist/src/rpc/handlers/get-value.d.ts.map +1 -1
- package/dist/src/rpc/handlers/get-value.js +2 -2
- package/dist/src/rpc/handlers/get-value.js.map +1 -1
- package/dist/src/rpc/handlers/ping.d.ts +1 -1
- package/dist/src/rpc/handlers/put-value.d.ts +1 -1
- package/dist/src/rpc/handlers/put-value.js +2 -2
- package/dist/src/rpc/handlers/put-value.js.map +1 -1
- package/dist/src/rpc/index.d.ts +2 -2
- package/dist/src/rpc/index.d.ts.map +1 -1
- package/dist/src/topology-listener.d.ts +3 -3
- package/dist/src/topology-listener.d.ts.map +1 -1
- package/dist/src/topology-listener.js +2 -4
- 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 +1 -1
- package/dist/src/utils.js.map +1 -1
- package/package.json +29 -138
- package/src/content-fetching/index.ts +5 -5
- package/src/content-routing/index.ts +1 -1
- package/src/dual-kad-dht.ts +7 -7
- package/src/index.ts +9 -10
- package/src/kad-dht.ts +6 -6
- package/src/message/index.ts +2 -2
- package/src/network.ts +9 -9
- package/src/peer-list/index.ts +1 -1
- package/src/peer-list/peer-distance-list.ts +1 -1
- package/src/peer-routing/index.ts +6 -6
- package/src/providers.ts +2 -2
- package/src/query/events.ts +4 -4
- package/src/query/manager.ts +5 -5
- package/src/query/query-path.ts +3 -3
- package/src/query/types.ts +1 -1
- package/src/query-self.ts +2 -2
- package/src/record/index.ts +70 -0
- package/src/record/record.proto +20 -0
- package/src/record/record.ts +87 -0
- package/src/record/selectors.ts +50 -0
- package/src/record/utils.ts +46 -0
- package/src/record/validators.ts +69 -0
- package/src/routing-table/index.ts +7 -7
- package/src/routing-table/k-bucket.ts +2 -2
- package/src/routing-table/refresh.ts +1 -1
- package/src/rpc/handlers/add-provider.ts +2 -2
- package/src/rpc/handlers/find-node.ts +3 -3
- package/src/rpc/handlers/get-providers.ts +4 -4
- package/src/rpc/handlers/get-value.ts +4 -4
- package/src/rpc/handlers/ping.ts +1 -1
- package/src/rpc/handlers/put-value.ts +3 -3
- package/src/rpc/index.ts +2 -2
- package/src/topology-listener.ts +4 -6
- package/src/utils.ts +3 -3
- package/dist/typedoc-urls.json +0 -29
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/* eslint-disable import/export */
|
|
2
|
+
/* eslint-disable complexity */
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
|
|
5
|
+
/* eslint-disable @typescript-eslint/no-empty-interface */
|
|
6
|
+
|
|
7
|
+
import { encodeMessage, decodeMessage, message } from 'protons-runtime'
|
|
8
|
+
import type { Codec } from 'protons-runtime'
|
|
9
|
+
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
10
|
+
|
|
11
|
+
export interface Record {
|
|
12
|
+
key: Uint8Array
|
|
13
|
+
value: Uint8Array
|
|
14
|
+
timeReceived: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export namespace Record {
|
|
18
|
+
let _codec: Codec<Record>
|
|
19
|
+
|
|
20
|
+
export const codec = (): Codec<Record> => {
|
|
21
|
+
if (_codec == null) {
|
|
22
|
+
_codec = message<Record>((obj, w, opts = {}) => {
|
|
23
|
+
if (opts.lengthDelimited !== false) {
|
|
24
|
+
w.fork()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if ((obj.key != null && obj.key.byteLength > 0)) {
|
|
28
|
+
w.uint32(10)
|
|
29
|
+
w.bytes(obj.key)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if ((obj.value != null && obj.value.byteLength > 0)) {
|
|
33
|
+
w.uint32(18)
|
|
34
|
+
w.bytes(obj.value)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if ((obj.timeReceived != null && obj.timeReceived !== '')) {
|
|
38
|
+
w.uint32(42)
|
|
39
|
+
w.string(obj.timeReceived)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (opts.lengthDelimited !== false) {
|
|
43
|
+
w.ldelim()
|
|
44
|
+
}
|
|
45
|
+
}, (reader, length) => {
|
|
46
|
+
const obj: any = {
|
|
47
|
+
key: new Uint8Array(0),
|
|
48
|
+
value: new Uint8Array(0),
|
|
49
|
+
timeReceived: ''
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const end = length == null ? reader.len : reader.pos + length
|
|
53
|
+
|
|
54
|
+
while (reader.pos < end) {
|
|
55
|
+
const tag = reader.uint32()
|
|
56
|
+
|
|
57
|
+
switch (tag >>> 3) {
|
|
58
|
+
case 1:
|
|
59
|
+
obj.key = reader.bytes()
|
|
60
|
+
break
|
|
61
|
+
case 2:
|
|
62
|
+
obj.value = reader.bytes()
|
|
63
|
+
break
|
|
64
|
+
case 5:
|
|
65
|
+
obj.timeReceived = reader.string()
|
|
66
|
+
break
|
|
67
|
+
default:
|
|
68
|
+
reader.skipType(tag & 7)
|
|
69
|
+
break
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return obj
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return _codec
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export const encode = (obj: Partial<Record>): Uint8Array => {
|
|
81
|
+
return encodeMessage(obj, Record.codec())
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export const decode = (buf: Uint8Array | Uint8ArrayList): Record => {
|
|
85
|
+
return decodeMessage(buf, Record.codec())
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { CodeError } from '@libp2p/interface/errors'
|
|
2
|
+
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
3
|
+
import type { Selectors } from '../index.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Select the best record out of the given records
|
|
7
|
+
*/
|
|
8
|
+
export function bestRecord (selectors: Selectors, k: Uint8Array, records: Uint8Array[]): number {
|
|
9
|
+
if (records.length === 0) {
|
|
10
|
+
const errMsg = 'No records given'
|
|
11
|
+
|
|
12
|
+
throw new CodeError(errMsg, 'ERR_NO_RECORDS_RECEIVED')
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const kStr = uint8ArrayToString(k)
|
|
16
|
+
const parts = kStr.split('/')
|
|
17
|
+
|
|
18
|
+
if (parts.length < 3) {
|
|
19
|
+
const errMsg = 'Record key does not have a selector function'
|
|
20
|
+
|
|
21
|
+
throw new CodeError(errMsg, 'ERR_NO_SELECTOR_FUNCTION_FOR_RECORD_KEY')
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const selector = selectors[parts[1].toString()]
|
|
25
|
+
|
|
26
|
+
if (selector == null) {
|
|
27
|
+
const errMsg = `Unrecognized key prefix: ${parts[1]}`
|
|
28
|
+
|
|
29
|
+
throw new CodeError(errMsg, 'ERR_UNRECOGNIZED_KEY_PREFIX')
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (records.length === 1) {
|
|
33
|
+
return 0
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return selector(k, records)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Best record selector, for public key records.
|
|
41
|
+
* Simply returns the first record, as all valid public key
|
|
42
|
+
* records are equal
|
|
43
|
+
*/
|
|
44
|
+
function publickKey (k: Uint8Array, records: Uint8Array[]): number {
|
|
45
|
+
return 0
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const selectors: Selectors = {
|
|
49
|
+
pk: publickKey
|
|
50
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a JavaScript date into an `RFC3339Nano` formatted
|
|
3
|
+
* string
|
|
4
|
+
*/
|
|
5
|
+
export function toRFC3339 (time: Date): string {
|
|
6
|
+
const year = time.getUTCFullYear()
|
|
7
|
+
const month = String(time.getUTCMonth() + 1).padStart(2, '0')
|
|
8
|
+
const day = String(time.getUTCDate()).padStart(2, '0')
|
|
9
|
+
const hour = String(time.getUTCHours()).padStart(2, '0')
|
|
10
|
+
const minute = String(time.getUTCMinutes()).padStart(2, '0')
|
|
11
|
+
const seconds = String(time.getUTCSeconds()).padStart(2, '0')
|
|
12
|
+
const milliseconds = time.getUTCMilliseconds()
|
|
13
|
+
const nanoseconds = String(milliseconds * 1000 * 1000).padStart(9, '0')
|
|
14
|
+
|
|
15
|
+
return `${year}-${month}-${day}T${hour}:${minute}:${seconds}.${nanoseconds}Z`
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Parses a date string formatted as `RFC3339Nano` into a
|
|
20
|
+
* JavaScript Date object
|
|
21
|
+
*/
|
|
22
|
+
export function parseRFC3339 (time: string): Date {
|
|
23
|
+
const rfc3339Matcher = new RegExp(
|
|
24
|
+
// 2006-01-02T
|
|
25
|
+
'(\\d{4})-(\\d{2})-(\\d{2})T' +
|
|
26
|
+
// 15:04:05
|
|
27
|
+
'(\\d{2}):(\\d{2}):(\\d{2})' +
|
|
28
|
+
// .999999999Z
|
|
29
|
+
'\\.(\\d+)Z'
|
|
30
|
+
)
|
|
31
|
+
const m = String(time).trim().match(rfc3339Matcher)
|
|
32
|
+
|
|
33
|
+
if (m == null) {
|
|
34
|
+
throw new Error('Invalid format')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const year = parseInt(m[1], 10)
|
|
38
|
+
const month = parseInt(m[2], 10) - 1
|
|
39
|
+
const date = parseInt(m[3], 10)
|
|
40
|
+
const hour = parseInt(m[4], 10)
|
|
41
|
+
const minute = parseInt(m[5], 10)
|
|
42
|
+
const second = parseInt(m[6], 10)
|
|
43
|
+
const millisecond = parseInt(m[7].slice(0, -6), 10)
|
|
44
|
+
|
|
45
|
+
return new Date(Date.UTC(year, month, date, hour, minute, second, millisecond))
|
|
46
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { CodeError } from '@libp2p/interface/errors'
|
|
2
|
+
import { sha256 } from 'multiformats/hashes/sha2'
|
|
3
|
+
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
|
|
4
|
+
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
5
|
+
import type { Libp2pRecord } from './index.js'
|
|
6
|
+
import type { Validators } from '../index.js'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Checks a record and ensures it is still valid.
|
|
10
|
+
* It runs the needed validators.
|
|
11
|
+
* If verification fails the returned Promise will reject with the error.
|
|
12
|
+
*/
|
|
13
|
+
export async function verifyRecord (validators: Validators, record: Libp2pRecord): Promise<void> {
|
|
14
|
+
const key = record.key
|
|
15
|
+
const keyString = uint8ArrayToString(key)
|
|
16
|
+
const parts = keyString.split('/')
|
|
17
|
+
|
|
18
|
+
if (parts.length < 3) {
|
|
19
|
+
// No validator available
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const validator = validators[parts[1].toString()]
|
|
24
|
+
|
|
25
|
+
if (validator == null) {
|
|
26
|
+
const errMsg = 'Invalid record keytype'
|
|
27
|
+
|
|
28
|
+
throw new CodeError(errMsg, 'ERR_INVALID_RECORD_KEY_TYPE')
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
await validator(key, record.value)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Validator for public key records.
|
|
36
|
+
* Verifies that the passed in record value is the PublicKey
|
|
37
|
+
* that matches the passed in key.
|
|
38
|
+
* If validation fails the returned Promise will reject with the error.
|
|
39
|
+
*
|
|
40
|
+
* @param {Uint8Array} key - A valid key is of the form `'/pk/<keymultihash>'`
|
|
41
|
+
* @param {Uint8Array} publicKey - The public key to validate against (protobuf encoded).
|
|
42
|
+
*/
|
|
43
|
+
const validatePublicKeyRecord = async (key: Uint8Array, publicKey: Uint8Array): Promise<void> => {
|
|
44
|
+
if (!(key instanceof Uint8Array)) {
|
|
45
|
+
throw new CodeError('"key" must be a Uint8Array', 'ERR_INVALID_RECORD_KEY_NOT_BUFFER')
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (key.byteLength < 5) {
|
|
49
|
+
throw new CodeError('invalid public key record', 'ERR_INVALID_RECORD_KEY_TOO_SHORT')
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const prefix = uint8ArrayToString(key.subarray(0, 4))
|
|
53
|
+
|
|
54
|
+
if (prefix !== '/pk/') {
|
|
55
|
+
throw new CodeError('key was not prefixed with /pk/', 'ERR_INVALID_RECORD_KEY_BAD_PREFIX')
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const keyhash = key.slice(4)
|
|
59
|
+
|
|
60
|
+
const publicKeyHash = await sha256.digest(publicKey)
|
|
61
|
+
|
|
62
|
+
if (!uint8ArrayEquals(keyhash, publicKeyHash.bytes)) {
|
|
63
|
+
throw new CodeError('public key does not match passed in key', 'ERR_INVALID_RECORD_HASH_MISMATCH')
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export const validators: Validators = {
|
|
68
|
+
pk: validatePublicKeyRecord
|
|
69
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { EventEmitter } from '@libp2p/
|
|
1
|
+
import { EventEmitter } from '@libp2p/interface/events'
|
|
2
2
|
import { logger } from '@libp2p/logger'
|
|
3
3
|
import { PeerSet } from '@libp2p/peer-collections'
|
|
4
4
|
import Queue from 'p-queue'
|
|
5
5
|
import * as utils from '../utils.js'
|
|
6
6
|
import { KBucket, type PingEventDetails } from './k-bucket.js'
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
9
|
-
import type {
|
|
10
|
-
import type {
|
|
11
|
-
import type {
|
|
7
|
+
import type { Metric, Metrics } from '@libp2p/interface/metrics'
|
|
8
|
+
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
9
|
+
import type { PeerStore } from '@libp2p/interface/peer-store'
|
|
10
|
+
import type { Startable } from '@libp2p/interface/startable'
|
|
11
|
+
import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager'
|
|
12
12
|
import type { Logger } from '@libp2p/logger'
|
|
13
13
|
|
|
14
14
|
export const KAD_CLOSE_TAG_NAME = 'kad-close'
|
|
@@ -217,7 +217,7 @@ export class RoutingTable extends EventEmitter<RoutingTableEvents> implements St
|
|
|
217
217
|
this.log('pinging old contact %p', oldContact.peer)
|
|
218
218
|
const connection = await this.components.connectionManager.openConnection(oldContact.peer, options)
|
|
219
219
|
const stream = await connection.newStream(this.protocol, options)
|
|
220
|
-
stream.close()
|
|
220
|
+
await stream.close()
|
|
221
221
|
responded++
|
|
222
222
|
} catch (err: any) {
|
|
223
223
|
if (this.running && this.kb != null) {
|
|
@@ -27,8 +27,8 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
27
27
|
OTHER DEALINGS IN THE SOFTWARE.
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
|
-
import { EventEmitter } from '@libp2p/
|
|
31
|
-
import type { PeerId } from '@libp2p/interface
|
|
30
|
+
import { EventEmitter } from '@libp2p/interface/events'
|
|
31
|
+
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
32
32
|
|
|
33
33
|
function arrayEquals (array1: Uint8Array, array2: Uint8Array): boolean {
|
|
34
34
|
if (array1 === array2) {
|
|
@@ -8,7 +8,7 @@ import { TABLE_REFRESH_INTERVAL, TABLE_REFRESH_QUERY_TIMEOUT } from '../constant
|
|
|
8
8
|
import GENERATED_PREFIXES from './generated-prefix-list.js'
|
|
9
9
|
import type { RoutingTable } from './index.js'
|
|
10
10
|
import type { PeerRouting } from '../peer-routing/index.js'
|
|
11
|
-
import type { PeerId } from '@libp2p/interface
|
|
11
|
+
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
12
12
|
import type { Logger } from '@libp2p/logger'
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { CodeError } from '@libp2p/
|
|
1
|
+
import { CodeError } from '@libp2p/interface/errors'
|
|
2
2
|
import { logger } from '@libp2p/logger'
|
|
3
3
|
import { CID } from 'multiformats/cid'
|
|
4
4
|
import type { Message } from '../../message/index.js'
|
|
5
5
|
import type { Providers } from '../../providers'
|
|
6
6
|
import type { DHTMessageHandler } from '../index.js'
|
|
7
|
-
import type { PeerId } from '@libp2p/interface
|
|
7
|
+
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
8
8
|
|
|
9
9
|
const log = logger('libp2p:kad-dht:rpc:handlers:add-provider')
|
|
10
10
|
|
|
@@ -8,9 +8,9 @@ import {
|
|
|
8
8
|
} from '../../utils.js'
|
|
9
9
|
import type { PeerRouting } from '../../peer-routing/index.js'
|
|
10
10
|
import type { DHTMessageHandler } from '../index.js'
|
|
11
|
-
import type {
|
|
12
|
-
import type {
|
|
13
|
-
import type {
|
|
11
|
+
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
12
|
+
import type { PeerInfo } from '@libp2p/interface/peer-info'
|
|
13
|
+
import type { AddressManager } from '@libp2p/interface-internal/address-manager'
|
|
14
14
|
|
|
15
15
|
const log = logger('libp2p:kad-dht:rpc:handlers:find-node')
|
|
16
16
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CodeError } from '@libp2p/
|
|
1
|
+
import { CodeError } from '@libp2p/interface/errors'
|
|
2
2
|
import { logger } from '@libp2p/logger'
|
|
3
3
|
import { CID } from 'multiformats/cid'
|
|
4
4
|
import { Message } from '../../message/index.js'
|
|
@@ -9,9 +9,9 @@ import {
|
|
|
9
9
|
import type { PeerRouting } from '../../peer-routing/index.js'
|
|
10
10
|
import type { Providers } from '../../providers.js'
|
|
11
11
|
import type { DHTMessageHandler } from '../index.js'
|
|
12
|
-
import type { PeerId } from '@libp2p/interface
|
|
13
|
-
import type { PeerInfo } from '@libp2p/interface
|
|
14
|
-
import type { PeerStore } from '@libp2p/interface
|
|
12
|
+
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
13
|
+
import type { PeerInfo } from '@libp2p/interface/peer-info'
|
|
14
|
+
import type { PeerStore } from '@libp2p/interface/peer-store'
|
|
15
15
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
16
16
|
|
|
17
17
|
const log = logger('libp2p:kad-dht:rpc:handlers:get-providers')
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { CodeError } from '@libp2p/
|
|
1
|
+
import { CodeError } from '@libp2p/interface/errors'
|
|
2
2
|
import { logger } from '@libp2p/logger'
|
|
3
|
-
import { Libp2pRecord } from '@libp2p/record'
|
|
4
3
|
import {
|
|
5
4
|
MAX_RECORD_AGE
|
|
6
5
|
} from '../../constants.js'
|
|
7
6
|
import { Message, MESSAGE_TYPE } from '../../message/index.js'
|
|
7
|
+
import { Libp2pRecord } from '../../record/index.js'
|
|
8
8
|
import { bufferToRecordKey, isPublicKeyKey, fromPublicKeyKey } from '../../utils.js'
|
|
9
9
|
import type { PeerRouting } from '../../peer-routing/index.js'
|
|
10
10
|
import type { DHTMessageHandler } from '../index.js'
|
|
11
|
-
import type { PeerId } from '@libp2p/interface
|
|
12
|
-
import type { PeerStore } from '@libp2p/interface
|
|
11
|
+
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
12
|
+
import type { PeerStore } from '@libp2p/interface/peer-store'
|
|
13
13
|
import type { Datastore } from 'interface-datastore'
|
|
14
14
|
|
|
15
15
|
const log = logger('libp2p:kad-dht:rpc:handlers:get-value')
|
package/src/rpc/handlers/ping.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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/interface
|
|
4
|
+
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
5
5
|
|
|
6
6
|
const log = logger('libp2p:kad-dht:rpc:handlers:ping')
|
|
7
7
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { CodeError } from '@libp2p/
|
|
1
|
+
import { CodeError } from '@libp2p/interface/errors'
|
|
2
2
|
import { type Logger, logger } from '@libp2p/logger'
|
|
3
|
-
import { verifyRecord } from '
|
|
3
|
+
import { verifyRecord } from '../../record/validators.js'
|
|
4
4
|
import { bufferToRecordKey } from '../../utils.js'
|
|
5
5
|
import type { Validators } from '../../index.js'
|
|
6
6
|
import type { Message } from '../../message/index.js'
|
|
7
7
|
import type { DHTMessageHandler } from '../index.js'
|
|
8
|
-
import type { PeerId } from '@libp2p/interface
|
|
8
|
+
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
9
9
|
import type { Datastore } from 'interface-datastore'
|
|
10
10
|
|
|
11
11
|
export interface PutValueHandlerInit {
|
package/src/rpc/index.ts
CHANGED
|
@@ -12,8 +12,8 @@ import type { Validators } from '../index.js'
|
|
|
12
12
|
import type { PeerRouting } from '../peer-routing'
|
|
13
13
|
import type { Providers } from '../providers'
|
|
14
14
|
import type { RoutingTable } from '../routing-table'
|
|
15
|
-
import type { PeerId } from '@libp2p/interface
|
|
16
|
-
import type { IncomingStreamData } from '@libp2p/interface-registrar'
|
|
15
|
+
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
16
|
+
import type { IncomingStreamData } from '@libp2p/interface-internal/registrar'
|
|
17
17
|
|
|
18
18
|
export interface DHTMessageHandler {
|
|
19
19
|
handle: (peerId: PeerId, msg: Message) => Promise<Message | undefined>
|
package/src/topology-listener.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { CustomEvent, EventEmitter } from '@libp2p/
|
|
1
|
+
import { CustomEvent, EventEmitter } from '@libp2p/interface/events'
|
|
2
2
|
import { logger } from '@libp2p/logger'
|
|
3
|
-
import { createTopology } from '@libp2p/topology'
|
|
4
3
|
import type { KadDHTComponents } from '.'
|
|
5
|
-
import type { PeerId } from '@libp2p/interface
|
|
6
|
-
import type { Startable } from '@libp2p/
|
|
4
|
+
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
5
|
+
import type { Startable } from '@libp2p/interface/startable'
|
|
7
6
|
import type { Logger } from '@libp2p/logger'
|
|
8
7
|
|
|
9
8
|
export interface TopologyListenerInit {
|
|
@@ -51,7 +50,7 @@ export class TopologyListener extends EventEmitter<TopologyListenerEvents> imple
|
|
|
51
50
|
this.running = true
|
|
52
51
|
|
|
53
52
|
// register protocol with topology
|
|
54
|
-
|
|
53
|
+
this.registrarId = await this.components.registrar.register(this.protocol, {
|
|
55
54
|
onConnect: (peerId) => {
|
|
56
55
|
this.log('observed peer %p with protocol %s', peerId, this.protocol)
|
|
57
56
|
this.dispatchEvent(new CustomEvent('peer', {
|
|
@@ -59,7 +58,6 @@ export class TopologyListener extends EventEmitter<TopologyListenerEvents> imple
|
|
|
59
58
|
}))
|
|
60
59
|
}
|
|
61
60
|
})
|
|
62
|
-
this.registrarId = await this.components.registrar.register(this.protocol, topology)
|
|
63
61
|
}
|
|
64
62
|
|
|
65
63
|
/**
|
package/src/utils.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { peerIdFromBytes } from '@libp2p/peer-id'
|
|
2
|
-
import { Libp2pRecord } from '@libp2p/record'
|
|
3
2
|
import { Key } from 'interface-datastore/key'
|
|
4
3
|
import { sha256 } from 'multiformats/hashes/sha2'
|
|
5
4
|
import isPrivateIp from 'private-ip'
|
|
@@ -7,8 +6,9 @@ import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
|
|
|
7
6
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
8
7
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
9
8
|
import { RECORD_KEY_PREFIX } from './constants.js'
|
|
10
|
-
import
|
|
11
|
-
import type {
|
|
9
|
+
import { Libp2pRecord } from './record/index.js'
|
|
10
|
+
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
11
|
+
import type { PeerInfo } from '@libp2p/interface/peer-info'
|
|
12
12
|
|
|
13
13
|
// const IPNS_PREFIX = uint8ArrayFromString('/ipns/')
|
|
14
14
|
const PK_PREFIX = uint8ArrayFromString('/pk/')
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"ProvidersInit": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/_internal_.ProvidersInit.html",
|
|
3
|
-
"EventTypes": "https://libp2p.github.io/js-libp2p-kad-dht/enums/EventTypes.html",
|
|
4
|
-
"MessageType": "https://libp2p.github.io/js-libp2p-kad-dht/enums/MessageType.html",
|
|
5
|
-
"AddPeerEvent": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/AddPeerEvent.html",
|
|
6
|
-
"DHTRecord": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/DHTRecord.html",
|
|
7
|
-
"DialPeerEvent": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/DialPeerEvent.html",
|
|
8
|
-
"DualKadDHT": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/DualKadDHT.html",
|
|
9
|
-
"FinalPeerEvent": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/FinalPeerEvent.html",
|
|
10
|
-
"KadDHT": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/KadDHT.html",
|
|
11
|
-
"KadDHTComponents": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/KadDHTComponents.html",
|
|
12
|
-
"KadDHTInit": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/KadDHTInit.html",
|
|
13
|
-
"PeerResponseEvent": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/PeerResponseEvent.html",
|
|
14
|
-
"ProviderEvent": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/ProviderEvent.html",
|
|
15
|
-
"QueryErrorEvent": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/QueryErrorEvent.html",
|
|
16
|
-
"QueryOptions": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/QueryOptions.html",
|
|
17
|
-
"RoutingTable": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/RoutingTable.html",
|
|
18
|
-
"SelectFn": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/SelectFn.html",
|
|
19
|
-
"SendQueryEvent": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/SendQueryEvent.html",
|
|
20
|
-
"SingleKadDHT": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/SingleKadDHT.html",
|
|
21
|
-
"ValidateFn": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/ValidateFn.html",
|
|
22
|
-
"ValueEvent": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/ValueEvent.html",
|
|
23
|
-
"DHTProgressEvents": "https://libp2p.github.io/js-libp2p-kad-dht/types/DHTProgressEvents.html",
|
|
24
|
-
"MessageName": "https://libp2p.github.io/js-libp2p-kad-dht/types/MessageName.html",
|
|
25
|
-
"QueryEvent": "https://libp2p.github.io/js-libp2p-kad-dht/types/QueryEvent.html",
|
|
26
|
-
"Selectors": "https://libp2p.github.io/js-libp2p-kad-dht/types/Selectors.html",
|
|
27
|
-
"Validators": "https://libp2p.github.io/js-libp2p-kad-dht/types/Validators.html",
|
|
28
|
-
"kadDHT": "https://libp2p.github.io/js-libp2p-kad-dht/functions/kadDHT-1.html"
|
|
29
|
-
}
|