@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.
Files changed (139) hide show
  1. package/README.md +6 -4
  2. package/dist/index.min.js +19 -19
  3. package/dist/src/content-fetching/index.d.ts +2 -2
  4. package/dist/src/content-fetching/index.d.ts.map +1 -1
  5. package/dist/src/content-fetching/index.js +4 -4
  6. package/dist/src/content-fetching/index.js.map +1 -1
  7. package/dist/src/dual-kad-dht.d.ts +5 -5
  8. package/dist/src/dual-kad-dht.d.ts.map +1 -1
  9. package/dist/src/dual-kad-dht.js +5 -5
  10. package/dist/src/dual-kad-dht.js.map +1 -1
  11. package/dist/src/index.d.ts +9 -10
  12. package/dist/src/index.d.ts.map +1 -1
  13. package/dist/src/index.js.map +1 -1
  14. package/dist/src/kad-dht.d.ts +4 -4
  15. package/dist/src/kad-dht.d.ts.map +1 -1
  16. package/dist/src/kad-dht.js +3 -3
  17. package/dist/src/kad-dht.js.map +1 -1
  18. package/dist/src/message/index.d.ts +2 -2
  19. package/dist/src/message/index.d.ts.map +1 -1
  20. package/dist/src/message/index.js +1 -1
  21. package/dist/src/message/index.js.map +1 -1
  22. package/dist/src/network.d.ts +5 -5
  23. package/dist/src/network.d.ts.map +1 -1
  24. package/dist/src/network.js +4 -4
  25. package/dist/src/network.js.map +1 -1
  26. package/dist/src/peer-list/index.d.ts +1 -1
  27. package/dist/src/peer-list/peer-distance-list.d.ts +1 -1
  28. package/dist/src/peer-routing/index.d.ts +3 -3
  29. package/dist/src/peer-routing/index.d.ts.map +1 -1
  30. package/dist/src/peer-routing/index.js +3 -3
  31. package/dist/src/peer-routing/index.js.map +1 -1
  32. package/dist/src/providers.d.ts +2 -2
  33. package/dist/src/providers.d.ts.map +1 -1
  34. package/dist/src/query/events.d.ts +3 -3
  35. package/dist/src/query/events.d.ts.map +1 -1
  36. package/dist/src/query/events.js +1 -1
  37. package/dist/src/query/events.js.map +1 -1
  38. package/dist/src/query/manager.d.ts +3 -3
  39. package/dist/src/query/manager.d.ts.map +1 -1
  40. package/dist/src/query/manager.js +2 -2
  41. package/dist/src/query/manager.js.map +1 -1
  42. package/dist/src/query/query-path.d.ts +2 -2
  43. package/dist/src/query/query-path.d.ts.map +1 -1
  44. package/dist/src/query/query-path.js +1 -1
  45. package/dist/src/query/query-path.js.map +1 -1
  46. package/dist/src/query/types.d.ts +1 -1
  47. package/dist/src/query-self.d.ts +2 -2
  48. package/dist/src/query-self.d.ts.map +1 -1
  49. package/dist/src/record/index.d.ts +22 -0
  50. package/dist/src/record/index.d.ts.map +1 -0
  51. package/dist/src/record/index.js +53 -0
  52. package/dist/src/record/index.js.map +1 -0
  53. package/dist/src/record/record.d.ts +13 -0
  54. package/dist/src/record/record.d.ts.map +1 -0
  55. package/dist/src/record/record.js +67 -0
  56. package/dist/src/record/record.js.map +1 -0
  57. package/dist/src/record/selectors.d.ts +7 -0
  58. package/dist/src/record/selectors.d.ts.map +1 -0
  59. package/dist/src/record/selectors.js +38 -0
  60. package/dist/src/record/selectors.js.map +1 -0
  61. package/dist/src/record/utils.d.ts +11 -0
  62. package/dist/src/record/utils.d.ts.map +1 -0
  63. package/dist/src/record/utils.js +41 -0
  64. package/dist/src/record/utils.js.map +1 -0
  65. package/dist/src/record/validators.d.ts +10 -0
  66. package/dist/src/record/validators.d.ts.map +1 -0
  67. package/dist/src/record/validators.js +54 -0
  68. package/dist/src/record/validators.js.map +1 -0
  69. package/dist/src/routing-table/index.d.ts +6 -6
  70. package/dist/src/routing-table/index.d.ts.map +1 -1
  71. package/dist/src/routing-table/index.js +2 -2
  72. package/dist/src/routing-table/index.js.map +1 -1
  73. package/dist/src/routing-table/k-bucket.d.ts +2 -2
  74. package/dist/src/routing-table/k-bucket.d.ts.map +1 -1
  75. package/dist/src/routing-table/k-bucket.js +1 -1
  76. package/dist/src/routing-table/k-bucket.js.map +1 -1
  77. package/dist/src/routing-table/refresh.d.ts +1 -1
  78. package/dist/src/rpc/handlers/add-provider.d.ts +1 -1
  79. package/dist/src/rpc/handlers/add-provider.js +1 -1
  80. package/dist/src/rpc/handlers/add-provider.js.map +1 -1
  81. package/dist/src/rpc/handlers/find-node.d.ts +2 -2
  82. package/dist/src/rpc/handlers/find-node.d.ts.map +1 -1
  83. package/dist/src/rpc/handlers/get-providers.d.ts +3 -3
  84. package/dist/src/rpc/handlers/get-providers.js +1 -1
  85. package/dist/src/rpc/handlers/get-providers.js.map +1 -1
  86. package/dist/src/rpc/handlers/get-value.d.ts +3 -3
  87. package/dist/src/rpc/handlers/get-value.d.ts.map +1 -1
  88. package/dist/src/rpc/handlers/get-value.js +2 -2
  89. package/dist/src/rpc/handlers/get-value.js.map +1 -1
  90. package/dist/src/rpc/handlers/ping.d.ts +1 -1
  91. package/dist/src/rpc/handlers/put-value.d.ts +1 -1
  92. package/dist/src/rpc/handlers/put-value.js +2 -2
  93. package/dist/src/rpc/handlers/put-value.js.map +1 -1
  94. package/dist/src/rpc/index.d.ts +2 -2
  95. package/dist/src/rpc/index.d.ts.map +1 -1
  96. package/dist/src/topology-listener.d.ts +3 -3
  97. package/dist/src/topology-listener.d.ts.map +1 -1
  98. package/dist/src/topology-listener.js +2 -4
  99. package/dist/src/topology-listener.js.map +1 -1
  100. package/dist/src/utils.d.ts +2 -2
  101. package/dist/src/utils.d.ts.map +1 -1
  102. package/dist/src/utils.js +1 -1
  103. package/dist/src/utils.js.map +1 -1
  104. package/package.json +29 -138
  105. package/src/content-fetching/index.ts +5 -5
  106. package/src/content-routing/index.ts +1 -1
  107. package/src/dual-kad-dht.ts +7 -7
  108. package/src/index.ts +9 -10
  109. package/src/kad-dht.ts +6 -6
  110. package/src/message/index.ts +2 -2
  111. package/src/network.ts +9 -9
  112. package/src/peer-list/index.ts +1 -1
  113. package/src/peer-list/peer-distance-list.ts +1 -1
  114. package/src/peer-routing/index.ts +6 -6
  115. package/src/providers.ts +2 -2
  116. package/src/query/events.ts +4 -4
  117. package/src/query/manager.ts +5 -5
  118. package/src/query/query-path.ts +3 -3
  119. package/src/query/types.ts +1 -1
  120. package/src/query-self.ts +2 -2
  121. package/src/record/index.ts +70 -0
  122. package/src/record/record.proto +20 -0
  123. package/src/record/record.ts +87 -0
  124. package/src/record/selectors.ts +50 -0
  125. package/src/record/utils.ts +46 -0
  126. package/src/record/validators.ts +69 -0
  127. package/src/routing-table/index.ts +7 -7
  128. package/src/routing-table/k-bucket.ts +2 -2
  129. package/src/routing-table/refresh.ts +1 -1
  130. package/src/rpc/handlers/add-provider.ts +2 -2
  131. package/src/rpc/handlers/find-node.ts +3 -3
  132. package/src/rpc/handlers/get-providers.ts +4 -4
  133. package/src/rpc/handlers/get-value.ts +4 -4
  134. package/src/rpc/handlers/ping.ts +1 -1
  135. package/src/rpc/handlers/put-value.ts +3 -3
  136. package/src/rpc/index.ts +2 -2
  137. package/src/topology-listener.ts +4 -6
  138. package/src/utils.ts +3 -3
  139. package/dist/typedoc-urls.json +0 -29
package/package.json CHANGED
@@ -1,23 +1,19 @@
1
1
  {
2
2
  "name": "@libp2p/kad-dht",
3
- "version": "9.3.8",
3
+ "version": "10.0.0",
4
4
  "description": "JavaScript implementation of the Kad-DHT for libp2p",
5
5
  "license": "Apache-2.0 OR MIT",
6
- "homepage": "https://github.com/libp2p/js-libp2p-kad-dht#readme",
6
+ "homepage": "https://github.com/libp2p/js-libp2p/tree/master/packages/kad-dht#readme",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "git+https://github.com/libp2p/js-libp2p-kad-dht.git"
9
+ "url": "git+https://github.com/libp2p/js-libp2p.git"
10
10
  },
11
11
  "bugs": {
12
- "url": "https://github.com/libp2p/js-libp2p-kad-dht/issues"
12
+ "url": "https://github.com/libp2p/js-libp2p/issues"
13
13
  },
14
14
  "keywords": [
15
15
  "IPFS"
16
16
  ],
17
- "engines": {
18
- "node": ">=16.0.0",
19
- "npm": ">=7.0.0"
20
- },
21
17
  "type": "module",
22
18
  "types": "./dist/src/index.d.ts",
23
19
  "files": [
@@ -41,91 +37,6 @@
41
37
  "src/message/dht.d.ts"
42
38
  ]
43
39
  },
44
- "release": {
45
- "branches": [
46
- "master"
47
- ],
48
- "plugins": [
49
- [
50
- "@semantic-release/commit-analyzer",
51
- {
52
- "preset": "conventionalcommits",
53
- "releaseRules": [
54
- {
55
- "breaking": true,
56
- "release": "major"
57
- },
58
- {
59
- "revert": true,
60
- "release": "patch"
61
- },
62
- {
63
- "type": "feat",
64
- "release": "minor"
65
- },
66
- {
67
- "type": "fix",
68
- "release": "patch"
69
- },
70
- {
71
- "type": "docs",
72
- "release": "patch"
73
- },
74
- {
75
- "type": "test",
76
- "release": "patch"
77
- },
78
- {
79
- "type": "deps",
80
- "release": "patch"
81
- },
82
- {
83
- "scope": "no-release",
84
- "release": false
85
- }
86
- ]
87
- }
88
- ],
89
- [
90
- "@semantic-release/release-notes-generator",
91
- {
92
- "preset": "conventionalcommits",
93
- "presetConfig": {
94
- "types": [
95
- {
96
- "type": "feat",
97
- "section": "Features"
98
- },
99
- {
100
- "type": "fix",
101
- "section": "Bug Fixes"
102
- },
103
- {
104
- "type": "chore",
105
- "section": "Trivial Changes"
106
- },
107
- {
108
- "type": "docs",
109
- "section": "Documentation"
110
- },
111
- {
112
- "type": "deps",
113
- "section": "Dependencies"
114
- },
115
- {
116
- "type": "test",
117
- "section": "Tests"
118
- }
119
- ]
120
- }
121
- }
122
- ],
123
- "@semantic-release/changelog",
124
- "@semantic-release/npm",
125
- "@semantic-release/github",
126
- "@semantic-release/git"
127
- ]
128
- },
129
40
  "scripts": {
130
41
  "clean": "aegir clean",
131
42
  "lint": "aegir lint",
@@ -137,46 +48,32 @@
137
48
  "test:chrome-webworker": "aegir test -t webworker",
138
49
  "test:firefox": "aegir test -t browser -- --browser firefox",
139
50
  "test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
140
- "dep-check": "aegir dep-check -i protons -i events",
141
- "release": "aegir release",
142
- "docs": "aegir docs"
51
+ "dep-check": "aegir dep-check -i events"
143
52
  },
144
53
  "dependencies": {
145
- "@libp2p/crypto": "^1.0.4",
146
- "@libp2p/interface-address-manager": "^3.0.0",
147
- "@libp2p/interface-connection": "^5.0.1",
148
- "@libp2p/interface-connection-manager": "^3.0.0",
149
- "@libp2p/interface-content-routing": "^2.1.0",
150
- "@libp2p/interface-metrics": "^4.0.0",
151
- "@libp2p/interface-peer-discovery": "^2.0.0",
152
- "@libp2p/interface-peer-id": "^2.0.0",
153
- "@libp2p/interface-peer-info": "^1.0.3",
154
- "@libp2p/interface-peer-routing": "^1.1.0",
155
- "@libp2p/interface-peer-store": "^2.0.0",
156
- "@libp2p/interface-registrar": "^2.0.11",
157
- "@libp2p/interfaces": "^3.2.0",
158
- "@libp2p/logger": "^2.0.1",
159
- "@libp2p/peer-collections": "^3.0.0",
160
- "@libp2p/peer-id": "^2.0.0",
161
- "@libp2p/record": "^3.0.0",
162
- "@libp2p/topology": "^4.0.0",
163
- "@multiformats/multiaddr": "^12.0.0",
164
- "@types/sinon": "^10.0.14",
54
+ "@libp2p/crypto": "^2.0.0",
55
+ "@libp2p/interface": "^0.1.0",
56
+ "@libp2p/interface-internal": "^0.1.0",
57
+ "@libp2p/logger": "^3.0.0",
58
+ "@libp2p/peer-collections": "^4.0.0",
59
+ "@libp2p/peer-id": "^3.0.0",
60
+ "@multiformats/multiaddr": "^12.1.3",
61
+ "@types/sinon": "^10.0.15",
165
62
  "abortable-iterator": "^5.0.1",
166
63
  "any-signal": "^4.1.1",
167
64
  "datastore-core": "^9.0.1",
168
65
  "events": "^3.3.0",
169
66
  "hashlru": "^2.3.0",
170
- "interface-datastore": "^8.0.0",
171
- "it-all": "^3.0.1",
172
- "it-drain": "^3.0.1",
67
+ "interface-datastore": "^8.2.0",
68
+ "it-all": "^3.0.2",
69
+ "it-drain": "^3.0.2",
173
70
  "it-first": "^3.0.1",
174
71
  "it-length": "^3.0.1",
175
- "it-length-prefixed": "^9.0.0",
176
- "it-map": "^3.0.1",
72
+ "it-length-prefixed": "^9.0.1",
73
+ "it-map": "^3.0.3",
177
74
  "it-merge": "^3.0.0",
178
75
  "it-parallel": "^3.0.0",
179
- "it-pipe": "^3.0.0",
76
+ "it-pipe": "^3.0.1",
180
77
  "it-stream-types": "^2.0.1",
181
78
  "it-take": "^3.0.1",
182
79
  "multiformats": "^12.0.1",
@@ -186,40 +83,34 @@
186
83
  "private-ip": "^3.0.0",
187
84
  "progress-events": "^1.0.0",
188
85
  "protons-runtime": "^5.0.0",
189
- "uint8arraylist": "^2.0.0",
190
- "uint8arrays": "^4.0.2",
86
+ "uint8arraylist": "^2.4.3",
87
+ "uint8arrays": "^4.0.4",
191
88
  "varint": "^6.0.0"
192
89
  },
193
90
  "devDependencies": {
194
- "@libp2p/interface-libp2p": "^3.0.0",
195
- "@libp2p/interface-mocks": "^12.0.0",
196
- "@libp2p/peer-id-factory": "^2.0.0",
197
- "@libp2p/peer-store": "^8.0.0",
91
+ "@libp2p/interface-compliance-tests": "^4.0.0",
92
+ "@libp2p/peer-id-factory": "^3.0.0",
93
+ "@libp2p/peer-store": "^9.0.0",
198
94
  "@types/lodash.random": "^3.2.6",
199
95
  "@types/lodash.range": "^3.2.6",
200
96
  "@types/varint": "^6.0.0",
201
97
  "@types/which": "^3.0.0",
202
- "aegir": "^39.0.5",
98
+ "aegir": "^40.0.1",
203
99
  "datastore-level": "^10.0.0",
204
100
  "delay": "^6.0.0",
205
- "execa": "^7.0.0",
101
+ "execa": "^7.1.1",
206
102
  "it-filter": "^3.0.1",
207
103
  "it-last": "^3.0.1",
208
104
  "lodash.random": "^3.2.0",
209
105
  "lodash.range": "^3.2.0",
210
- "p-retry": "^5.0.0",
211
- "p-wait-for": "^5.0.0",
106
+ "p-retry": "^5.1.2",
107
+ "p-wait-for": "^5.0.2",
212
108
  "protons": "^7.0.2",
213
- "sinon": "^15.0.0",
109
+ "sinon": "^15.1.2",
214
110
  "ts-sinon": "^2.0.2",
215
111
  "which": "^3.0.0"
216
112
  },
217
113
  "browser": {
218
114
  "./dist/src/routing-table/generated-prefix-list.js": "./dist/src/routing-table/generated-prefix-list-browser.js"
219
- },
220
- "typedocs": {
221
- "KadDHTComponents": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/KadDHTComponents.html",
222
- "KadDHTInit": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/KadDHTInit.html",
223
- "kadDHT": "https://libp2p.github.io/js-libp2p-kad-dht/functions/kadDHT.html"
224
115
  }
225
116
  }
@@ -1,8 +1,5 @@
1
- import { CodeError } from '@libp2p/interfaces/errors'
1
+ import { CodeError } from '@libp2p/interface/errors'
2
2
  import { logger } from '@libp2p/logger'
3
- import { Libp2pRecord } from '@libp2p/record'
4
- import { bestRecord } from '@libp2p/record/selectors'
5
- import { verifyRecord } from '@libp2p/record/validators'
6
3
  import map from 'it-map'
7
4
  import parallel from 'it-parallel'
8
5
  import { pipe } from 'it-pipe'
@@ -15,13 +12,16 @@ import {
15
12
  valueEvent,
16
13
  queryErrorEvent
17
14
  } from '../query/events.js'
15
+ import { Libp2pRecord } from '../record/index.js'
16
+ import { bestRecord } from '../record/selectors.js'
17
+ import { verifyRecord } from '../record/validators.js'
18
18
  import { createPutRecord, bufferToRecordKey } from '../utils.js'
19
19
  import type { KadDHTComponents, Validators, Selectors, ValueEvent, QueryOptions, QueryEvent } from '../index.js'
20
20
  import type { Network } from '../network.js'
21
21
  import type { PeerRouting } from '../peer-routing/index.js'
22
22
  import type { QueryManager } from '../query/manager.js'
23
23
  import type { QueryFunc } from '../query/types.js'
24
- import type { AbortOptions } from '@libp2p/interfaces'
24
+ import type { AbortOptions } from '@libp2p/interface'
25
25
  import type { Logger } from '@libp2p/logger'
26
26
 
27
27
  export interface ContentFetchingInit {
@@ -16,7 +16,7 @@ import type { Providers } from '../providers.js'
16
16
  import type { QueryManager } from '../query/manager.js'
17
17
  import type { QueryFunc } from '../query/types.js'
18
18
  import type { RoutingTable } from '../routing-table/index.js'
19
- import type { PeerInfo } from '@libp2p/interface-peer-info'
19
+ import type { PeerInfo } from '@libp2p/interface/peer-info'
20
20
  import type { Logger } from '@libp2p/logger'
21
21
  import type { Multiaddr } from '@multiformats/multiaddr'
22
22
  import type { CID } from 'multiformats/cid'
@@ -1,8 +1,8 @@
1
- import { type ContentRouting, contentRouting } from '@libp2p/interface-content-routing'
2
- import { type PeerDiscovery, peerDiscovery, type PeerDiscoveryEvents } from '@libp2p/interface-peer-discovery'
3
- import { type PeerRouting, peerRouting } from '@libp2p/interface-peer-routing'
4
- import { CodeError } from '@libp2p/interfaces/errors'
5
- import { EventEmitter, CustomEvent } from '@libp2p/interfaces/events'
1
+ import { type ContentRouting, contentRouting } from '@libp2p/interface/content-routing'
2
+ import { CodeError } from '@libp2p/interface/errors'
3
+ import { EventEmitter, CustomEvent } from '@libp2p/interface/events'
4
+ import { type PeerDiscovery, peerDiscovery, type PeerDiscoveryEvents } from '@libp2p/interface/peer-discovery'
5
+ import { type PeerRouting, peerRouting } from '@libp2p/interface/peer-routing'
6
6
  import { logger } from '@libp2p/logger'
7
7
  import drain from 'it-drain'
8
8
  import merge from 'it-merge'
@@ -10,8 +10,8 @@ import isPrivate from 'private-ip'
10
10
  import { DefaultKadDHT } from './kad-dht.js'
11
11
  import { queryErrorEvent } from './query/events.js'
12
12
  import type { DualKadDHT, KadDHT, KadDHTComponents, KadDHTInit, QueryEvent, QueryOptions } from './index.js'
13
- import type { PeerId } from '@libp2p/interface-peer-id'
14
- import type { PeerInfo } from '@libp2p/interface-peer-info'
13
+ import type { PeerId } from '@libp2p/interface/peer-id'
14
+ import type { PeerInfo } from '@libp2p/interface/peer-info'
15
15
  import type { Multiaddr } from '@multiformats/multiaddr'
16
16
  import type { CID } from 'multiformats/cid'
17
17
 
package/src/index.ts CHANGED
@@ -1,15 +1,14 @@
1
1
  import { DefaultDualKadDHT } from './dual-kad-dht.js'
2
2
  import type { ProvidersInit } from './providers.js'
3
- import type { AddressManager } from '@libp2p/interface-address-manager'
4
- import type { ConnectionManager } from '@libp2p/interface-connection-manager'
5
- import type { Libp2pEvents } from '@libp2p/interface-libp2p'
6
- import type { Metrics } from '@libp2p/interface-metrics'
7
- import type { PeerId } from '@libp2p/interface-peer-id'
8
- import type { PeerInfo } from '@libp2p/interface-peer-info'
9
- import type { PeerStore } from '@libp2p/interface-peer-store'
10
- import type { Registrar } from '@libp2p/interface-registrar'
11
- import type { AbortOptions } from '@libp2p/interfaces'
12
- import type { EventEmitter } from '@libp2p/interfaces/events'
3
+ import type { Libp2pEvents, AbortOptions } from '@libp2p/interface'
4
+ import type { EventEmitter } from '@libp2p/interface/events'
5
+ import type { Metrics } from '@libp2p/interface/metrics'
6
+ import type { PeerId } from '@libp2p/interface/peer-id'
7
+ import type { PeerInfo } from '@libp2p/interface/peer-info'
8
+ import type { PeerStore } from '@libp2p/interface/peer-store'
9
+ import type { AddressManager } from '@libp2p/interface-internal/address-manager'
10
+ import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager'
11
+ import type { Registrar } from '@libp2p/interface-internal/registrar'
13
12
  import type { Datastore } from 'interface-datastore'
14
13
  import type { CID } from 'multiformats/cid'
15
14
  import type { ProgressOptions, ProgressEvent } from 'progress-events'
package/src/kad-dht.ts CHANGED
@@ -1,7 +1,5 @@
1
- import { CustomEvent, EventEmitter } from '@libp2p/interfaces/events'
1
+ import { CustomEvent, EventEmitter } from '@libp2p/interface/events'
2
2
  import { type Logger, logger } from '@libp2p/logger'
3
- import { selectors as recordSelectors } from '@libp2p/record/selectors'
4
- import { validators as recordValidators } from '@libp2p/record/validators'
5
3
  import pDefer from 'p-defer'
6
4
  import { PROTOCOL_DHT, PROTOCOL_PREFIX, LAN_PREFIX } from './constants.js'
7
5
  import { ContentFetching } from './content-fetching/index.js'
@@ -11,6 +9,8 @@ import { PeerRouting } from './peer-routing/index.js'
11
9
  import { Providers } from './providers.js'
12
10
  import { QueryManager } from './query/manager.js'
13
11
  import { QuerySelf } from './query-self.js'
12
+ import { selectors as recordSelectors } from './record/selectors.js'
13
+ import { validators as recordValidators } from './record/validators.js'
14
14
  import { RoutingTable } from './routing-table/index.js'
15
15
  import { RoutingTableRefresh } from './routing-table/refresh.js'
16
16
  import { RPC } from './rpc/index.js'
@@ -20,9 +20,9 @@ import {
20
20
  removePublicAddresses
21
21
  } from './utils.js'
22
22
  import type { KadDHTComponents, KadDHTInit, QueryOptions, Validators, Selectors, KadDHT, QueryEvent } from './index.js'
23
- import type { PeerDiscoveryEvents } from '@libp2p/interface-peer-discovery'
24
- import type { PeerId } from '@libp2p/interface-peer-id'
25
- import type { PeerInfo } from '@libp2p/interface-peer-info'
23
+ import type { PeerDiscoveryEvents } from '@libp2p/interface/peer-discovery'
24
+ import type { PeerId } from '@libp2p/interface/peer-id'
25
+ import type { PeerInfo } from '@libp2p/interface/peer-info'
26
26
  import type { CID } from 'multiformats/cid'
27
27
 
28
28
  export const DEFAULT_MAX_INBOUND_STREAMS = 32
@@ -1,8 +1,8 @@
1
1
  import { peerIdFromBytes } from '@libp2p/peer-id'
2
- import { Libp2pRecord } from '@libp2p/record'
3
2
  import { multiaddr } from '@multiformats/multiaddr'
3
+ import { Libp2pRecord } from '../record/index.js'
4
4
  import { Message as PBMessage } from './dht.js'
5
- import type { PeerInfo } from '@libp2p/interface-peer-info'
5
+ import type { PeerInfo } from '@libp2p/interface/peer-info'
6
6
  import type { Uint8ArrayList } from 'uint8arraylist'
7
7
 
8
8
  export const MESSAGE_TYPE = PBMessage.MessageType
package/src/network.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { CodeError } from '@libp2p/interfaces/errors'
2
- import { EventEmitter, CustomEvent } from '@libp2p/interfaces/events'
1
+ import { CodeError } from '@libp2p/interface/errors'
2
+ import { EventEmitter, CustomEvent } from '@libp2p/interface/events'
3
3
  import { logger } from '@libp2p/logger'
4
4
  import { abortableDuplex } from 'abortable-iterator'
5
5
  import drain from 'it-drain'
@@ -14,11 +14,11 @@ import {
14
14
  queryErrorEvent
15
15
  } from './query/events.js'
16
16
  import type { KadDHTComponents, QueryEvent, QueryOptions } from './index.js'
17
- import type { Stream } from '@libp2p/interface-connection'
18
- import type { PeerId } from '@libp2p/interface-peer-id'
19
- import type { PeerInfo } from '@libp2p/interface-peer-info'
20
- import type { AbortOptions } from '@libp2p/interfaces'
21
- import type { Startable } from '@libp2p/interfaces/startable'
17
+ import type { AbortOptions } from '@libp2p/interface'
18
+ import type { Stream } from '@libp2p/interface/connection'
19
+ import type { PeerId } from '@libp2p/interface/peer-id'
20
+ import type { PeerInfo } from '@libp2p/interface/peer-info'
21
+ import type { Startable } from '@libp2p/interface/startable'
22
22
  import type { Logger } from '@libp2p/logger'
23
23
  import type { Duplex, Source } from 'it-stream-types'
24
24
  import type { Uint8ArrayList } from 'uint8arraylist'
@@ -110,7 +110,7 @@ export class Network extends EventEmitter<NetworkEvents> implements Startable {
110
110
  yield queryErrorEvent({ from: to, error: err }, options)
111
111
  } finally {
112
112
  if (stream != null) {
113
- stream.close()
113
+ await stream.close()
114
114
  }
115
115
  }
116
116
  }
@@ -140,7 +140,7 @@ export class Network extends EventEmitter<NetworkEvents> implements Startable {
140
140
  yield queryErrorEvent({ from: to, error: err }, options)
141
141
  } finally {
142
142
  if (stream != null) {
143
- stream.close()
143
+ await stream.close()
144
144
  }
145
145
  }
146
146
  }
@@ -1,4 +1,4 @@
1
- import type { PeerId } from '@libp2p/interface-peer-id'
1
+ import type { PeerId } from '@libp2p/interface/peer-id'
2
2
 
3
3
  /**
4
4
  * A list of unique peers.
@@ -1,7 +1,7 @@
1
1
  import { compare as uint8ArrayCompare } from 'uint8arrays/compare'
2
2
  import { xor as uint8ArrayXor } from 'uint8arrays/xor'
3
3
  import * as utils from '../utils.js'
4
- import type { PeerId } from '@libp2p/interface-peer-id'
4
+ import type { PeerId } from '@libp2p/interface/peer-id'
5
5
 
6
6
  interface PeerDistance {
7
7
  peerId: PeerId
@@ -1,9 +1,7 @@
1
1
  import { keys } from '@libp2p/crypto'
2
- import { CodeError } from '@libp2p/interfaces/errors'
2
+ import { CodeError } from '@libp2p/interface/errors'
3
3
  import { logger } from '@libp2p/logger'
4
4
  import { peerIdFromKeys } from '@libp2p/peer-id'
5
- import { Libp2pRecord } from '@libp2p/record'
6
- import { verifyRecord } from '@libp2p/record/validators'
7
5
  import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
8
6
  import { Message, MESSAGE_TYPE } from '../message/index.js'
9
7
  import { PeerDistanceList } from '../peer-list/peer-distance-list.js'
@@ -12,15 +10,17 @@ import {
12
10
  finalPeerEvent,
13
11
  valueEvent
14
12
  } from '../query/events.js'
13
+ import { Libp2pRecord } from '../record/index.js'
14
+ import { verifyRecord } from '../record/validators.js'
15
15
  import * as utils from '../utils.js'
16
16
  import type { KadDHTComponents, DHTRecord, DialPeerEvent, FinalPeerEvent, QueryEvent, Validators } from '../index.js'
17
17
  import type { Network } from '../network.js'
18
18
  import type { QueryManager, QueryOptions } from '../query/manager.js'
19
19
  import type { QueryFunc } from '../query/types.js'
20
20
  import type { RoutingTable } from '../routing-table/index.js'
21
- import type { PeerId } from '@libp2p/interface-peer-id'
22
- import type { PeerInfo } from '@libp2p/interface-peer-info'
23
- import type { AbortOptions } from '@libp2p/interfaces'
21
+ import type { AbortOptions } from '@libp2p/interface'
22
+ import type { PeerId } from '@libp2p/interface/peer-id'
23
+ import type { PeerInfo } from '@libp2p/interface/peer-info'
24
24
  import type { Logger } from '@libp2p/logger'
25
25
 
26
26
  export interface PeerRoutingInit {
package/src/providers.ts CHANGED
@@ -11,8 +11,8 @@ import {
11
11
  PROVIDERS_LRU_CACHE_SIZE,
12
12
  PROVIDER_KEY_PREFIX
13
13
  } from './constants.js'
14
- import type { PeerId } from '@libp2p/interface-peer-id'
15
- import type { Startable } from '@libp2p/interfaces/startable'
14
+ import type { PeerId } from '@libp2p/interface/peer-id'
15
+ import type { Startable } from '@libp2p/interface/startable'
16
16
  import type { Datastore } from 'interface-datastore'
17
17
  import type { CID } from 'multiformats'
18
18
 
@@ -1,10 +1,10 @@
1
- import { CustomEvent } from '@libp2p/interfaces/events'
1
+ import { CustomEvent } from '@libp2p/interface/events'
2
2
  import { MESSAGE_TYPE_LOOKUP } from '../message/index.js'
3
3
  import type { SendQueryEvent, PeerResponseEvent, DialPeerEvent, AddPeerEvent, ValueEvent, ProviderEvent, QueryErrorEvent, FinalPeerEvent, QueryOptions } from '../index.js'
4
4
  import type { Message } from '../message/dht.js'
5
- import type { PeerId } from '@libp2p/interface-peer-id'
6
- import type { PeerInfo } from '@libp2p/interface-peer-info'
7
- import type { Libp2pRecord } from '@libp2p/record'
5
+ import type { Libp2pRecord } from '../record/index.js'
6
+ import type { PeerId } from '@libp2p/interface/peer-id'
7
+ import type { PeerInfo } from '@libp2p/interface/peer-info'
8
8
 
9
9
  export interface QueryEventFields {
10
10
  to: PeerId
@@ -1,6 +1,6 @@
1
1
  import { setMaxListeners } from 'events'
2
- import { AbortError } from '@libp2p/interfaces/errors'
3
- import { EventEmitter, CustomEvent } from '@libp2p/interfaces/events'
2
+ import { AbortError } from '@libp2p/interface/errors'
3
+ import { EventEmitter, CustomEvent } from '@libp2p/interface/events'
4
4
  import { logger } from '@libp2p/logger'
5
5
  import { PeerSet } from '@libp2p/peer-collections'
6
6
  import { anySignal } from 'any-signal'
@@ -14,9 +14,9 @@ import { queryPath } from './query-path.js'
14
14
  import type { QueryFunc } from './types.js'
15
15
  import type { QueryEvent, QueryOptions as RootQueryOptions } from '../index.js'
16
16
  import type { RoutingTable } from '../routing-table/index.js'
17
- import type { Metric, Metrics } from '@libp2p/interface-metrics'
18
- import type { PeerId } from '@libp2p/interface-peer-id'
19
- import type { Startable } from '@libp2p/interfaces/startable'
17
+ import type { Metric, Metrics } from '@libp2p/interface/metrics'
18
+ import type { PeerId } from '@libp2p/interface/peer-id'
19
+ import type { Startable } from '@libp2p/interface/startable'
20
20
  import type { DeferredPromise } from 'p-defer'
21
21
 
22
22
  export interface CleanUpEvents {
@@ -1,4 +1,4 @@
1
- import { CodeError } from '@libp2p/interfaces/errors'
1
+ import { CodeError } from '@libp2p/interface/errors'
2
2
  import { anySignal } from 'any-signal'
3
3
  import defer from 'p-defer'
4
4
  import Queue from 'p-queue'
@@ -9,8 +9,8 @@ import { queryErrorEvent } from './events.js'
9
9
  import type { CleanUpEvents } from './manager.js'
10
10
  import type { QueryEvent, QueryOptions } from '../index.js'
11
11
  import type { QueryFunc } from '../query/types.js'
12
- import type { PeerId } from '@libp2p/interface-peer-id'
13
- import type { EventEmitter } from '@libp2p/interfaces/events'
12
+ import type { EventEmitter } from '@libp2p/interface/events'
13
+ import type { PeerId } from '@libp2p/interface/peer-id'
14
14
  import type { Logger } from '@libp2p/logger'
15
15
  import type { PeerSet } from '@libp2p/peer-collections'
16
16
 
@@ -1,5 +1,5 @@
1
1
  import type { QueryEvent } from '../index.js'
2
- import type { PeerId } from '@libp2p/interface-peer-id'
2
+ import type { PeerId } from '@libp2p/interface/peer-id'
3
3
 
4
4
  export interface QueryContext {
5
5
  // the key we are looking up
package/src/query-self.ts CHANGED
@@ -9,8 +9,8 @@ import { pEvent } from 'p-event'
9
9
  import { QUERY_SELF_INTERVAL, QUERY_SELF_TIMEOUT, K, QUERY_SELF_INITIAL_INTERVAL } from './constants.js'
10
10
  import type { PeerRouting } from './peer-routing/index.js'
11
11
  import type { RoutingTable } from './routing-table/index.js'
12
- import type { PeerId } from '@libp2p/interface-peer-id'
13
- import type { Startable } from '@libp2p/interfaces/startable'
12
+ import type { PeerId } from '@libp2p/interface/peer-id'
13
+ import type { Startable } from '@libp2p/interface/startable'
14
14
  import type { DeferredPromise } from 'p-defer'
15
15
 
16
16
  export interface QuerySelfInit {
@@ -0,0 +1,70 @@
1
+ import {
2
+ Record
3
+ } from './record.js'
4
+ import * as utils from './utils.js'
5
+ import type { Uint8ArrayList } from 'uint8arraylist'
6
+
7
+ export class Libp2pRecord {
8
+ public key: Uint8Array
9
+ public value: Uint8Array
10
+ public timeReceived: Date
11
+
12
+ constructor (key: Uint8Array, value: Uint8Array, timeReceived: Date) {
13
+ if (!(key instanceof Uint8Array)) {
14
+ throw new Error('key must be a Uint8Array')
15
+ }
16
+
17
+ if (!(value instanceof Uint8Array)) {
18
+ throw new Error('value must be a Uint8Array')
19
+ }
20
+
21
+ this.key = key
22
+ this.value = value
23
+ this.timeReceived = timeReceived
24
+ }
25
+
26
+ serialize (): Uint8Array {
27
+ return Record.encode(this.prepareSerialize())
28
+ }
29
+
30
+ /**
31
+ * Return the object format ready to be given to the protobuf library.
32
+ */
33
+ prepareSerialize (): Record {
34
+ return {
35
+ key: this.key,
36
+ value: this.value,
37
+ timeReceived: utils.toRFC3339(this.timeReceived)
38
+ }
39
+ }
40
+
41
+ /**
42
+ * Decode a protobuf encoded record
43
+ */
44
+ static deserialize (raw: Uint8Array | Uint8ArrayList): Libp2pRecord {
45
+ const rec = Record.decode(raw)
46
+
47
+ return new Libp2pRecord(rec.key, rec.value, new Date(rec.timeReceived))
48
+ }
49
+
50
+ /**
51
+ * Create a record from the raw object returned from the protobuf library
52
+ */
53
+ static fromDeserialized (obj: Record): Libp2pRecord {
54
+ const recvtime = utils.parseRFC3339(obj.timeReceived)
55
+
56
+ if (obj.key == null) {
57
+ throw new Error('key missing from deserialized object')
58
+ }
59
+
60
+ if (obj.value == null) {
61
+ throw new Error('value missing from deserialized object')
62
+ }
63
+
64
+ const rec = new Libp2pRecord(
65
+ obj.key, obj.value, recvtime
66
+ )
67
+
68
+ return rec
69
+ }
70
+ }
@@ -0,0 +1,20 @@
1
+ syntax = "proto3";
2
+
3
+ // Record represents a dht record that contains a value
4
+ // for a key value pair
5
+ message Record {
6
+ // The key that references this record
7
+ bytes key = 1;
8
+
9
+ // The actual value this record is storing
10
+ bytes value = 2;
11
+
12
+ // Note: These fields were removed from the Record message
13
+ // hash of the authors public key
14
+ // optional bytes author = 3;
15
+ // A PKI signature for the key+value+author
16
+ // optional bytes signature = 4;
17
+
18
+ // Time the record was received, set by receiver
19
+ string timeReceived = 5;
20
+ }