@streamr/dht 100.0.0-testnet-three.2 → 100.0.0-testnet-three.4

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 (64) hide show
  1. package/README.md +90 -8
  2. package/dist/package.json +5 -5
  3. package/dist/src/connection/ConnectionManager.js +10 -2
  4. package/dist/src/connection/ConnectionManager.js.map +1 -1
  5. package/dist/src/connection/connectivityRequestHandler.d.ts +1 -0
  6. package/dist/src/connection/connectivityRequestHandler.js +39 -22
  7. package/dist/src/connection/connectivityRequestHandler.js.map +1 -1
  8. package/dist/src/connection/websocket/WebsocketConnector.js +32 -37
  9. package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
  10. package/dist/src/dht/DhtNode.d.ts +2 -2
  11. package/dist/src/dht/DhtNode.js +16 -11
  12. package/dist/src/dht/DhtNode.js.map +1 -1
  13. package/dist/src/dht/DhtNodeRpcLocal.d.ts +1 -1
  14. package/dist/src/dht/DhtNodeRpcLocal.js +2 -2
  15. package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
  16. package/dist/src/dht/PeerManager.d.ts +7 -9
  17. package/dist/src/dht/PeerManager.js +7 -14
  18. package/dist/src/dht/PeerManager.js.map +1 -1
  19. package/dist/src/dht/contact/ContactList.d.ts +1 -1
  20. package/dist/src/dht/contact/RandomContactList.js +1 -1
  21. package/dist/src/dht/contact/RandomContactList.js.map +1 -1
  22. package/dist/src/dht/contact/SortedContactList.js +14 -15
  23. package/dist/src/dht/contact/SortedContactList.js.map +1 -1
  24. package/dist/src/dht/discovery/DiscoverySession.d.ts +1 -1
  25. package/dist/src/dht/discovery/DiscoverySession.js +5 -5
  26. package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
  27. package/dist/src/dht/discovery/PeerDiscovery.js +2 -2
  28. package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
  29. package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js +0 -1
  30. package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js.map +1 -1
  31. package/dist/src/dht/routing/RouterRpcLocal.js +2 -3
  32. package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
  33. package/dist/src/dht/routing/RoutingSession.js +2 -1
  34. package/dist/src/dht/routing/RoutingSession.js.map +1 -1
  35. package/dist/src/dht/store/LocalDataStore.d.ts +1 -1
  36. package/dist/src/dht/store/LocalDataStore.js +2 -5
  37. package/dist/src/dht/store/LocalDataStore.js.map +1 -1
  38. package/dist/src/dht/store/StoreManager.d.ts +1 -1
  39. package/dist/src/dht/store/StoreManager.js +10 -17
  40. package/dist/src/dht/store/StoreManager.js.map +1 -1
  41. package/package.json +5 -5
  42. package/src/connection/ConnectionManager.ts +9 -2
  43. package/src/connection/connectivityRequestHandler.ts +39 -22
  44. package/src/connection/websocket/WebsocketConnector.ts +33 -37
  45. package/src/dht/DhtNode.ts +20 -15
  46. package/src/dht/DhtNodeRpcLocal.ts +3 -3
  47. package/src/dht/PeerManager.ts +12 -21
  48. package/src/dht/contact/ContactList.ts +1 -1
  49. package/src/dht/contact/RandomContactList.ts +1 -1
  50. package/src/dht/contact/SortedContactList.ts +14 -18
  51. package/src/dht/discovery/DiscoverySession.ts +5 -5
  52. package/src/dht/discovery/PeerDiscovery.ts +2 -2
  53. package/src/dht/recursive-operation/RecursiveOperationRpcLocal.ts +0 -1
  54. package/src/dht/routing/RouterRpcLocal.ts +2 -3
  55. package/src/dht/routing/RoutingSession.ts +2 -1
  56. package/src/dht/store/LocalDataStore.ts +2 -5
  57. package/src/dht/store/StoreManager.ts +10 -17
  58. package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +8 -4
  59. package/test/end-to-end/Layer0Webrtc.test.ts +0 -2
  60. package/test/end-to-end/memory-leak.test.ts +3 -3
  61. package/test/unit/PeerManager.test.ts +1 -1
  62. package/test/unit/SortedContactList.test.ts +5 -5
  63. package/test/unit/StoreManager.test.ts +26 -23
  64. package/test/unit/connectivityRequestHandler.test.ts +39 -6
@@ -15,8 +15,9 @@ describe('connectivityRequestHandler', () => {
15
15
 
16
16
  let httpServer: HttpServer
17
17
  let wsServer: WsServer
18
+ let connection: any
18
19
 
19
- beforeAll(async () => {
20
+ beforeEach(async () => {
20
21
  httpServer = createHttpServer()
21
22
  wsServer = new WsServer({
22
23
  httpServer,
@@ -24,19 +25,18 @@ describe('connectivityRequestHandler', () => {
24
25
  })
25
26
  httpServer.listen(PORT)
26
27
  await once(httpServer, 'listening')
28
+ connection = new EventEmitter()
29
+ connection.send = jest.fn()
30
+ connection.getRemoteIp = () => HOST
27
31
  })
28
32
 
29
- afterAll(async () => {
33
+ afterEach(async () => {
30
34
  wsServer.shutDown()
31
35
  httpServer.close()
32
36
  await once(httpServer, 'close')
33
37
  })
34
38
 
35
39
  it('happy path', async () => {
36
- const connection: any = new EventEmitter()
37
- connection.send = jest.fn()
38
- connection.getRemoteIp = () => HOST
39
-
40
40
  attachConnectivityRequestHandler(connection)
41
41
  const request: Message = {
42
42
  serviceId: CONNECTIVITY_CHECKER_SERVICE_ID,
@@ -72,4 +72,37 @@ describe('connectivityRequestHandler', () => {
72
72
  serviceId: 'system/connectivity-checker'
73
73
  })
74
74
  })
75
+
76
+ it('disabled connectivity probing', async () => {
77
+ attachConnectivityRequestHandler(connection)
78
+ const request: Message = {
79
+ serviceId: CONNECTIVITY_CHECKER_SERVICE_ID,
80
+ messageType: MessageType.CONNECTIVITY_REQUEST,
81
+ messageId: 'mock-message-id',
82
+ body: {
83
+ oneofKind: 'connectivityRequest',
84
+ connectivityRequest: { port: 0, host: HOST, tls: false, selfSigned: false }
85
+ }
86
+ }
87
+ connection.emit('data', Message.toBinary(request))
88
+
89
+ await waitForCondition(() => connection.send.mock.calls.length > 0)
90
+
91
+ const receivedMessage = Message.fromBinary(connection.send.mock.calls[0][0])
92
+ expect(receivedMessage).toEqual({
93
+ body: {
94
+ connectivityResponse: {
95
+ host: HOST,
96
+ natType: 'unknown',
97
+ ipAddress: ipv4ToNumber(HOST),
98
+ version
99
+ },
100
+ oneofKind: 'connectivityResponse'
101
+ },
102
+ messageId: expect.any(String),
103
+ messageType: MessageType.CONNECTIVITY_RESPONSE,
104
+ serviceId: 'system/connectivity-checker'
105
+ })
106
+ })
107
+
75
108
  })