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

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 (45) hide show
  1. package/dist/package.json +5 -6
  2. package/dist/src/connection/Handshaker.js.map +1 -1
  3. package/dist/src/connection/connectivityChecker.d.ts +1 -1
  4. package/dist/src/connection/connectivityChecker.js +9 -2
  5. package/dist/src/connection/connectivityChecker.js.map +1 -1
  6. package/dist/src/connection/connectivityRequestHandler.js +5 -2
  7. package/dist/src/connection/connectivityRequestHandler.js.map +1 -1
  8. package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
  9. package/dist/src/connection/websocket/WebsocketConnector.js +15 -4
  10. package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
  11. package/dist/src/dht/DhtNode.d.ts +1 -0
  12. package/dist/src/dht/DhtNode.js +12 -0
  13. package/dist/src/dht/DhtNode.js.map +1 -1
  14. package/dist/src/dht/contact/SortedContactList.js +6 -4
  15. package/dist/src/dht/contact/SortedContactList.js.map +1 -1
  16. package/dist/src/identifiers.d.ts +1 -0
  17. package/dist/src/identifiers.js +3 -3
  18. package/dist/src/identifiers.js.map +1 -1
  19. package/dist/src/proto/google/protobuf/any.d.ts +5 -8
  20. package/dist/src/proto/google/protobuf/any.js.map +1 -1
  21. package/dist/src/proto/google/protobuf/empty.d.ts +1 -0
  22. package/dist/src/proto/google/protobuf/empty.js.map +1 -1
  23. package/dist/src/proto/google/protobuf/timestamp.d.ts +1 -10
  24. package/dist/src/proto/google/protobuf/timestamp.js.map +1 -1
  25. package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +4 -0
  26. package/dist/src/proto/packages/dht/protos/DhtRpc.js +2 -1
  27. package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
  28. package/package.json +5 -6
  29. package/protos/DhtRpc.proto +1 -0
  30. package/src/connection/Handshaker.ts +4 -4
  31. package/src/connection/connectivityChecker.ts +9 -2
  32. package/src/connection/connectivityRequestHandler.ts +5 -2
  33. package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +2 -2
  34. package/src/connection/websocket/WebsocketConnector.ts +17 -7
  35. package/src/dht/DhtNode.ts +13 -1
  36. package/src/dht/contact/SortedContactList.ts +14 -8
  37. package/src/identifiers.ts +1 -1
  38. package/src/proto/google/protobuf/any.ts +5 -8
  39. package/src/proto/google/protobuf/empty.ts +1 -0
  40. package/src/proto/google/protobuf/timestamp.ts +1 -10
  41. package/src/proto/packages/dht/protos/DhtRpc.ts +6 -1
  42. package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +5 -5
  43. package/test/integration/ConnectivityChecking.test.ts +64 -0
  44. package/test/unit/SortedContactList.test.ts +13 -0
  45. package/test/unit/connectivityRequestHandler.test.ts +3 -1
@@ -0,0 +1,64 @@
1
+ import { MetricsContext } from '@streamr/utils'
2
+ import { ConnectionManager } from '../../src/connection/ConnectionManager'
3
+ import { DefaultConnectorFacade } from '../../src/connection/ConnectorFacade'
4
+ import { MockTransport } from '../utils/mock/Transport'
5
+ import { createMockPeerDescriptor } from '../utils/utils'
6
+ import { sendConnectivityRequest } from '../../src/connection/connectivityChecker'
7
+ import { version } from '../../package.json'
8
+
9
+ describe('ConnectivityChecking', () => {
10
+
11
+ let server: ConnectionManager
12
+ const PORT = 15000
13
+ const HOST = '127.0.0.1'
14
+
15
+ beforeEach(async () => {
16
+ server = new ConnectionManager({
17
+ createConnectorFacade: () => new DefaultConnectorFacade({
18
+ createLocalPeerDescriptor: () => {
19
+ return {
20
+ ...createMockPeerDescriptor(),
21
+ websocket: {
22
+ host: HOST,
23
+ port: PORT,
24
+ tls: false
25
+ }
26
+ }
27
+ },
28
+ websocketHost: HOST,
29
+ websocketPortRange: { min: PORT, max: PORT },
30
+ websocketServerEnableTls: false,
31
+ transport: new MockTransport()
32
+ }),
33
+ metricsContext: new MetricsContext()
34
+ })
35
+ await server.start()
36
+ })
37
+
38
+ afterEach(async () => {
39
+ await server.stop()
40
+ })
41
+
42
+ it('connectivityCheck with compatible version', async () => {
43
+ const request = {
44
+ host: HOST,
45
+ port: PORT,
46
+ tls: false,
47
+ selfSigned: false
48
+ }
49
+ const response = await sendConnectivityRequest(request, server.getLocalPeerDescriptor(), version)
50
+ expect(response.version).toEqual(version)
51
+ })
52
+
53
+ it('connectivityCheck with incompatible version', async () => {
54
+ const request = {
55
+ host: HOST,
56
+ port: PORT,
57
+ tls: false,
58
+ selfSigned: false
59
+ }
60
+ await expect(sendConnectivityRequest(request, server.getLocalPeerDescriptor(), '0.0.1'))
61
+ .toReject()
62
+ })
63
+
64
+ })
@@ -118,4 +118,17 @@ describe('SortedContactList', () => {
118
118
  list.setActive(item4.getNodeId())
119
119
  expect(list.getActiveContacts()).toEqual([item2, item3, item4])
120
120
  })
121
+
122
+ it('does not emit newContact if contact did not fit the structure', () => {
123
+ const list = new SortedContactList({ referenceId: item0.getNodeId(), maxSize: 2, allowToContainReferenceId: false, emitEvents: true })
124
+ const onNewContact = jest.fn()
125
+ list.on('newContact', onNewContact)
126
+ list.addContact(item1)
127
+ list.addContact(item2)
128
+ expect(onNewContact).toBeCalledTimes(2)
129
+ list.addContact(item3)
130
+ expect(onNewContact).toBeCalledTimes(2)
131
+ expect(list.getAllContacts().length).toEqual(2)
132
+ })
133
+
121
134
  })
@@ -6,6 +6,7 @@ import { server as WsServer } from 'websocket'
6
6
  import { CONNECTIVITY_CHECKER_SERVICE_ID } from '../../src/connection/connectivityChecker'
7
7
  import { attachConnectivityRequestHandler } from '../../src/connection/connectivityRequestHandler'
8
8
  import { Message, MessageType } from '../../src/proto/packages/dht/protos/DhtRpc'
9
+ import { version } from '../../package.json'
9
10
 
10
11
  const HOST = '127.0.0.1'
11
12
  const PORT = 15001
@@ -61,7 +62,8 @@ describe('connectivityRequestHandler', () => {
61
62
  port: PORT,
62
63
  tls: false
63
64
  },
64
- ipAddress: ipv4ToNumber(HOST)
65
+ ipAddress: ipv4ToNumber(HOST),
66
+ version
65
67
  },
66
68
  oneofKind: 'connectivityResponse'
67
69
  },