@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
@@ -3,10 +3,11 @@ import { ConnectionManager } from '../../src/connection/ConnectionManager'
3
3
  import { DefaultConnectorFacade } from '../../src/connection/ConnectorFacade'
4
4
  import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
5
5
  import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTransport'
6
- import { ITransport } from '../../src/exports'
6
+ import { ITransport } from '../../src/transport/ITransport'
7
7
  import { PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
8
8
  import { getRandomRegion } from '../../dist/src/connection/simulator/pings'
9
9
  import { createMockPeerDescriptor } from '../utils/utils'
10
+ import { getNodeIdFromPeerDescriptor } from '../../src/identifiers'
10
11
 
11
12
  const createConnectionManager = (localPeerDescriptor: PeerDescriptor, transport: ITransport) => {
12
13
  return new ConnectionManager({
@@ -55,114 +56,126 @@ describe('Connection Locking', () => {
55
56
  })
56
57
 
57
58
  it('can lock connections', async () => {
59
+ const nodeId1 = getNodeIdFromPeerDescriptor(mockPeerDescriptor1)
60
+ const nodeId2 = getNodeIdFromPeerDescriptor(mockPeerDescriptor2)
58
61
  await Promise.all([
59
- waitForCondition(() => connectionManager2.hasRemoteLockedConnection(mockPeerDescriptor1)),
62
+ waitForCondition(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
60
63
  connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock')
61
64
  ])
62
- expect(connectionManager1.hasConnection(mockPeerDescriptor2)).toEqual(true)
63
- expect(connectionManager1.hasLocalLockedConnection(mockPeerDescriptor2)).toEqual(true)
64
- expect(connectionManager2.hasRemoteLockedConnection(mockPeerDescriptor1)).toEqual(true)
65
+ expect(connectionManager1.hasConnection(nodeId2)).toEqual(true)
66
+ expect(connectionManager1.hasLocalLockedConnection(nodeId2)).toEqual(true)
67
+ expect(connectionManager2.hasRemoteLockedConnection(nodeId1)).toEqual(true)
65
68
  })
66
69
 
67
70
  it('Multiple services on the same peer', async () => {
71
+ const nodeId1 = getNodeIdFromPeerDescriptor(mockPeerDescriptor1)
72
+ const nodeId2 = getNodeIdFromPeerDescriptor(mockPeerDescriptor2)
68
73
  await Promise.all([
69
- waitForCondition(() => connectionManager2.hasRemoteLockedConnection(mockPeerDescriptor1)),
74
+ waitForCondition(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
70
75
  connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock1')
71
76
  ])
72
77
  await Promise.all([
73
- waitForCondition(() => connectionManager2.hasRemoteLockedConnection(mockPeerDescriptor1)),
78
+ waitForCondition(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
74
79
  connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock2')
75
80
  ])
76
- expect(connectionManager1.hasConnection(mockPeerDescriptor2)).toEqual(true)
77
- expect(connectionManager1.hasLocalLockedConnection(mockPeerDescriptor2)).toEqual(true)
78
- expect(connectionManager2.hasRemoteLockedConnection(mockPeerDescriptor1)).toEqual(true)
81
+ expect(connectionManager1.hasConnection(nodeId2)).toEqual(true)
82
+ expect(connectionManager1.hasLocalLockedConnection(nodeId2)).toEqual(true)
83
+ expect(connectionManager2.hasRemoteLockedConnection(nodeId1)).toEqual(true)
79
84
  })
80
85
 
81
86
  it('can unlock connections', async () => {
87
+ const nodeId1 = getNodeIdFromPeerDescriptor(mockPeerDescriptor1)
88
+ const nodeId2 = getNodeIdFromPeerDescriptor(mockPeerDescriptor2)
82
89
  await Promise.all([
83
- waitForCondition(() => connectionManager2.hasRemoteLockedConnection(mockPeerDescriptor1)),
90
+ waitForCondition(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
84
91
  connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock')
85
92
  ])
86
- expect(connectionManager1.hasConnection(mockPeerDescriptor2))
87
- expect(connectionManager2.hasLocalLockedConnection(mockPeerDescriptor2)).toEqual(false)
88
- expect(connectionManager2.hasRemoteLockedConnection(mockPeerDescriptor1)).toEqual(true)
93
+ expect(connectionManager1.hasConnection(nodeId2))
94
+ expect(connectionManager2.hasLocalLockedConnection(nodeId2)).toEqual(false)
95
+ expect(connectionManager2.hasRemoteLockedConnection(nodeId1)).toEqual(true)
89
96
 
90
97
  connectionManager1.unlockConnection(mockPeerDescriptor2, 'testLock')
91
- expect(connectionManager1.hasLocalLockedConnection(mockPeerDescriptor2)).toEqual(false)
92
- await waitForCondition(() => connectionManager2.hasRemoteLockedConnection(mockPeerDescriptor1) === false)
93
- expect(connectionManager1.hasConnection(mockPeerDescriptor1)).toEqual(false)
98
+ expect(connectionManager1.hasLocalLockedConnection(nodeId2)).toEqual(false)
99
+ await waitForCondition(() => connectionManager2.hasRemoteLockedConnection(nodeId1) === false)
100
+ expect(connectionManager1.hasConnection(nodeId1)).toEqual(false)
94
101
  })
95
102
 
96
103
  it('unlocking multiple services', async () => {
104
+ const nodeId1 = getNodeIdFromPeerDescriptor(mockPeerDescriptor1)
105
+ const nodeId2 = getNodeIdFromPeerDescriptor(mockPeerDescriptor2)
97
106
  await Promise.all([
98
- waitForCondition(() => connectionManager2.hasRemoteLockedConnection(mockPeerDescriptor1)),
107
+ waitForCondition(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
99
108
  connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock1')
100
109
  ])
101
110
  await Promise.all([
102
- waitForCondition(() => connectionManager2.hasRemoteLockedConnection(mockPeerDescriptor1)),
111
+ waitForCondition(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
103
112
  connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock2')
104
113
  ])
105
114
 
106
- expect(connectionManager1.hasConnection(mockPeerDescriptor2))
107
- expect(connectionManager2.hasLocalLockedConnection(mockPeerDescriptor1)).toEqual(false)
115
+ expect(connectionManager1.hasConnection(nodeId2))
116
+ expect(connectionManager2.hasLocalLockedConnection(nodeId1)).toEqual(false)
108
117
 
109
118
  connectionManager1.unlockConnection(mockPeerDescriptor2, 'testLock1')
110
- expect(connectionManager1.hasLocalLockedConnection(mockPeerDescriptor2)).toEqual(true)
119
+ expect(connectionManager1.hasLocalLockedConnection(nodeId2)).toEqual(true)
111
120
 
112
121
  connectionManager1.unlockConnection(mockPeerDescriptor2, 'testLock2')
113
- expect(connectionManager1.hasLocalLockedConnection(mockPeerDescriptor2)).toEqual(false)
114
- expect(connectionManager1.hasConnection(mockPeerDescriptor1)).toEqual(false)
122
+ expect(connectionManager1.hasLocalLockedConnection(nodeId2)).toEqual(false)
123
+ expect(connectionManager1.hasConnection(nodeId1)).toEqual(false)
115
124
  })
116
125
 
117
126
  it('maintains connection if both sides initially lock and then one end unlocks', async () => {
127
+ const nodeId1 = getNodeIdFromPeerDescriptor(mockPeerDescriptor1)
128
+ const nodeId2 = getNodeIdFromPeerDescriptor(mockPeerDescriptor2)
118
129
  await Promise.all([
119
- waitForCondition(() => connectionManager2.hasRemoteLockedConnection(mockPeerDescriptor1)),
120
- waitForCondition(() => connectionManager1.hasRemoteLockedConnection(mockPeerDescriptor2)),
130
+ waitForCondition(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
131
+ waitForCondition(() => connectionManager1.hasRemoteLockedConnection(nodeId2)),
121
132
  connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock1'),
122
133
  connectionManager2.lockConnection(mockPeerDescriptor1, 'testLock1')
123
134
  ])
124
135
 
125
- expect(connectionManager1.hasLocalLockedConnection(mockPeerDescriptor2))
126
- expect(connectionManager2.hasLocalLockedConnection(mockPeerDescriptor1))
136
+ expect(connectionManager1.hasLocalLockedConnection(nodeId2))
137
+ expect(connectionManager2.hasLocalLockedConnection(nodeId1))
127
138
 
128
139
  connectionManager1.unlockConnection(mockPeerDescriptor2, 'testLock1')
129
140
  await waitForCondition(() =>
130
- connectionManager1.hasRemoteLockedConnection(mockPeerDescriptor2)
131
- && !connectionManager1.hasLocalLockedConnection(mockPeerDescriptor2)
132
- && !connectionManager2.hasRemoteLockedConnection(mockPeerDescriptor1)
133
- && connectionManager2.hasLocalLockedConnection(mockPeerDescriptor1)
141
+ connectionManager1.hasRemoteLockedConnection(nodeId2)
142
+ && !connectionManager1.hasLocalLockedConnection(nodeId2)
143
+ && !connectionManager2.hasRemoteLockedConnection(nodeId1)
144
+ && connectionManager2.hasLocalLockedConnection(nodeId1)
134
145
  )
135
146
 
136
- expect(connectionManager2.hasConnection(mockPeerDescriptor1)).toEqual(true)
137
- expect(connectionManager1.hasConnection(mockPeerDescriptor2)).toEqual(true)
147
+ expect(connectionManager2.hasConnection(nodeId1)).toEqual(true)
148
+ expect(connectionManager1.hasConnection(nodeId2)).toEqual(true)
138
149
  })
139
150
 
140
151
  it('unlocks after graceful disconnect', async () => {
152
+ const nodeId1 = getNodeIdFromPeerDescriptor(mockPeerDescriptor1)
153
+ const nodeId2 = getNodeIdFromPeerDescriptor(mockPeerDescriptor2)
141
154
  await Promise.all([
142
- waitForCondition(() => connectionManager2.hasRemoteLockedConnection(mockPeerDescriptor1)),
143
- waitForCondition(() => connectionManager1.hasRemoteLockedConnection(mockPeerDescriptor2)),
155
+ waitForCondition(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
156
+ waitForCondition(() => connectionManager1.hasRemoteLockedConnection(nodeId2)),
144
157
  connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock1'),
145
158
  connectionManager2.lockConnection(mockPeerDescriptor1, 'testLock1')
146
159
  ])
147
- expect(connectionManager1.hasConnection(mockPeerDescriptor2))
148
- expect(connectionManager2.hasLocalLockedConnection(mockPeerDescriptor1)).toEqual(true)
149
- expect(connectionManager2.hasRemoteLockedConnection(mockPeerDescriptor1)).toEqual(true)
160
+ expect(connectionManager1.hasConnection(nodeId2))
161
+ expect(connectionManager2.hasLocalLockedConnection(nodeId1)).toEqual(true)
162
+ expect(connectionManager2.hasRemoteLockedConnection(nodeId1)).toEqual(true)
150
163
 
151
164
  //@ts-expect-error private field
152
165
  await connectionManager1.gracefullyDisconnectAsync(mockPeerDescriptor2)
153
166
 
154
167
  await waitForCondition(() =>
155
- !connectionManager1.hasRemoteLockedConnection(mockPeerDescriptor2)
156
- && !connectionManager1.hasLocalLockedConnection(mockPeerDescriptor2)
168
+ !connectionManager1.hasRemoteLockedConnection(nodeId2)
169
+ && !connectionManager1.hasLocalLockedConnection(nodeId2)
157
170
  )
158
171
  await waitForCondition(() =>
159
- !connectionManager2.hasRemoteLockedConnection(mockPeerDescriptor1)
160
- && !connectionManager2.hasLocalLockedConnection(mockPeerDescriptor1)
172
+ !connectionManager2.hasRemoteLockedConnection(nodeId1)
173
+ && !connectionManager2.hasLocalLockedConnection(nodeId1)
161
174
  )
162
- await waitForCondition(() => !connectionManager2.hasConnection(mockPeerDescriptor1))
163
- await waitForCondition(() => !connectionManager1.hasConnection(mockPeerDescriptor2))
175
+ await waitForCondition(() => !connectionManager2.hasConnection(nodeId1))
176
+ await waitForCondition(() => !connectionManager1.hasConnection(nodeId2))
164
177
 
165
- expect(connectionManager1.hasConnection(mockPeerDescriptor2)).toEqual(false)
166
- expect(connectionManager2.hasConnection(mockPeerDescriptor1)).toEqual(false)
178
+ expect(connectionManager1.hasConnection(nodeId2)).toEqual(false)
179
+ expect(connectionManager2.hasConnection(nodeId1)).toEqual(false)
167
180
  }, 10000)
168
181
  })
@@ -1,15 +1,15 @@
1
+ import { Logger, MetricsContext, waitForEvent3 } from '@streamr/utils'
2
+ import { MarkOptional } from 'ts-essentials'
1
3
  import { ConnectionManager } from '../../src/connection/ConnectionManager'
2
- import { ConnectivityResponse, Message, MessageType, NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
4
+ import { DefaultConnectorFacade, DefaultConnectorFacadeConfig } from '../../src/connection/ConnectorFacade'
3
5
  import { Simulator } from '../../src/connection/simulator/Simulator'
4
- import { createPeerDescriptor } from '../../src/dht/DhtNode'
6
+ import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTransport'
7
+ import { createPeerDescriptor } from '../../src/helpers/createPeerDescriptor'
8
+ import { createRandomDhtAddress, getRawFromDhtAddress } from '../../src/identifiers'
9
+ import { ConnectivityResponse, Message, MessageType, NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
5
10
  import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
6
- import { Logger, MetricsContext, waitForEvent3 } from '@streamr/utils'
7
- import { SimulatorTransport } from '../../src/exports'
8
- import { DefaultConnectorFacade, DefaultConnectorFacadeConfig } from '../../src/connection/ConnectorFacade'
9
- import { MarkOptional } from 'ts-essentials'
10
11
  import { TransportEvents } from '../../src/transport/ITransport'
11
12
  import { createMockPeerDescriptor } from '../utils/utils'
12
- import { createRandomDhtAddress, getRawFromDhtAddress } from '../../src/identifiers'
13
13
 
14
14
  const SERVICE_ID = 'demo'
15
15
 
@@ -292,6 +292,7 @@ describe('ConnectionManager', () => {
292
292
  await Promise.all([disconnectedPromise1, disconnectedPromise2])
293
293
  await connectionManager3.stop()
294
294
  await connectionManager4.stop()
295
+ simulator2.stop()
295
296
  })
296
297
 
297
298
  it('Cannot send to own WebsocketServer if nodeIds do not match', async () => {
@@ -21,10 +21,10 @@ const runTest = async (latencyType: LatencyType) => {
21
21
  await entryPoint.joinDht([entrypointDescriptor])
22
22
  await Promise.all(nodes.map((node) => node.joinDht([entrypointDescriptor])))
23
23
  nodes.forEach((node) => {
24
- expect(node.getNumberOfNeighbors()).toBeGreaterThanOrEqual(NUM_OF_NODES_PER_KBUCKET / 2)
24
+ expect(node.getNeighborCount()).toBeGreaterThanOrEqual(NUM_OF_NODES_PER_KBUCKET / 2)
25
25
  expect(node.getClosestContacts().length).toBeGreaterThanOrEqual(NUM_OF_NODES_PER_KBUCKET / 2)
26
26
  })
27
- expect(entryPoint.getNumberOfNeighbors()).toBeGreaterThanOrEqual(NUM_OF_NODES_PER_KBUCKET / 2)
27
+ expect(entryPoint.getNeighborCount()).toBeGreaterThanOrEqual(NUM_OF_NODES_PER_KBUCKET / 2)
28
28
 
29
29
  await Promise.all([
30
30
  entryPoint.stop(),
@@ -1,7 +1,6 @@
1
1
  import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
2
2
  import { DhtNode } from '../../src/dht/DhtNode'
3
- import { createRandomDhtAddress, getDhtAddressFromRaw } from '../../src/identifiers'
4
- import { getNodeIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
3
+ import { createRandomDhtAddress, getDhtAddressFromRaw, getNodeIdFromPeerDescriptor } from '../../src/identifiers'
5
4
  import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
6
5
  import { createMockConnectionDhtNode } from '../utils/utils'
7
6
 
@@ -8,15 +8,16 @@ import {
8
8
  PingResponse
9
9
  } from '../../src/proto/packages/dht/protos/DhtRpc'
10
10
  import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
11
- import { getNodeIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
11
+ import { DhtCallContext } from '../../src/rpc-protocol/DhtCallContext'
12
+ import { getNodeIdFromPeerDescriptor } from '../../src/identifiers'
12
13
 
13
14
  const SERVICE_ID = 'test'
14
15
 
15
16
  describe('DhtNodeRpcRemote', () => {
16
17
 
17
18
  let rpcRemote: DhtNodeRpcRemote
18
- let clientRpcCommunicator: RpcCommunicator
19
- let serverRpcCommunicator: RpcCommunicator
19
+ let clientRpcCommunicator: RpcCommunicator<DhtCallContext>
20
+ let serverRpcCommunicator: RpcCommunicator<DhtCallContext>
20
21
  const clientPeerDescriptor = createMockPeerDescriptor()
21
22
  const serverPeerDescriptor = createMockPeerDescriptor()
22
23
  const mockDhtRpc = createMockDhtRpc(createMockPeers())
@@ -4,12 +4,13 @@ import { DhtNodeRpcClient } from '../../src/proto/packages/dht/protos/DhtRpc.cli
4
4
  import { ClosestPeersRequest, ClosestPeersResponse } from '../../src/proto/packages/dht/protos/DhtRpc'
5
5
  import { wait } from '@streamr/utils'
6
6
  import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
7
- import { getNodeIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
7
+ import { getNodeIdFromPeerDescriptor } from '../../src/identifiers'
8
+ import { DhtCallContext } from '../../src/rpc-protocol/DhtCallContext'
8
9
 
9
10
  describe('DhtRpc', () => {
10
11
 
11
- let rpcCommunicator1: RpcCommunicator
12
- let rpcCommunicator2: RpcCommunicator
12
+ let rpcCommunicator1: RpcCommunicator<DhtCallContext>
13
+ let rpcCommunicator2: RpcCommunicator<DhtCallContext>
13
14
  let client1: ProtoRpcClient<DhtNodeRpcClient>
14
15
  let client2: ProtoRpcClient<DhtNodeRpcClient>
15
16
  const peerDescriptor1 = createMockPeerDescriptor()
@@ -2,12 +2,10 @@ import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator
2
2
  import { DhtNode } from '../../src/dht/DhtNode'
3
3
  import { PeerDescriptor, RecursiveOperation } from '../../src/proto/packages/dht/protos/DhtRpc'
4
4
  import { createMockConnectionDhtNode, waitConnectionManagersReadyForTesting } from '../utils/utils'
5
- import { PeerID } from '../../src/helpers/PeerID'
6
- import { peerIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
7
- import { getDhtAddressFromRaw, getRawFromDhtAddress } from '../../src/identifiers'
5
+ import { getDhtAddressFromRaw, getNodeIdFromPeerDescriptor, getRawFromDhtAddress } from '../../src/identifiers'
8
6
 
9
7
  const NUM_NODES = 100
10
- const K = 2
8
+ const K = 8
11
9
 
12
10
  describe('Find correctness', () => {
13
11
 
@@ -22,7 +20,7 @@ describe('Find correctness', () => {
22
20
  nodes.push(entryPoint)
23
21
  entrypointDescriptor = entryPoint.getLocalPeerDescriptor()
24
22
  for (let i = 1; i < NUM_NODES; i++) {
25
- const node = await createMockConnectionDhtNode(simulator, undefined, K, 20, 60000)
23
+ const node = await createMockConnectionDhtNode(simulator, undefined, K, 40, 60000)
26
24
  nodes.push(node)
27
25
  }
28
26
  await entryPoint.joinDht([entrypointDescriptor])
@@ -41,7 +39,7 @@ describe('Find correctness', () => {
41
39
  const targetId = getRawFromDhtAddress(nodes[45].getNodeId())
42
40
  const results = await entryPoint.executeRecursiveOperation(getDhtAddressFromRaw(targetId), RecursiveOperation.FIND_NODE)
43
41
  expect(results.closestNodes.length).toBeGreaterThanOrEqual(5)
44
- expect(PeerID.fromValue(targetId).equals(peerIdFromPeerDescriptor(results.closestNodes[0])))
42
+ expect(getDhtAddressFromRaw(targetId)).toEqual(getNodeIdFromPeerDescriptor(results.closestNodes[0]))
45
43
  }, 30000)
46
44
 
47
45
  })
@@ -63,9 +63,9 @@ describe('Layer1', () => {
63
63
  const layer0Node = nodes[i]
64
64
  const layer1Node = layer1Nodes[i]
65
65
  expect(layer1Node.getNodeId()).toEqual(layer0Node.getNodeId())
66
- expect(layer1Node.getNumberOfConnections()).toEqual(layer0Node.getNumberOfConnections())
67
- expect(layer1Node.getNumberOfNeighbors()).toBeGreaterThanOrEqual(NUM_OF_NODES_PER_KBUCKET / 2)
68
- expect(layer1Node.getAllConnectionPeerDescriptors()).toEqual(layer0Node.getAllConnectionPeerDescriptors())
66
+ expect(layer1Node.getConnectionCount()).toEqual(layer0Node.getConnectionCount())
67
+ expect(layer1Node.getNeighborCount()).toBeGreaterThanOrEqual(NUM_OF_NODES_PER_KBUCKET / 2)
68
+ expect(layer1Node.getConnections()).toEqual(layer0Node.getConnections())
69
69
  }
70
70
  }, 120000)
71
71
 
@@ -119,10 +119,10 @@ describe('Layer1', () => {
119
119
  const stream3Node = stream3[i]
120
120
  const stream4Node = stream4[i]
121
121
 
122
- expect(layer0Node.getNumberOfConnections()).toEqual(stream1Node.getNumberOfConnections())
123
- expect(layer0Node.getNumberOfConnections()).toEqual(stream2Node.getNumberOfConnections())
124
- expect(layer0Node.getNumberOfConnections()).toEqual(stream3Node.getNumberOfConnections())
125
- expect(layer0Node.getNumberOfConnections()).toEqual(stream4Node.getNumberOfConnections())
122
+ expect(layer0Node.getConnectionCount()).toEqual(stream1Node.getConnectionCount())
123
+ expect(layer0Node.getConnectionCount()).toEqual(stream2Node.getConnectionCount())
124
+ expect(layer0Node.getConnectionCount()).toEqual(stream3Node.getConnectionCount())
125
+ expect(layer0Node.getConnectionCount()).toEqual(stream4Node.getConnectionCount())
126
126
 
127
127
  }
128
128
  }, 120000)
@@ -2,13 +2,10 @@ import { Logger } from '@streamr/utils'
2
2
  import { Simulator } from '../../src/connection/simulator/Simulator'
3
3
  import { DhtNode } from '../../src/dht/DhtNode'
4
4
  import { createMockConnectionDhtNode, createMockConnectionLayer1Node } from '../utils/utils'
5
- import { PeerID } from '../../src/exports'
6
- import { getDhtAddressFromRaw } from '../../src/identifiers'
5
+ import { createRandomDhtAddress } from '../../src/identifiers'
7
6
 
8
7
  const logger = new Logger(module)
9
8
 
10
- // TODO refactor the test to not to use PeerID
11
-
12
9
  describe('Layer 1 on Layer 0 with mocked connections', () => {
13
10
 
14
11
  const simulator = new Simulator()
@@ -25,11 +22,11 @@ describe('Layer 1 on Layer 0 with mocked connections', () => {
25
22
 
26
23
  beforeEach(async () => {
27
24
 
28
- layer0EntryPoint = await createMockConnectionDhtNode(simulator, getDhtAddressFromRaw(PeerID.fromString('layer0entrypoint').value))
29
- layer0Node1 = await createMockConnectionDhtNode(simulator, getDhtAddressFromRaw(PeerID.fromString('node1').value))
30
- layer0Node2 = await createMockConnectionDhtNode(simulator, getDhtAddressFromRaw(PeerID.fromString('node2').value))
31
- layer0Node3 = await createMockConnectionDhtNode(simulator, getDhtAddressFromRaw(PeerID.fromString('node3').value))
32
- layer0Node4 = await createMockConnectionDhtNode(simulator, getDhtAddressFromRaw(PeerID.fromString('node4').value))
25
+ layer0EntryPoint = await createMockConnectionDhtNode(simulator, createRandomDhtAddress())
26
+ layer0Node1 = await createMockConnectionDhtNode(simulator, createRandomDhtAddress())
27
+ layer0Node2 = await createMockConnectionDhtNode(simulator, createRandomDhtAddress())
28
+ layer0Node3 = await createMockConnectionDhtNode(simulator, createRandomDhtAddress())
29
+ layer0Node4 = await createMockConnectionDhtNode(simulator, createRandomDhtAddress())
33
30
 
34
31
  layer1EntryPoint = await createMockConnectionLayer1Node(layer0EntryPoint)
35
32
 
@@ -68,21 +65,21 @@ describe('Layer 1 on Layer 0 with mocked connections', () => {
68
65
  await layer1Node3.joinDht([layer0EntryPoint.getLocalPeerDescriptor()])
69
66
  await layer1Node4.joinDht([layer0EntryPoint.getLocalPeerDescriptor()])
70
67
 
71
- logger.info('layer1EntryPoint.getNumberOfNeighbors() ' + layer1EntryPoint.getNumberOfNeighbors())
72
- logger.info('layer1Node1.getNumberOfNeighbors()' + layer1Node1.getNumberOfNeighbors())
73
- logger.info('layer1Node2.getNumberOfNeighbors()' + layer1Node2.getNumberOfNeighbors())
74
- logger.info('layer1Node3.getNumberOfNeighbors()' + layer1Node3.getNumberOfNeighbors())
75
- logger.info('layer1Node4.getNumberOfNeighbors()' + layer1Node4.getNumberOfNeighbors())
76
-
77
- expect(layer1Node1.getNumberOfNeighbors()).toEqual(layer0Node1.getNumberOfNeighbors())
78
- expect(layer1Node2.getNumberOfNeighbors()).toEqual(layer0Node2.getNumberOfNeighbors())
79
- expect(layer1Node3.getNumberOfNeighbors()).toEqual(layer0Node3.getNumberOfNeighbors())
80
- expect(layer1Node4.getNumberOfNeighbors()).toEqual(layer0Node4.getNumberOfNeighbors())
81
-
82
- expect(layer1Node1.getAllNeighborPeerDescriptors()).toContainValues(layer0Node1.getAllNeighborPeerDescriptors())
83
- expect(layer1Node2.getAllNeighborPeerDescriptors()).toContainValues(layer0Node2.getAllNeighborPeerDescriptors())
84
- expect(layer1Node3.getAllNeighborPeerDescriptors()).toContainValues(layer0Node3.getAllNeighborPeerDescriptors())
85
- expect(layer1Node4.getAllNeighborPeerDescriptors()).toContainValues(layer0Node4.getAllNeighborPeerDescriptors())
68
+ logger.info('layer1EntryPoint.getNeighborCount() ' + layer1EntryPoint.getNeighborCount())
69
+ logger.info('layer1Node1.getNeighborCount()' + layer1Node1.getNeighborCount())
70
+ logger.info('layer1Node2.getNeighborCount()' + layer1Node2.getNeighborCount())
71
+ logger.info('layer1Node3.getNeighborCount()' + layer1Node3.getNeighborCount())
72
+ logger.info('layer1Node4.getNeighborCount()' + layer1Node4.getNeighborCount())
73
+
74
+ expect(layer1Node1.getNeighborCount()).toEqual(layer0Node1.getNeighborCount())
75
+ expect(layer1Node2.getNeighborCount()).toEqual(layer0Node2.getNeighborCount())
76
+ expect(layer1Node3.getNeighborCount()).toEqual(layer0Node3.getNeighborCount())
77
+ expect(layer1Node4.getNeighborCount()).toEqual(layer0Node4.getNeighborCount())
78
+
79
+ expect(layer1Node1.getNeighbors()).toContainValues(layer0Node1.getNeighbors())
80
+ expect(layer1Node2.getNeighbors()).toContainValues(layer0Node2.getNeighbors())
81
+ expect(layer1Node3.getNeighbors()).toContainValues(layer0Node3.getNeighbors())
82
+ expect(layer1Node4.getNeighbors()).toContainValues(layer0Node4.getNeighbors())
86
83
 
87
84
  }, 60000)
88
85
  })
@@ -42,9 +42,9 @@ describe('multiple entry point joining', () => {
42
42
  node2.joinDht(entryPoints),
43
43
  node3.joinDht(entryPoints)
44
44
  ])
45
- expect(node1.getNumberOfNeighbors()).toEqual(2)
46
- expect(node2.getNumberOfNeighbors()).toEqual(2)
47
- expect(node3.getNumberOfNeighbors()).toEqual(2)
45
+ expect(node1.getNeighborCount()).toEqual(2)
46
+ expect(node2.getNeighborCount()).toEqual(2)
47
+ expect(node3.getNeighborCount()).toEqual(2)
48
48
  })
49
49
 
50
50
  it('can join even if a node is offline', async () => {
@@ -53,8 +53,8 @@ describe('multiple entry point joining', () => {
53
53
  node1.joinDht(entryPoints),
54
54
  node2.joinDht(entryPoints)
55
55
  ])
56
- expect(node1.getNumberOfNeighbors()).toEqual(1)
57
- expect(node2.getNumberOfNeighbors()).toEqual(1)
56
+ expect(node1.getNeighborCount()).toEqual(1)
57
+ expect(node2.getNeighborCount()).toEqual(1)
58
58
  }, 10000)
59
59
  })
60
60
 
@@ -96,9 +96,9 @@ describe('multiple entry point joining', () => {
96
96
 
97
97
  it('non-entry point nodes can join', async () => {
98
98
  await node1.joinDht(entryPoints)
99
- expect(node1.getNumberOfNeighbors()).toEqual(2)
99
+ expect(node1.getNeighborCount()).toEqual(2)
100
100
  await node2.joinDht(entryPoints)
101
- expect(node2.getNumberOfNeighbors()).toEqual(3)
101
+ expect(node2.getNeighborCount()).toEqual(3)
102
102
  })
103
103
 
104
104
  })