@streamr/dht 100.0.0-testnet-two.4 → 100.0.0-testnet-three.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 (304) hide show
  1. package/dist/package.json +8 -8
  2. package/dist/src/connection/Connection.d.ts +1 -0
  3. package/dist/src/connection/Connection.js +10 -3
  4. package/dist/src/connection/Connection.js.map +1 -1
  5. package/dist/src/connection/ConnectionLockHandler.d.ts +3 -3
  6. package/dist/src/connection/ConnectionLockHandler.js +8 -10
  7. package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
  8. package/dist/src/connection/ConnectionLockRpcLocal.js +5 -4
  9. package/dist/src/connection/ConnectionLockRpcLocal.js.map +1 -1
  10. package/dist/src/connection/ConnectionLockRpcRemote.js +4 -4
  11. package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
  12. package/dist/src/connection/ConnectionManager.d.ts +8 -8
  13. package/dist/src/connection/ConnectionManager.js +54 -55
  14. package/dist/src/connection/ConnectionManager.js.map +1 -1
  15. package/dist/src/connection/ConnectorFacade.d.ts +3 -2
  16. package/dist/src/connection/ConnectorFacade.js +7 -0
  17. package/dist/src/connection/ConnectorFacade.js.map +1 -1
  18. package/dist/src/connection/Handshaker.js +3 -1
  19. package/dist/src/connection/Handshaker.js.map +1 -1
  20. package/dist/src/connection/IConnection.d.ts +2 -7
  21. package/dist/src/connection/IConnection.js +1 -8
  22. package/dist/src/connection/IConnection.js.map +1 -1
  23. package/dist/src/connection/ManagedConnection.js +23 -15
  24. package/dist/src/connection/ManagedConnection.js.map +1 -1
  25. package/dist/src/connection/ManagedWebrtcConnection.js.map +1 -1
  26. package/dist/src/connection/connectivityChecker.js.map +1 -1
  27. package/dist/src/connection/connectivityRequestHandler.js +5 -2
  28. package/dist/src/connection/connectivityRequestHandler.js.map +1 -1
  29. package/dist/src/connection/simulator/Simulator.js +32 -20
  30. package/dist/src/connection/simulator/Simulator.js.map +1 -1
  31. package/dist/src/connection/simulator/SimulatorConnection.js +13 -10
  32. package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -1
  33. package/dist/src/connection/simulator/SimulatorConnector.js +9 -6
  34. package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
  35. package/dist/src/connection/simulator/pings.js.map +1 -1
  36. package/dist/src/connection/webrtc/NodeWebrtcConnection.d.ts +1 -1
  37. package/dist/src/connection/webrtc/NodeWebrtcConnection.js +26 -14
  38. package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
  39. package/dist/src/connection/webrtc/WebrtcConnector.d.ts +0 -1
  40. package/dist/src/connection/webrtc/WebrtcConnector.js +18 -17
  41. package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
  42. package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +10 -9
  43. package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
  44. package/dist/src/connection/webrtc/iceServerAsString.js.map +1 -1
  45. package/dist/src/connection/websocket/AutoCertifierClientFacade.js +3 -0
  46. package/dist/src/connection/websocket/AutoCertifierClientFacade.js.map +1 -1
  47. package/dist/src/connection/websocket/ClientWebsocket.js +7 -4
  48. package/dist/src/connection/websocket/ClientWebsocket.js.map +1 -1
  49. package/dist/src/connection/websocket/ServerWebsocket.d.ts +1 -0
  50. package/dist/src/connection/websocket/ServerWebsocket.js +22 -3
  51. package/dist/src/connection/websocket/ServerWebsocket.js.map +1 -1
  52. package/dist/src/connection/websocket/WebsocketConnector.d.ts +2 -1
  53. package/dist/src/connection/websocket/WebsocketConnector.js +24 -15
  54. package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
  55. package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.d.ts +2 -1
  56. package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js +3 -1
  57. package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js.map +1 -1
  58. package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js +2 -2
  59. package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js.map +1 -1
  60. package/dist/src/connection/websocket/WebsocketServer.js +6 -3
  61. package/dist/src/connection/websocket/WebsocketServer.js.map +1 -1
  62. package/dist/src/dht/DhtNode.d.ts +18 -19
  63. package/dist/src/dht/DhtNode.js +56 -65
  64. package/dist/src/dht/DhtNode.js.map +1 -1
  65. package/dist/src/dht/DhtNodeRpcLocal.d.ts +1 -1
  66. package/dist/src/dht/DhtNodeRpcLocal.js +5 -4
  67. package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
  68. package/dist/src/dht/DhtNodeRpcRemote.d.ts +2 -1
  69. package/dist/src/dht/DhtNodeRpcRemote.js +5 -3
  70. package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
  71. package/dist/src/dht/ExternalApiRpcLocal.d.ts +1 -1
  72. package/dist/src/dht/ExternalApiRpcLocal.js +4 -3
  73. package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
  74. package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
  75. package/dist/src/dht/PeerManager.d.ts +5 -5
  76. package/dist/src/dht/PeerManager.js +31 -24
  77. package/dist/src/dht/PeerManager.js.map +1 -1
  78. package/dist/src/dht/contact/Contact.js +3 -2
  79. package/dist/src/dht/contact/Contact.js.map +1 -1
  80. package/dist/src/dht/contact/ContactList.js +9 -5
  81. package/dist/src/dht/contact/ContactList.js.map +1 -1
  82. package/dist/src/dht/contact/RandomContactList.js +1 -0
  83. package/dist/src/dht/contact/RandomContactList.js.map +1 -1
  84. package/dist/src/dht/contact/RpcRemote.d.ts +2 -1
  85. package/dist/src/dht/contact/RpcRemote.js +4 -0
  86. package/dist/src/dht/contact/RpcRemote.js.map +1 -1
  87. package/dist/src/dht/contact/SortedContactList.js +3 -2
  88. package/dist/src/dht/contact/SortedContactList.js.map +1 -1
  89. package/dist/src/dht/discovery/DiscoverySession.js +8 -8
  90. package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
  91. package/dist/src/dht/discovery/PeerDiscovery.d.ts +8 -2
  92. package/dist/src/dht/discovery/PeerDiscovery.js +26 -17
  93. package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
  94. package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +1 -1
  95. package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +9 -9
  96. package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -1
  97. package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js +3 -2
  98. package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js.map +1 -1
  99. package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js +6 -5
  100. package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +1 -1
  101. package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +2 -1
  102. package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +26 -20
  103. package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -1
  104. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.d.ts +4 -2
  105. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js +5 -2
  106. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js.map +1 -1
  107. package/dist/src/dht/routing/DuplicateDetector.d.ts +2 -4
  108. package/dist/src/dht/routing/DuplicateDetector.js +10 -15
  109. package/dist/src/dht/routing/DuplicateDetector.js.map +1 -1
  110. package/dist/src/dht/routing/Router.d.ts +1 -1
  111. package/dist/src/dht/routing/Router.js +20 -15
  112. package/dist/src/dht/routing/Router.js.map +1 -1
  113. package/dist/src/dht/routing/RouterRpcLocal.js +4 -4
  114. package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
  115. package/dist/src/dht/routing/RouterRpcRemote.js +11 -9
  116. package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
  117. package/dist/src/dht/routing/RoutingSession.d.ts +2 -0
  118. package/dist/src/dht/routing/RoutingSession.js +27 -9
  119. package/dist/src/dht/routing/RoutingSession.js.map +1 -1
  120. package/dist/src/dht/store/LocalDataStore.js +5 -4
  121. package/dist/src/dht/store/LocalDataStore.js.map +1 -1
  122. package/dist/src/dht/store/StoreManager.js +8 -8
  123. package/dist/src/dht/store/StoreManager.js.map +1 -1
  124. package/dist/src/dht/store/StoreRpcLocal.js +1 -0
  125. package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
  126. package/dist/src/dht/store/StoreRpcRemote.js +3 -3
  127. package/dist/src/dht/store/StoreRpcRemote.js.map +1 -1
  128. package/dist/src/exports.d.ts +1 -4
  129. package/dist/src/exports.js +4 -7
  130. package/dist/src/exports.js.map +1 -1
  131. package/dist/src/helpers/AddressTools.js.map +1 -1
  132. package/dist/src/helpers/Connectivity.js.map +1 -1
  133. package/dist/src/helpers/MapWithTtl.js +2 -1
  134. package/dist/src/helpers/MapWithTtl.js.map +1 -1
  135. package/dist/src/helpers/createPeerDescriptor.d.ts +3 -0
  136. package/dist/src/helpers/createPeerDescriptor.js +56 -0
  137. package/dist/src/helpers/createPeerDescriptor.js.map +1 -0
  138. package/dist/src/helpers/createPeerDescriptorSignaturePayload.d.ts +2 -0
  139. package/dist/src/helpers/createPeerDescriptorSignaturePayload.js +30 -0
  140. package/dist/src/helpers/createPeerDescriptorSignaturePayload.js.map +1 -0
  141. package/dist/src/helpers/debugHelpers.js.map +1 -1
  142. package/dist/src/helpers/errors.js +2 -0
  143. package/dist/src/helpers/errors.js.map +1 -1
  144. package/dist/src/helpers/offering.d.ts +4 -0
  145. package/dist/src/helpers/offering.js +18 -0
  146. package/dist/src/helpers/offering.js.map +1 -0
  147. package/dist/src/helpers/protoToString.js.map +1 -1
  148. package/dist/src/identifiers.d.ts +3 -0
  149. package/dist/src/identifiers.js +9 -1
  150. package/dist/src/identifiers.js.map +1 -1
  151. package/dist/src/proto/google/protobuf/any.d.ts +8 -5
  152. package/dist/src/proto/google/protobuf/any.js +8 -8
  153. package/dist/src/proto/google/protobuf/any.js.map +1 -1
  154. package/dist/src/proto/google/protobuf/empty.d.ts +0 -1
  155. package/dist/src/proto/google/protobuf/empty.js +2 -4
  156. package/dist/src/proto/google/protobuf/empty.js.map +1 -1
  157. package/dist/src/proto/google/protobuf/timestamp.d.ts +10 -1
  158. package/dist/src/proto/google/protobuf/timestamp.js +10 -10
  159. package/dist/src/proto/google/protobuf/timestamp.js.map +1 -1
  160. package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +4 -5
  161. package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +38 -29
  162. package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
  163. package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +22 -12
  164. package/dist/src/proto/packages/dht/protos/DhtRpc.js +11 -16
  165. package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
  166. package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +2 -3
  167. package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +1 -1
  168. package/dist/src/rpc-protocol/DhtCallContext.d.ts +0 -1
  169. package/dist/src/rpc-protocol/DhtCallContext.js +8 -0
  170. package/dist/src/rpc-protocol/DhtCallContext.js.map +1 -1
  171. package/dist/src/transport/ITransport.d.ts +1 -1
  172. package/dist/src/transport/ListeningRpcCommunicator.js +2 -0
  173. package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -1
  174. package/dist/src/transport/RoutingRpcCommunicator.d.ts +2 -1
  175. package/dist/src/transport/RoutingRpcCommunicator.js +2 -0
  176. package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
  177. package/package.json +8 -8
  178. package/protos/DhtRpc.proto +7 -4
  179. package/src/connection/Connection.ts +6 -1
  180. package/src/connection/ConnectionLockHandler.ts +3 -3
  181. package/src/connection/ConnectionLockRpcLocal.ts +1 -5
  182. package/src/connection/ConnectionLockRpcRemote.ts +1 -1
  183. package/src/connection/ConnectionManager.ts +24 -38
  184. package/src/connection/ConnectorFacade.ts +3 -2
  185. package/src/connection/IConnection.ts +2 -8
  186. package/src/connection/ManagedConnection.ts +3 -3
  187. package/src/connection/connectivityRequestHandler.ts +7 -3
  188. package/src/connection/simulator/Simulator.ts +1 -2
  189. package/src/connection/simulator/SimulatorConnection.ts +1 -1
  190. package/src/connection/simulator/SimulatorConnector.ts +1 -2
  191. package/src/connection/webrtc/BrowserWebrtcConnection.ts +4 -3
  192. package/src/connection/webrtc/NodeWebrtcConnection.ts +5 -4
  193. package/src/connection/webrtc/WebrtcConnector.ts +9 -17
  194. package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +7 -7
  195. package/src/connection/websocket/ClientWebsocket.ts +3 -2
  196. package/src/connection/websocket/ServerWebsocket.ts +17 -1
  197. package/src/connection/websocket/WebsocketConnector.ts +10 -9
  198. package/src/connection/websocket/WebsocketConnectorRpcLocal.ts +4 -2
  199. package/src/connection/websocket/WebsocketConnectorRpcRemote.ts +1 -1
  200. package/src/connection/websocket/WebsocketServer.ts +2 -2
  201. package/src/dht/DhtNode.ts +63 -86
  202. package/src/dht/DhtNodeRpcLocal.ts +5 -5
  203. package/src/dht/DhtNodeRpcRemote.ts +3 -3
  204. package/src/dht/ExternalApiRpcLocal.ts +3 -4
  205. package/src/dht/PeerManager.ts +14 -20
  206. package/src/dht/contact/Contact.ts +1 -2
  207. package/src/dht/contact/RpcRemote.ts +2 -1
  208. package/src/dht/discovery/DiscoverySession.ts +2 -3
  209. package/src/dht/discovery/PeerDiscovery.ts +16 -9
  210. package/src/dht/recursive-operation/RecursiveOperationManager.ts +12 -6
  211. package/src/dht/recursive-operation/RecursiveOperationRpcLocal.ts +1 -1
  212. package/src/dht/recursive-operation/RecursiveOperationRpcRemote.ts +3 -2
  213. package/src/dht/recursive-operation/RecursiveOperationSession.ts +19 -9
  214. package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +13 -3
  215. package/src/dht/routing/DuplicateDetector.ts +9 -21
  216. package/src/dht/routing/Router.ts +12 -11
  217. package/src/dht/routing/RouterRpcLocal.ts +1 -2
  218. package/src/dht/routing/RouterRpcRemote.ts +5 -5
  219. package/src/dht/routing/RoutingSession.ts +22 -2
  220. package/src/dht/store/StoreManager.ts +1 -2
  221. package/src/dht/store/StoreRpcRemote.ts +1 -1
  222. package/src/exports.ts +9 -4
  223. package/src/helpers/createPeerDescriptor.ts +56 -0
  224. package/src/helpers/createPeerDescriptorSignaturePayload.ts +28 -0
  225. package/src/helpers/offering.ts +15 -0
  226. package/src/identifiers.ts +10 -1
  227. package/src/proto/google/protobuf/any.ts +12 -9
  228. package/src/proto/google/protobuf/empty.ts +2 -5
  229. package/src/proto/google/protobuf/timestamp.ts +14 -5
  230. package/src/proto/packages/dht/protos/DhtRpc.client.ts +6 -7
  231. package/src/proto/packages/dht/protos/DhtRpc.server.ts +3 -4
  232. package/src/proto/packages/dht/protos/DhtRpc.ts +32 -20
  233. package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +1 -1
  234. package/src/rpc-protocol/DhtCallContext.ts +0 -1
  235. package/src/transport/ITransport.ts +1 -1
  236. package/src/transport/RoutingRpcCommunicator.ts +1 -1
  237. package/test/benchmark/Find.test.ts +6 -8
  238. package/test/benchmark/KademliaCorrectness.test.ts +2 -3
  239. package/test/benchmark/SortedContactListBenchmark.test.ts +16 -16
  240. package/test/benchmark/WebsocketServerMemoryLeak.test.ts +1 -1
  241. package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +8 -8
  242. package/test/benchmark/kademlia-simulation/SimulationNode.ts +8 -8
  243. package/test/end-to-end/Layer0-Layer1.test.ts +1 -1
  244. package/test/end-to-end/Layer0.test.ts +4 -4
  245. package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +12 -12
  246. package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +18 -18
  247. package/test/end-to-end/Layer0Webrtc.test.ts +13 -10
  248. package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +2 -2
  249. package/test/end-to-end/Layer1-Scale-Webrtc.test.ts +2 -2
  250. package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +1 -1
  251. package/test/end-to-end/WebsocketConnectionRequest.test.ts +3 -3
  252. package/test/end-to-end/memory-leak.test.ts +2 -2
  253. package/test/integration/ConnectionLocking.test.ts +60 -47
  254. package/test/integration/ConnectionManager.test.ts +8 -7
  255. package/test/integration/DhtJoinPeerDiscovery.test.ts +2 -2
  256. package/test/integration/DhtNodeExternalAPI.test.ts +1 -2
  257. package/test/integration/DhtNodeRpcRemote.test.ts +4 -3
  258. package/test/integration/DhtRpc.test.ts +4 -3
  259. package/test/integration/Find.test.ts +4 -6
  260. package/test/integration/Layer1-scale.test.ts +7 -7
  261. package/test/integration/Mock-Layer1-Layer0.test.ts +21 -24
  262. package/test/integration/MultipleEntryPointJoining.test.ts +7 -7
  263. package/test/integration/ReplicateData.test.ts +52 -161
  264. package/test/integration/RouteMessage.test.ts +24 -47
  265. package/test/integration/RouterRpcRemote.test.ts +7 -4
  266. package/test/integration/ScaleDownDht.test.ts +2 -3
  267. package/test/integration/SimultaneousConnections.test.ts +9 -8
  268. package/test/integration/Store.test.ts +1 -2
  269. package/test/integration/StoreAndDelete.test.ts +5 -0
  270. package/test/integration/StoreOnDhtWithThreeNodes.test.ts +59 -0
  271. package/test/integration/StoreOnDhtWithTwoNodes.test.ts +1 -1
  272. package/test/integration/StoreRpcRemote.test.ts +4 -4
  273. package/test/integration/WebrtcConnectionManagement.test.ts +6 -5
  274. package/test/integration/WebrtcConnectorRpc.test.ts +3 -2
  275. package/test/integration/WebsocketConnectionManagement.test.ts +27 -15
  276. package/test/integration/WebsocketConnectorRpc.test.ts +3 -2
  277. package/test/integration/{RpcErrors.test.ts → rpc-connections-over-webrpc.test.ts} +6 -3
  278. package/test/unit/DuplicateDetector.test.ts +2 -2
  279. package/test/unit/LocalDataStore.test.ts +1 -4
  280. package/test/unit/RandomContactList.test.ts +2 -4
  281. package/test/unit/RecursiveOperationManager.test.ts +5 -6
  282. package/test/unit/RecursiveOperationSession.test.ts +5 -4
  283. package/test/unit/Router.test.ts +25 -8
  284. package/test/unit/RoutingSession.test.ts +3 -3
  285. package/test/unit/SortedContactList.test.ts +2 -4
  286. package/test/unit/connectivityRequestHandler.test.ts +5 -3
  287. package/test/unit/createPeerDescriptor.test.ts +63 -0
  288. package/test/utils/FakeTransport.ts +7 -4
  289. package/test/utils/mock/Transport.ts +1 -1
  290. package/test/utils/utils.ts +6 -6
  291. package/dist/src/helpers/PeerID.d.ts +0 -27
  292. package/dist/src/helpers/PeerID.js +0 -87
  293. package/dist/src/helpers/PeerID.js.map +0 -1
  294. package/dist/src/helpers/UUID.d.ts +0 -8
  295. package/dist/src/helpers/UUID.js +0 -36
  296. package/dist/src/helpers/UUID.js.map +0 -1
  297. package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +0 -7
  298. package/dist/src/helpers/peerIdFromPeerDescriptor.js +0 -23
  299. package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +0 -1
  300. package/src/helpers/PeerID.ts +0 -97
  301. package/src/helpers/UUID.ts +0 -35
  302. package/src/helpers/peerIdFromPeerDescriptor.ts +0 -20
  303. package/test/unit/PeerID.test.ts +0 -22
  304. package/test/unit/UUID.test.ts +0 -55
@@ -4,6 +4,7 @@ import { Message, connection as WsConnection } from 'websocket'
4
4
  import { Logger } from '@streamr/utils'
5
5
  import { Url } from 'url'
6
6
  import { CUSTOM_GOING_AWAY, GOING_AWAY } from './ClientWebsocket'
7
+ import { createRandomConnectionId } from '../Connection'
7
8
 
8
9
  const logger = new Logger(module)
9
10
 
@@ -34,7 +35,7 @@ export class ServerWebsocket extends EventEmitter<ConnectionEvents> implements I
34
35
  this.onError = this.onError.bind(this)
35
36
 
36
37
  this.resourceURL = resourceURL
37
- this.connectionId = new ConnectionID()
38
+ this.connectionId = createRandomConnectionId()
38
39
 
39
40
  socket.on('message', this.onMessage)
40
41
  socket.on('close', this.onClose)
@@ -82,6 +83,7 @@ export class ServerWebsocket extends EventEmitter<ConnectionEvents> implements I
82
83
  // If in an Karma / Electron test, use the NodeJS implementation
83
84
  // of Buffer instead of the browser polyfill
84
85
 
86
+ // TODO: no need to check this.socket as it is always defined when stopped is false?
85
87
  if (!this.stopped && this.socket) {
86
88
  if (typeof NodeJsBuffer !== 'undefined') {
87
89
  this.socket.sendBytes(NodeJsBuffer.from(data))
@@ -104,6 +106,7 @@ export class ServerWebsocket extends EventEmitter<ConnectionEvents> implements I
104
106
  }
105
107
  }
106
108
 
109
+ // TODO could rename to "closeSilently?"
107
110
  public destroy(): void {
108
111
  if (!this.stopped) {
109
112
  this.removeAllListeners()
@@ -119,9 +122,22 @@ export class ServerWebsocket extends EventEmitter<ConnectionEvents> implements I
119
122
  }
120
123
 
121
124
  public getRemoteAddress(): string {
125
+ // TODO: no need to check this.socket as it is always defined when stopped is false?
122
126
  if (!this.stopped && this.socket) {
123
127
  return this.socket.remoteAddress
124
128
  } else {
129
+ // TODO throw
130
+ logger.error('Tried to get the remoteAddress of a stopped connection')
131
+ return ''
132
+ }
133
+ }
134
+
135
+ public getRemoteIp(): string {
136
+ // TODO: no need to check this.socket as it is always defined when stopped is false?
137
+ if (!this.stopped && this.socket) {
138
+ return this.socket.socket.remoteAddress!
139
+ } else {
140
+ // TODO throw
125
141
  logger.error('Tried to get the remoteAddress of a stopped connection')
126
142
  return ''
127
143
  }
@@ -12,14 +12,13 @@ import {
12
12
  WebsocketConnectionRequest
13
13
  } from '../../proto/packages/dht/protos/DhtRpc'
14
14
  import { WebsocketConnectorRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
15
- import { Logger, wait } from '@streamr/utils'
15
+ import { ipv4ToNumber, Logger, wait } from '@streamr/utils'
16
16
  import { ManagedConnection } from '../ManagedConnection'
17
17
  import { WebsocketServer } from './WebsocketServer'
18
18
  import { sendConnectivityRequest } from '../connectivityChecker'
19
19
  import { NatType, PortRange, TlsCertificate } from '../ConnectionManager'
20
20
  import { ServerWebsocket } from './ServerWebsocket'
21
21
  import { Handshaker } from '../Handshaker'
22
- import { areEqualPeerDescriptors, getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
23
22
  import { ParsedUrlQuery } from 'querystring'
24
23
  import { range, sample } from 'lodash'
25
24
  import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
@@ -29,7 +28,7 @@ import { AutoCertifierClientFacade } from './AutoCertifierClientFacade'
29
28
  import { attachConnectivityRequestHandler } from '../connectivityRequestHandler'
30
29
  import * as Err from '../../helpers/errors'
31
30
  import { Empty } from '../../proto/google/protobuf/empty'
32
- import { DhtAddress } from '../../identifiers'
31
+ import { DhtAddress, areEqualPeerDescriptors, getNodeIdFromPeerDescriptor } from '../../identifiers'
33
32
  import { version } from '../../../package.json'
34
33
  import { isCompatibleVersion } from '../../helpers/versionCompatibility'
35
34
 
@@ -46,7 +45,7 @@ const ENTRY_POINT_CONNECTION_ATTEMPTS = 5
46
45
  export interface WebsocketConnectorConfig {
47
46
  transport: ITransport
48
47
  onNewConnection: (connection: ManagedConnection) => boolean
49
- hasConnection: (peerDescriptor: PeerDescriptor) => boolean
48
+ hasConnection: (nodeId: DhtAddress) => boolean
50
49
  portRange?: PortRange
51
50
  maxMessageSize?: number
52
51
  host?: string
@@ -90,12 +89,11 @@ export class WebsocketConnector {
90
89
  private registerLocalRpcMethods(config: WebsocketConnectorConfig) {
91
90
  const rpcLocal = new WebsocketConnectorRpcLocal({
92
91
  connect: (targetPeerDescriptor: PeerDescriptor) => this.connect(targetPeerDescriptor),
93
- hasConnection: (targetPeerDescriptor: PeerDescriptor): boolean => {
94
- const nodeId = getNodeIdFromPeerDescriptor(targetPeerDescriptor)
92
+ hasConnection: (nodeId: DhtAddress): boolean => {
95
93
  if (this.connectingConnections.has(nodeId)
96
94
  || this.connectingConnections.has(nodeId)
97
95
  || this.ongoingConnectRequests.has(nodeId)
98
- || config.hasConnection(targetPeerDescriptor)
96
+ || config.hasConnection(nodeId)
99
97
  ) {
100
98
  return true
101
99
  } else {
@@ -167,7 +165,8 @@ export class WebsocketConnector {
167
165
  // TODO: this could throw if the server is not running
168
166
  const noServerConnectivityResponse: ConnectivityResponse = {
169
167
  host: '127.0.0.1',
170
- natType: NatType.UNKNOWN
168
+ natType: NatType.UNKNOWN,
169
+ ipAddress: ipv4ToNumber('127.0.0.1')
171
170
  }
172
171
  if (this.abortController.signal.aborted) {
173
172
  return noServerConnectivityResponse
@@ -183,7 +182,9 @@ export class WebsocketConnector {
183
182
  const preconfiguredConnectivityResponse: ConnectivityResponse = {
184
183
  host: this.host!,
185
184
  natType: NatType.OPEN_INTERNET,
186
- websocket: { host: this.host!, port: this.selectedPort!, tls: this.config.tlsCertificate !== undefined }
185
+ websocket: { host: this.host!, port: this.selectedPort!, tls: this.config.tlsCertificate !== undefined },
186
+ // TODO: maybe do a DNS lookup here?
187
+ ipAddress: ipv4ToNumber('127.0.0.1')
187
188
  }
188
189
  return preconfiguredConnectivityResponse
189
190
  } else {
@@ -7,10 +7,12 @@ import { IWebsocketConnectorRpc } from '../../proto/packages/dht/protos/DhtRpc.s
7
7
  import { DhtCallContext } from '../../rpc-protocol/DhtCallContext'
8
8
  import { ManagedConnection } from '../ManagedConnection'
9
9
  import { Empty } from '../../proto/google/protobuf/empty'
10
+ import { getNodeIdFromPeerDescriptor } from '../../identifiers'
11
+ import { DhtAddress } from '../../identifiers'
10
12
 
11
13
  interface WebsocketConnectorRpcLocalConfig {
12
14
  connect: (targetPeerDescriptor: PeerDescriptor) => ManagedConnection
13
- hasConnection: (targetPeerDescriptor: PeerDescriptor) => boolean
15
+ hasConnection: (nodeId: DhtAddress) => boolean
14
16
  onNewConnection: (connection: ManagedConnection) => boolean
15
17
  abortSignal: AbortSignal
16
18
  }
@@ -28,7 +30,7 @@ export class WebsocketConnectorRpcLocal implements IWebsocketConnectorRpc {
28
30
  return {}
29
31
  }
30
32
  const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
31
- if (!this.config.hasConnection(senderPeerDescriptor)) {
33
+ if (!this.config.hasConnection(getNodeIdFromPeerDescriptor(senderPeerDescriptor))) {
32
34
  const connection = this.config.connect(senderPeerDescriptor)
33
35
  this.config.onNewConnection(connection)
34
36
  }
@@ -2,9 +2,9 @@ import {
2
2
  WebsocketConnectionRequest
3
3
  } from '../../proto/packages/dht/protos/DhtRpc'
4
4
  import { Logger } from '@streamr/utils'
5
- import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
6
5
  import { RpcRemote } from '../../dht/contact/RpcRemote'
7
6
  import { WebsocketConnectorRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
7
+ import { getNodeIdFromPeerDescriptor } from '../../identifiers'
8
8
 
9
9
  const logger = new Logger(module)
10
10
 
@@ -10,7 +10,7 @@ import { WebsocketServerStartError } from '../../helpers/errors'
10
10
  import { PortRange, TlsCertificate } from '../ConnectionManager'
11
11
  import { range } from 'lodash'
12
12
  import fs from 'fs'
13
- import { UUID } from '../../helpers/UUID'
13
+ import { v4 as uuid } from 'uuid'
14
14
 
15
15
  const logger = new Logger(module)
16
16
 
@@ -77,7 +77,7 @@ export class WebsocketServer extends EventEmitter<ConnectionSourceEvents> {
77
77
  this.httpServer = createHttpServer(requestListener)
78
78
  } else {
79
79
  // TODO use config option or named constant?
80
- const certificate = createSelfSignedCertificate('streamr-self-signed-' + new UUID().toString(), 1000)
80
+ const certificate = createSelfSignedCertificate('streamr-self-signed-' + uuid(), 1000)
81
81
  this.httpServer = createHttpsServer({
82
82
  key: certificate.serverKey,
83
83
  cert: certificate.serverCert
@@ -1,56 +1,51 @@
1
- import { DhtNodeRpcRemote } from './DhtNodeRpcRemote'
1
+ import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
2
+ import {
3
+ Logger,
4
+ MetricsContext,
5
+ merge,
6
+ waitForCondition
7
+ } from '@streamr/utils'
2
8
  import { EventEmitter } from 'eventemitter3'
3
- import { RoutingRpcCommunicator } from '../transport/RoutingRpcCommunicator'
4
- import { PeerID } from '../helpers/PeerID'
9
+ import { sample } from 'lodash'
10
+ import { MarkRequired } from 'ts-essentials'
11
+ import { ConnectionManager, PortRange, TlsCertificate } from '../connection/ConnectionManager'
12
+ import { DefaultConnectorFacade, DefaultConnectorFacadeConfig } from '../connection/ConnectorFacade'
13
+ import { IceServer } from '../connection/webrtc/WebrtcConnector'
14
+ import { isBrowserEnvironment } from '../helpers/browser/isBrowserEnvironment'
15
+ import { DhtAddress, getNodeIdFromPeerDescriptor } from '../identifiers'
16
+ import { Any } from '../proto/google/protobuf/any'
5
17
  import {
6
18
  ClosestPeersRequest,
7
19
  ClosestPeersResponse,
8
- LeaveNotice,
9
20
  ConnectivityResponse,
10
- Message,
11
- NodeType,
12
- PeerDescriptor,
13
- PingRequest,
14
- PingResponse,
15
21
  DataEntry,
16
22
  ExternalFindDataRequest,
17
23
  ExternalFindDataResponse,
18
24
  ExternalStoreDataRequest,
19
25
  ExternalStoreDataResponse,
20
- RecursiveOperation,
26
+ LeaveNotice,
27
+ Message,
28
+ PeerDescriptor,
29
+ PingRequest,
30
+ PingResponse,
31
+ RecursiveOperation
21
32
  } from '../proto/packages/dht/protos/DhtRpc'
22
- import { ITransport, TransportEvents } from '../transport/ITransport'
23
- import { ConnectionManager, PortRange, TlsCertificate } from '../connection/ConnectionManager'
24
33
  import { ExternalApiRpcClient, StoreRpcClient } from '../proto/packages/dht/protos/DhtRpc.client'
25
- import {
26
- Logger,
27
- MetricsContext,
28
- merge,
29
- waitForCondition
30
- } from '@streamr/utils'
31
- import { Any } from '../proto/google/protobuf/any'
32
- import {
33
- getNodeIdFromPeerDescriptor
34
- } from '../helpers/peerIdFromPeerDescriptor'
35
- import { Router } from './routing/Router'
36
- import { RecursiveOperationManager, RecursiveOperationResult } from './recursive-operation/RecursiveOperationManager'
37
- import { StoreManager } from './store/StoreManager'
38
- import { PeerDiscovery } from './discovery/PeerDiscovery'
39
- import { LocalDataStore } from './store/LocalDataStore'
40
- import { IceServer } from '../connection/webrtc/WebrtcConnector'
41
- import { ExternalApiRpcRemote } from './ExternalApiRpcRemote'
42
- import { UUID } from '../helpers/UUID'
43
- import { isBrowserEnvironment } from '../helpers/browser/isBrowserEnvironment'
44
- import { sample } from 'lodash'
45
- import { DefaultConnectorFacade, DefaultConnectorFacadeConfig } from '../connection/ConnectorFacade'
46
- import { MarkRequired } from 'ts-essentials'
34
+ import { ITransport, TransportEvents } from '../transport/ITransport'
35
+ import { RoutingRpcCommunicator } from '../transport/RoutingRpcCommunicator'
36
+ import { ServiceID } from '../types/ServiceID'
47
37
  import { DhtNodeRpcLocal } from './DhtNodeRpcLocal'
48
- import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
38
+ import { DhtNodeRpcRemote } from './DhtNodeRpcRemote'
49
39
  import { ExternalApiRpcLocal } from './ExternalApiRpcLocal'
40
+ import { ExternalApiRpcRemote } from './ExternalApiRpcRemote'
50
41
  import { PeerManager } from './PeerManager'
51
- import { ServiceID } from '../types/ServiceID'
52
- import { DhtAddress, DhtAddressRaw, getRawFromDhtAddress } from '../identifiers'
42
+ import { PeerDiscovery } from './discovery/PeerDiscovery'
43
+ import { RecursiveOperationManager, RecursiveOperationResult } from './recursive-operation/RecursiveOperationManager'
44
+ import { Router } from './routing/Router'
45
+ import { LocalDataStore } from './store/LocalDataStore'
46
+ import { StoreManager } from './store/StoreManager'
53
47
  import { StoreRpcRemote } from './store/StoreRpcRemote'
48
+ import { createPeerDescriptor } from '../helpers/createPeerDescriptor'
54
49
 
55
50
  export interface DhtNodeEvents {
56
51
  newContact: (peerDescriptor: PeerDescriptor, closestPeers: PeerDescriptor[]) => void
@@ -79,7 +74,7 @@ export interface DhtNodeOptions {
79
74
  websocketHost?: string
80
75
  websocketPortRange?: PortRange
81
76
  websocketServerEnableTls?: boolean
82
- peerId?: string
77
+ nodeId?: DhtAddress
83
78
 
84
79
  rpcRequestTimeout?: number
85
80
  iceServers?: IceServer[]
@@ -109,28 +104,12 @@ type StrictDhtNodeOptions = MarkRequired<DhtNodeOptions,
109
104
  'storeMaxTtl' |
110
105
  'networkConnectivityTimeout' |
111
106
  'storageRedundancyFactor' |
112
- 'metricsContext' |
113
- 'peerId'>
107
+ 'metricsContext'>
114
108
 
115
109
  const logger = new Logger(module)
116
110
 
117
111
  export type Events = TransportEvents & DhtNodeEvents
118
112
 
119
- export const createPeerDescriptor = (msg?: ConnectivityResponse, peerId?: string): PeerDescriptor => {
120
- let nodeId: DhtAddressRaw
121
- if (msg) {
122
- nodeId = (peerId !== undefined) ? getRawFromDhtAddress(peerId as DhtAddress) : PeerID.fromIp(msg.host).value
123
- } else {
124
- nodeId = getRawFromDhtAddress(peerId! as DhtAddress)
125
- }
126
- const nodeType = isBrowserEnvironment() ? NodeType.BROWSER : NodeType.NODEJS
127
- const ret: PeerDescriptor = { nodeId, type: nodeType }
128
- if (msg && msg.websocket) {
129
- ret.websocket = { host: msg.websocket.host, port: msg.websocket.port, tls: msg.websocket.tls }
130
- }
131
- return ret
132
- }
133
-
134
113
  export class DhtNode extends EventEmitter<Events> implements ITransport {
135
114
 
136
115
  private readonly config: StrictDhtNodeOptions
@@ -162,10 +141,9 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
162
141
  storeMaxTtl: 60000,
163
142
  networkConnectivityTimeout: 10000,
164
143
  storageRedundancyFactor: 5,
165
- metricsContext: new MetricsContext(),
166
- peerId: new UUID().toHex()
144
+ metricsContext: new MetricsContext()
167
145
  }, conf)
168
- this.localDataStore = new LocalDataStore(this.config.storeMaxTtl)
146
+ this.localDataStore = new LocalDataStore(this.config.storeMaxTtl)
169
147
  this.send = this.send.bind(this)
170
148
  }
171
149
 
@@ -214,7 +192,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
214
192
  min: this.config.peerDescriptor.websocket.port,
215
193
  max: this.config.peerDescriptor.websocket.port
216
194
  }
217
- // If websocketPortRange is given, create ws server using it, websocketHost can be undefined
195
+ // If websocketPortRange is given, create ws server using it, websocketHost can be undefined
218
196
  } else if (this.config.websocketPortRange) {
219
197
  connectorFacadeConfig.websocketHost = this.config.websocketHost
220
198
  connectorFacadeConfig.websocketPortRange = this.config.websocketPortRange
@@ -334,10 +312,10 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
334
312
  this.emit('connected', peerDescriptor)
335
313
  })
336
314
  this.transport!.on('disconnected', (peerDescriptor: PeerDescriptor, gracefulLeave: boolean) => {
337
- this.peerManager!.handleDisconnected(peerDescriptor, gracefulLeave)
315
+ this.peerManager!.handleDisconnected(getNodeIdFromPeerDescriptor(peerDescriptor), gracefulLeave)
338
316
  this.emit('disconnected', peerDescriptor, gracefulLeave)
339
317
  })
340
- this.transport!.getAllConnectionPeerDescriptors().forEach((peer) => {
318
+ this.transport!.getConnections().forEach((peer) => {
341
319
  this.peerManager!.handleConnected(peer)
342
320
  })
343
321
  }
@@ -353,7 +331,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
353
331
  .map((dhtPeer: DhtNodeRpcRemote) => dhtPeer.getPeerDescriptor())
354
332
  },
355
333
  addNewContact: (contact: PeerDescriptor) => this.peerManager!.handleNewPeers([contact]),
356
- removeContact: (contact: PeerDescriptor) => this.removeContact(contact)
334
+ removeContact: (nodeId: DhtAddress) => this.removeContact(nodeId)
357
335
  })
358
336
  this.rpcCommunicator!.registerRpcMethod(ClosestPeersRequest, ClosestPeersResponse, 'getClosestPeers',
359
337
  (req: ClosestPeersRequest, context) => dhtNodeRpcLocal.getClosestPeers(req, context))
@@ -362,7 +340,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
362
340
  this.rpcCommunicator!.registerRpcNotification(LeaveNotice, 'leaveNotice',
363
341
  (_req: LeaveNotice, context) => dhtNodeRpcLocal.leaveNotice(context))
364
342
  const externalApiRpcLocal = new ExternalApiRpcLocal({
365
- executeRecursiveOperation: (key: DhtAddress, operation: RecursiveOperation, excludedPeer: PeerDescriptor) => {
343
+ executeRecursiveOperation: (key: DhtAddress, operation: RecursiveOperation, excludedPeer: DhtAddress) => {
366
344
  return this.executeRecursiveOperation(key, operation, excludedPeer)
367
345
  },
368
346
  storeDataToDht: (key: DhtAddress, data: Any, creator?: DhtAddress) => this.storeDataToDht(key, data, creator)
@@ -395,10 +373,10 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
395
373
  }
396
374
 
397
375
  private generatePeerDescriptorCallBack(connectivityResponse: ConnectivityResponse) {
398
- if (this.config.peerDescriptor) {
376
+ if (this.config.peerDescriptor !== undefined) {
399
377
  this.localPeerDescriptor = this.config.peerDescriptor
400
378
  } else {
401
- this.localPeerDescriptor = createPeerDescriptor(connectivityResponse, this.config.peerId)
379
+ this.localPeerDescriptor = createPeerDescriptor(connectivityResponse, this.config.nodeId)
402
380
  }
403
381
  return this.localPeerDescriptor
404
382
  }
@@ -409,20 +387,20 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
409
387
  limit).map((peer) => peer.getPeerDescriptor()
410
388
  )
411
389
  }
412
-
390
+
413
391
  public getNodeId(): DhtAddress {
414
392
  return getNodeIdFromPeerDescriptor(this.localPeerDescriptor!)
415
393
  }
416
394
 
417
- public getNumberOfNeighbors(): number {
418
- return this.peerManager!.getNumberOfNeighbors()
395
+ public getNeighborCount(): number {
396
+ return this.peerManager!.getNeighborCount()
419
397
  }
420
398
 
421
- public removeContact(contact: PeerDescriptor): void {
399
+ public removeContact(nodeId: DhtAddress): void {
422
400
  if (!this.started) { // the stopped state is checked in PeerManager
423
401
  return
424
402
  }
425
- this.peerManager!.handlePeerLeaving(contact)
403
+ this.peerManager!.handlePeerLeaving(nodeId)
426
404
  }
427
405
 
428
406
  public async send(msg: Message): Promise<void> {
@@ -439,11 +417,11 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
439
417
  ) : []
440
418
  }
441
419
 
442
- public async joinDht(entryPointDescriptors: PeerDescriptor[], doAdditionalRandomPeerDiscovery?: boolean, retry?: boolean): Promise<void> {
420
+ public async joinDht(entryPointDescriptors: PeerDescriptor[], doAdditionalDistantPeerDiscovery?: boolean, retry?: boolean): Promise<void> {
443
421
  if (!this.started) {
444
422
  throw new Error('Cannot join DHT before calling start() on DhtNode')
445
423
  }
446
- await this.peerDiscovery!.joinDht(entryPointDescriptors, doAdditionalRandomPeerDiscovery, retry)
424
+ await this.peerDiscovery!.joinDht(entryPointDescriptors, doAdditionalDistantPeerDiscovery, retry)
447
425
  }
448
426
 
449
427
  // TODO make this private and unify the public API of find/fetch/store/delete methods
@@ -451,7 +429,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
451
429
  public async executeRecursiveOperation(
452
430
  key: DhtAddress,
453
431
  operation: RecursiveOperation,
454
- excludedPeer?: PeerDescriptor
432
+ excludedPeer?: DhtAddress
455
433
  ): Promise<RecursiveOperationResult> {
456
434
  return this.recursiveOperationManager!.execute(key, operation, excludedPeer)
457
435
  }
@@ -507,29 +485,28 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
507
485
  return this.localPeerDescriptor!
508
486
  }
509
487
 
510
- public getAllConnectionPeerDescriptors(): PeerDescriptor[] {
488
+ public getConnections(): PeerDescriptor[] {
511
489
  return Array.from(this.peerManager!.connections.values()).map((peer) => peer.getPeerDescriptor())
512
490
  }
513
491
 
514
- // TODO rename to getNeighbors
515
- public getAllNeighborPeerDescriptors(): PeerDescriptor[] {
516
- return this.peerManager!.getNeighbors()
492
+ public getNeighbors(): PeerDescriptor[] {
493
+ return this.started ? this.peerManager!.getNeighbors() : []
517
494
  }
518
495
 
519
- public getNumberOfConnections(): number {
520
- return this.peerManager!.getNumberOfConnections()
496
+ public getConnectionCount(): number {
497
+ return this.peerManager!.getConnectionCount()
521
498
  }
522
499
 
523
- public getNumberOfLocalLockedConnections(): number {
524
- return this.connectionManager!.getNumberOfLocalLockedConnections()
500
+ public getLocalLockedConnectionCount(): number {
501
+ return this.connectionManager!.getLocalLockedConnectionCount()
525
502
  }
526
503
 
527
- public getNumberOfRemoteLockedConnections(): number {
528
- return this.connectionManager!.getNumberOfRemoteLockedConnections()
504
+ public getRemoteLockedConnectionCount(): number {
505
+ return this.connectionManager!.getRemoteLockedConnectionCount()
529
506
  }
530
507
 
531
- public getNumberOfWeakLockedConnections(): number {
532
- return this.connectionManager!.getNumberOfWeakLockedConnections()
508
+ public getWeakLockedConnectionCount(): number {
509
+ return this.connectionManager!.getWeakLockedConnectionCount()
533
510
  }
534
511
 
535
512
  public async waitForNetworkConnectivity(): Promise<void> {
@@ -537,7 +514,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
537
514
  if (!this.peerManager) {
538
515
  return false
539
516
  } else {
540
- return (this.peerManager.getNumberOfConnections() > 0)
517
+ return (this.peerManager.getConnectionCount() > 0)
541
518
  }
542
519
  }, this.config.networkConnectivityTimeout, 100, this.abortController.signal)
543
520
  }
@@ -1,6 +1,5 @@
1
1
  import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
2
2
  import { Logger } from '@streamr/utils'
3
- import { getNodeIdFromPeerDescriptor } from '../helpers/peerIdFromPeerDescriptor'
4
3
  import { Empty } from '../proto/google/protobuf/empty'
5
4
  import {
6
5
  ClosestPeersRequest,
@@ -11,13 +10,13 @@ import {
11
10
  } from '../proto/packages/dht/protos/DhtRpc'
12
11
  import { IDhtNodeRpc } from '../proto/packages/dht/protos/DhtRpc.server'
13
12
  import { DhtCallContext } from '../rpc-protocol/DhtCallContext'
14
- import { DhtAddress, getDhtAddressFromRaw } from '../identifiers'
13
+ import { DhtAddress, getDhtAddressFromRaw, getNodeIdFromPeerDescriptor } from '../identifiers'
15
14
 
16
15
  interface DhtNodeRpcLocalConfig {
17
16
  peerDiscoveryQueryBatchSize: number
18
17
  getClosestPeersTo: (nodeId: DhtAddress, limit: number) => PeerDescriptor[]
19
18
  addNewContact: (contact: PeerDescriptor) => void
20
- removeContact: (contact: PeerDescriptor) => void
19
+ removeContact: (nodeId: DhtAddress) => void
21
20
  }
22
21
 
23
22
  const logger = new Logger(module)
@@ -53,8 +52,9 @@ export class DhtNodeRpcLocal implements IDhtNodeRpc {
53
52
  async leaveNotice(context: ServerCallContext): Promise<Empty> {
54
53
  // TODO check signature??
55
54
  const sender = (context as DhtCallContext).incomingSourceDescriptor!
56
- logger.trace('received leave notice: ' + getNodeIdFromPeerDescriptor(sender))
57
- this.config.removeContact(sender)
55
+ const senderNodeId = getNodeIdFromPeerDescriptor(sender)
56
+ logger.trace('received leave notice: ' + senderNodeId)
57
+ this.config.removeContact(senderNodeId)
58
58
  return {}
59
59
  }
60
60
  }
@@ -1,8 +1,7 @@
1
1
  import { RpcCommunicator } from '@streamr/proto-rpc'
2
2
  import { Logger } from '@streamr/utils'
3
3
  import { v4 } from 'uuid'
4
- import { DhtAddress, DhtAddressRaw, getRawFromDhtAddress } from '../identifiers'
5
- import { getNodeIdFromPeerDescriptor } from '../helpers/peerIdFromPeerDescriptor'
4
+ import { DhtAddress, DhtAddressRaw, getNodeIdFromPeerDescriptor, getRawFromDhtAddress } from '../identifiers'
6
5
  import {
7
6
  ClosestPeersRequest,
8
7
  PeerDescriptor,
@@ -11,6 +10,7 @@ import {
11
10
  import { DhtNodeRpcClient } from '../proto/packages/dht/protos/DhtRpc.client'
12
11
  import { ServiceID } from '../types/ServiceID'
13
12
  import { RpcRemote } from './contact/RpcRemote'
13
+ import { DhtCallContext } from '../rpc-protocol/DhtCallContext'
14
14
 
15
15
  const logger = new Logger(module)
16
16
 
@@ -31,7 +31,7 @@ export class DhtNodeRpcRemote extends RpcRemote<DhtNodeRpcClient> implements KBu
31
31
  localPeerDescriptor: PeerDescriptor,
32
32
  peerDescriptor: PeerDescriptor,
33
33
  serviceId: ServiceID,
34
- rpcCommunicator: RpcCommunicator,
34
+ rpcCommunicator: RpcCommunicator<DhtCallContext>,
35
35
  rpcRequestTimeout?: number
36
36
  ) {
37
37
  super(localPeerDescriptor, peerDescriptor, rpcCommunicator, DhtNodeRpcClient, rpcRequestTimeout)
@@ -11,15 +11,14 @@ import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
11
11
  import { DhtCallContext } from '../rpc-protocol/DhtCallContext'
12
12
  import { RecursiveOperationResult } from './recursive-operation/RecursiveOperationManager'
13
13
  import { Any } from '../proto/google/protobuf/any'
14
- import { DhtAddress } from '../identifiers'
15
- import { getNodeIdFromPeerDescriptor } from '../helpers/peerIdFromPeerDescriptor'
14
+ import { DhtAddress, getNodeIdFromPeerDescriptor } from '../identifiers'
16
15
  import { getDhtAddressFromRaw } from '../identifiers'
17
16
 
18
17
  interface ExternalApiRpcLocalConfig {
19
18
  executeRecursiveOperation: (
20
19
  targetId: DhtAddress,
21
20
  operation: RecursiveOperation,
22
- excludedPeer: PeerDescriptor
21
+ excludedPeer: DhtAddress
23
22
  ) => Promise<RecursiveOperationResult>
24
23
  storeDataToDht: (
25
24
  key: DhtAddress,
@@ -41,7 +40,7 @@ export class ExternalApiRpcLocal implements IExternalApiRpc {
41
40
  const result = await this.config.executeRecursiveOperation(
42
41
  getDhtAddressFromRaw(findDataRequest.key),
43
42
  RecursiveOperation.FETCH_DATA,
44
- senderPeerDescriptor
43
+ getNodeIdFromPeerDescriptor(senderPeerDescriptor)
45
44
  )
46
45
  return ExternalFindDataResponse.create({ entries: result.dataEntries ?? [] })
47
46
  }