@streamr/trackerless-network 103.1.2 → 103.2.0-experiment.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 (172) hide show
  1. package/dist/exports.cjs +4489 -0
  2. package/dist/exports.cjs.map +1 -0
  3. package/dist/exports.d.ts +1391 -0
  4. package/dist/exports.js +4477 -0
  5. package/dist/exports.js.map +1 -0
  6. package/package.json +25 -18
  7. package/dist/generated/google/protobuf/any.d.ts +0 -180
  8. package/dist/generated/google/protobuf/any.js +0 -155
  9. package/dist/generated/google/protobuf/any.js.map +0 -1
  10. package/dist/generated/google/protobuf/empty.d.ts +0 -31
  11. package/dist/generated/google/protobuf/empty.js +0 -45
  12. package/dist/generated/google/protobuf/empty.js.map +0 -1
  13. package/dist/generated/google/protobuf/timestamp.d.ts +0 -156
  14. package/dist/generated/google/protobuf/timestamp.js +0 -136
  15. package/dist/generated/google/protobuf/timestamp.js.map +0 -1
  16. package/dist/generated/packages/dht/protos/DhtRpc.client.d.ts +0 -371
  17. package/dist/generated/packages/dht/protos/DhtRpc.client.js +0 -292
  18. package/dist/generated/packages/dht/protos/DhtRpc.client.js.map +0 -1
  19. package/dist/generated/packages/dht/protos/DhtRpc.d.ts +0 -1031
  20. package/dist/generated/packages/dht/protos/DhtRpc.js +0 -702
  21. package/dist/generated/packages/dht/protos/DhtRpc.js.map +0 -1
  22. package/dist/generated/packages/dht/protos/DhtRpc.server.d.ts +0 -168
  23. package/dist/generated/packages/dht/protos/DhtRpc.server.js +0 -3
  24. package/dist/generated/packages/dht/protos/DhtRpc.server.js.map +0 -1
  25. package/dist/generated/packages/proto-rpc/protos/ProtoRpc.d.ts +0 -87
  26. package/dist/generated/packages/proto-rpc/protos/ProtoRpc.js +0 -66
  27. package/dist/generated/packages/proto-rpc/protos/ProtoRpc.js.map +0 -1
  28. package/dist/generated/packages/trackerless-network/protos/NetworkRpc.client.d.ts +0 -237
  29. package/dist/generated/packages/trackerless-network/protos/NetworkRpc.client.js +0 -190
  30. package/dist/generated/packages/trackerless-network/protos/NetworkRpc.client.js.map +0 -1
  31. package/dist/generated/packages/trackerless-network/protos/NetworkRpc.d.ts +0 -687
  32. package/dist/generated/packages/trackerless-network/protos/NetworkRpc.js +0 -479
  33. package/dist/generated/packages/trackerless-network/protos/NetworkRpc.js.map +0 -1
  34. package/dist/generated/packages/trackerless-network/protos/NetworkRpc.server.d.ts +0 -102
  35. package/dist/generated/packages/trackerless-network/protos/NetworkRpc.server.js +0 -3
  36. package/dist/generated/packages/trackerless-network/protos/NetworkRpc.server.js.map +0 -1
  37. package/dist/package.json +0 -56
  38. package/dist/src/ContentDeliveryManager.d.ts +0 -82
  39. package/dist/src/ContentDeliveryManager.js +0 -325
  40. package/dist/src/ContentDeliveryManager.js.map +0 -1
  41. package/dist/src/NetworkNode.d.ts +0 -44
  42. package/dist/src/NetworkNode.js +0 -98
  43. package/dist/src/NetworkNode.js.map +0 -1
  44. package/dist/src/NetworkStack.d.ts +0 -36
  45. package/dist/src/NetworkStack.js +0 -165
  46. package/dist/src/NetworkStack.js.map +0 -1
  47. package/dist/src/NodeInfoClient.d.ts +0 -9
  48. package/dist/src/NodeInfoClient.js +0 -21
  49. package/dist/src/NodeInfoClient.js.map +0 -1
  50. package/dist/src/NodeInfoRpcLocal.d.ts +0 -12
  51. package/dist/src/NodeInfoRpcLocal.js +0 -22
  52. package/dist/src/NodeInfoRpcLocal.js.map +0 -1
  53. package/dist/src/NodeInfoRpcRemote.d.ts +0 -6
  54. package/dist/src/NodeInfoRpcRemote.js +0 -11
  55. package/dist/src/NodeInfoRpcRemote.js.map +0 -1
  56. package/dist/src/StreamPartNetworkSplitAvoidance.d.ts +0 -18
  57. package/dist/src/StreamPartNetworkSplitAvoidance.js +0 -74
  58. package/dist/src/StreamPartNetworkSplitAvoidance.js.map +0 -1
  59. package/dist/src/StreamPartReconnect.d.ts +0 -11
  60. package/dist/src/StreamPartReconnect.js +0 -37
  61. package/dist/src/StreamPartReconnect.js.map +0 -1
  62. package/dist/src/content-delivery-layer/ContentDeliveryLayerNode.d.ts +0 -78
  63. package/dist/src/content-delivery-layer/ContentDeliveryLayerNode.js +0 -240
  64. package/dist/src/content-delivery-layer/ContentDeliveryLayerNode.js.map +0 -1
  65. package/dist/src/content-delivery-layer/ContentDeliveryRpcLocal.d.ts +0 -23
  66. package/dist/src/content-delivery-layer/ContentDeliveryRpcLocal.js +0 -40
  67. package/dist/src/content-delivery-layer/ContentDeliveryRpcLocal.js.map +0 -1
  68. package/dist/src/content-delivery-layer/ContentDeliveryRpcRemote.d.ts +0 -11
  69. package/dist/src/content-delivery-layer/ContentDeliveryRpcRemote.js +0 -38
  70. package/dist/src/content-delivery-layer/ContentDeliveryRpcRemote.js.map +0 -1
  71. package/dist/src/content-delivery-layer/DuplicateMessageDetector.d.ts +0 -55
  72. package/dist/src/content-delivery-layer/DuplicateMessageDetector.js +0 -159
  73. package/dist/src/content-delivery-layer/DuplicateMessageDetector.js.map +0 -1
  74. package/dist/src/content-delivery-layer/NodeList.d.ts +0 -26
  75. package/dist/src/content-delivery-layer/NodeList.js +0 -93
  76. package/dist/src/content-delivery-layer/NodeList.js.map +0 -1
  77. package/dist/src/content-delivery-layer/createContentDeliveryLayerNode.d.ts +0 -14
  78. package/dist/src/content-delivery-layer/createContentDeliveryLayerNode.js +0 -129
  79. package/dist/src/content-delivery-layer/createContentDeliveryLayerNode.js.map +0 -1
  80. package/dist/src/content-delivery-layer/formStreamPartDeliveryServiceId.d.ts +0 -3
  81. package/dist/src/content-delivery-layer/formStreamPartDeliveryServiceId.js +0 -9
  82. package/dist/src/content-delivery-layer/formStreamPartDeliveryServiceId.js.map +0 -1
  83. package/dist/src/content-delivery-layer/inspection/InspectSession.d.ts +0 -19
  84. package/dist/src/content-delivery-layer/inspection/InspectSession.js +0 -43
  85. package/dist/src/content-delivery-layer/inspection/InspectSession.js.map +0 -1
  86. package/dist/src/content-delivery-layer/inspection/Inspector.d.ts +0 -30
  87. package/dist/src/content-delivery-layer/inspection/Inspector.js +0 -75
  88. package/dist/src/content-delivery-layer/inspection/Inspector.js.map +0 -1
  89. package/dist/src/content-delivery-layer/neighbor-discovery/HandshakeRpcLocal.d.ts +0 -29
  90. package/dist/src/content-delivery-layer/neighbor-discovery/HandshakeRpcLocal.js +0 -106
  91. package/dist/src/content-delivery-layer/neighbor-discovery/HandshakeRpcLocal.js.map +0 -1
  92. package/dist/src/content-delivery-layer/neighbor-discovery/HandshakeRpcRemote.d.ts +0 -14
  93. package/dist/src/content-delivery-layer/neighbor-discovery/HandshakeRpcRemote.js +0 -55
  94. package/dist/src/content-delivery-layer/neighbor-discovery/HandshakeRpcRemote.js.map +0 -1
  95. package/dist/src/content-delivery-layer/neighbor-discovery/Handshaker.d.ts +0 -32
  96. package/dist/src/content-delivery-layer/neighbor-discovery/Handshaker.js +0 -149
  97. package/dist/src/content-delivery-layer/neighbor-discovery/Handshaker.js.map +0 -1
  98. package/dist/src/content-delivery-layer/neighbor-discovery/NeighborFinder.d.ts +0 -22
  99. package/dist/src/content-delivery-layer/neighbor-discovery/NeighborFinder.js +0 -64
  100. package/dist/src/content-delivery-layer/neighbor-discovery/NeighborFinder.js.map +0 -1
  101. package/dist/src/content-delivery-layer/neighbor-discovery/NeighborUpdateManager.d.ts +0 -27
  102. package/dist/src/content-delivery-layer/neighbor-discovery/NeighborUpdateManager.js +0 -47
  103. package/dist/src/content-delivery-layer/neighbor-discovery/NeighborUpdateManager.js.map +0 -1
  104. package/dist/src/content-delivery-layer/neighbor-discovery/NeighborUpdateRpcLocal.d.ts +0 -25
  105. package/dist/src/content-delivery-layer/neighbor-discovery/NeighborUpdateRpcLocal.js +0 -52
  106. package/dist/src/content-delivery-layer/neighbor-discovery/NeighborUpdateRpcLocal.js.map +0 -1
  107. package/dist/src/content-delivery-layer/neighbor-discovery/NeighborUpdateRpcRemote.d.ts +0 -11
  108. package/dist/src/content-delivery-layer/neighbor-discovery/NeighborUpdateRpcRemote.js +0 -31
  109. package/dist/src/content-delivery-layer/neighbor-discovery/NeighborUpdateRpcRemote.js.map +0 -1
  110. package/dist/src/content-delivery-layer/plumtree/PausedNeighbors.d.ts +0 -12
  111. package/dist/src/content-delivery-layer/plumtree/PausedNeighbors.js +0 -50
  112. package/dist/src/content-delivery-layer/plumtree/PausedNeighbors.js.map +0 -1
  113. package/dist/src/content-delivery-layer/plumtree/PlumtreeManager.d.ts +0 -37
  114. package/dist/src/content-delivery-layer/plumtree/PlumtreeManager.js +0 -141
  115. package/dist/src/content-delivery-layer/plumtree/PlumtreeManager.js.map +0 -1
  116. package/dist/src/content-delivery-layer/plumtree/PlumtreeRpcLocal.d.ts +0 -20
  117. package/dist/src/content-delivery-layer/plumtree/PlumtreeRpcLocal.js +0 -37
  118. package/dist/src/content-delivery-layer/plumtree/PlumtreeRpcLocal.js.map +0 -1
  119. package/dist/src/content-delivery-layer/plumtree/PlumtreeRpcRemote.d.ts +0 -8
  120. package/dist/src/content-delivery-layer/plumtree/PlumtreeRpcRemote.js +0 -26
  121. package/dist/src/content-delivery-layer/plumtree/PlumtreeRpcRemote.js.map +0 -1
  122. package/dist/src/content-delivery-layer/propagation/FifoMapWithTTL.d.ts +0 -29
  123. package/dist/src/content-delivery-layer/propagation/FifoMapWithTTL.js +0 -93
  124. package/dist/src/content-delivery-layer/propagation/FifoMapWithTTL.js.map +0 -1
  125. package/dist/src/content-delivery-layer/propagation/Propagation.d.ts +0 -35
  126. package/dist/src/content-delivery-layer/propagation/Propagation.js +0 -68
  127. package/dist/src/content-delivery-layer/propagation/Propagation.js.map +0 -1
  128. package/dist/src/content-delivery-layer/propagation/PropagationTaskStore.d.ts +0 -22
  129. package/dist/src/content-delivery-layer/propagation/PropagationTaskStore.js +0 -33
  130. package/dist/src/content-delivery-layer/propagation/PropagationTaskStore.js.map +0 -1
  131. package/dist/src/content-delivery-layer/proxy/ProxyClient.d.ts +0 -46
  132. package/dist/src/content-delivery-layer/proxy/ProxyClient.js +0 -214
  133. package/dist/src/content-delivery-layer/proxy/ProxyClient.js.map +0 -1
  134. package/dist/src/content-delivery-layer/proxy/ProxyConnectionRpcLocal.d.ts +0 -34
  135. package/dist/src/content-delivery-layer/proxy/ProxyConnectionRpcLocal.js +0 -72
  136. package/dist/src/content-delivery-layer/proxy/ProxyConnectionRpcLocal.js.map +0 -1
  137. package/dist/src/content-delivery-layer/proxy/ProxyConnectionRpcRemote.d.ts +0 -7
  138. package/dist/src/content-delivery-layer/proxy/ProxyConnectionRpcRemote.js +0 -27
  139. package/dist/src/content-delivery-layer/proxy/ProxyConnectionRpcRemote.js.map +0 -1
  140. package/dist/src/content-delivery-layer/temporary-connection/TemporaryConnectionRpcLocal.d.ts +0 -26
  141. package/dist/src/content-delivery-layer/temporary-connection/TemporaryConnectionRpcLocal.js +0 -45
  142. package/dist/src/content-delivery-layer/temporary-connection/TemporaryConnectionRpcLocal.js.map +0 -1
  143. package/dist/src/content-delivery-layer/temporary-connection/TemporaryConnectionRpcRemote.d.ts +0 -6
  144. package/dist/src/content-delivery-layer/temporary-connection/TemporaryConnectionRpcRemote.js +0 -31
  145. package/dist/src/content-delivery-layer/temporary-connection/TemporaryConnectionRpcRemote.js.map +0 -1
  146. package/dist/src/control-layer/ControlLayerNode.d.ts +0 -16
  147. package/dist/src/control-layer/ControlLayerNode.js +0 -3
  148. package/dist/src/control-layer/ControlLayerNode.js.map +0 -1
  149. package/dist/src/control-layer/ExternalNetworkRpc.d.ts +0 -16
  150. package/dist/src/control-layer/ExternalNetworkRpc.js +0 -23
  151. package/dist/src/control-layer/ExternalNetworkRpc.js.map +0 -1
  152. package/dist/src/control-layer/PeerDescriptorStoreManager.d.ts +0 -28
  153. package/dist/src/control-layer/PeerDescriptorStoreManager.js +0 -78
  154. package/dist/src/control-layer/PeerDescriptorStoreManager.js.map +0 -1
  155. package/dist/src/discovery-layer/DiscoveryLayerNode.d.ts +0 -28
  156. package/dist/src/discovery-layer/DiscoveryLayerNode.js +0 -3
  157. package/dist/src/discovery-layer/DiscoveryLayerNode.js.map +0 -1
  158. package/dist/src/exports.d.ts +0 -6
  159. package/dist/src/exports.js +0 -24
  160. package/dist/src/exports.js.map +0 -1
  161. package/dist/src/types.d.ts +0 -6
  162. package/dist/src/types.js +0 -3
  163. package/dist/src/types.js.map +0 -1
  164. package/dist/src/utils.d.ts +0 -3
  165. package/dist/src/utils.js +0 -17
  166. package/dist/src/utils.js.map +0 -1
  167. package/dist/test/benchmark/first-message.d.ts +0 -1
  168. package/dist/test/benchmark/first-message.js +0 -139
  169. package/dist/test/benchmark/first-message.js.map +0 -1
  170. package/dist/test/utils/utils.d.ts +0 -15
  171. package/dist/test/utils/utils.js +0 -106
  172. package/dist/test/utils/utils.js.map +0 -1
@@ -1,240 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ContentDeliveryLayerNode = exports.DEFAULT_ACCEPT_PROXY_CONNECTIONS = exports.DEFAULT_NEIGHBOR_TARGET_COUNT = exports.DEFAULT_NODE_VIEW_SIZE = void 0;
4
- const dht_1 = require("@streamr/dht");
5
- const utils_1 = require("@streamr/utils");
6
- const eventemitter3_1 = require("eventemitter3");
7
- const NetworkRpc_1 = require("../../generated/packages/trackerless-network/protos/NetworkRpc");
8
- const NetworkRpc_client_1 = require("../../generated/packages/trackerless-network/protos/NetworkRpc.client");
9
- const ContentDeliveryRpcLocal_1 = require("./ContentDeliveryRpcLocal");
10
- const ContentDeliveryRpcRemote_1 = require("./ContentDeliveryRpcRemote");
11
- const utils_2 = require("../utils");
12
- exports.DEFAULT_NODE_VIEW_SIZE = 20;
13
- exports.DEFAULT_NEIGHBOR_TARGET_COUNT = 4;
14
- exports.DEFAULT_ACCEPT_PROXY_CONNECTIONS = false;
15
- const logger = new utils_1.Logger(module);
16
- class ContentDeliveryLayerNode extends eventemitter3_1.EventEmitter {
17
- started = false;
18
- duplicateDetectors;
19
- options;
20
- contentDeliveryRpcLocal;
21
- abortController = new AbortController();
22
- messagesPropagated = 0;
23
- constructor(options) {
24
- super();
25
- this.options = options;
26
- this.duplicateDetectors = new Map();
27
- this.contentDeliveryRpcLocal = new ContentDeliveryRpcLocal_1.ContentDeliveryRpcLocal({
28
- localPeerDescriptor: this.options.localPeerDescriptor,
29
- streamPartId: this.options.streamPartId,
30
- rpcCommunicator: this.options.rpcCommunicator,
31
- markAndCheckDuplicate: (msg, prev) => (0, utils_2.markAndCheckDuplicate)(this.duplicateDetectors, msg, prev),
32
- broadcast: (message, previousNode) => this.broadcast(message, previousNode),
33
- onLeaveNotice: (remoteNodeId, sourceIsStreamEntryPoint) => {
34
- if (this.abortController.signal.aborted) {
35
- return;
36
- }
37
- const contact = this.options.nearbyNodeView.get(remoteNodeId)
38
- ?? this.options.randomNodeView.get(remoteNodeId)
39
- ?? this.options.neighbors.get(remoteNodeId)
40
- ?? this.options.proxyConnectionRpcLocal?.getConnection(remoteNodeId)?.remote;
41
- // TODO: check integrity of notifier?
42
- if (contact) {
43
- this.options.discoveryLayerNode.removeContact(remoteNodeId);
44
- this.options.neighbors.remove(remoteNodeId);
45
- this.options.nearbyNodeView.remove(remoteNodeId);
46
- this.options.randomNodeView.remove(remoteNodeId);
47
- this.options.leftNodeView.remove(remoteNodeId);
48
- this.options.rightNodeView.remove(remoteNodeId);
49
- this.options.neighborFinder.start([remoteNodeId]);
50
- this.options.proxyConnectionRpcLocal?.removeConnection(remoteNodeId);
51
- }
52
- if (sourceIsStreamEntryPoint) {
53
- this.emit('entryPointLeaveDetected');
54
- }
55
- },
56
- markForInspection: (remoteNodeId, messageId) => this.options.inspector.markMessage(remoteNodeId, messageId),
57
- plumtreeManager: this.options.plumtreeManager
58
- });
59
- }
60
- async start() {
61
- this.started = true;
62
- this.registerDefaultServerMethods();
63
- (0, utils_1.addManagedEventListener)(this.options.discoveryLayerNode, 'nearbyContactAdded', () => this.onNearbyContactAdded(), this.abortController.signal);
64
- (0, utils_1.addManagedEventListener)(this.options.discoveryLayerNode, 'nearbyContactRemoved', () => this.onNearbyContactRemoved(), this.abortController.signal);
65
- (0, utils_1.addManagedEventListener)(this.options.discoveryLayerNode, 'randomContactAdded', () => this.onRandomContactAdded(), this.abortController.signal);
66
- (0, utils_1.addManagedEventListener)(this.options.discoveryLayerNode, 'randomContactRemoved', () => this.onRandomContactRemoved(), this.abortController.signal);
67
- (0, utils_1.addManagedEventListener)(this.options.discoveryLayerNode, 'ringContactAdded', () => this.onRingContactsUpdated(), this.abortController.signal);
68
- (0, utils_1.addManagedEventListener)(this.options.discoveryLayerNode, 'ringContactRemoved', () => this.onRingContactsUpdated(), this.abortController.signal);
69
- (0, utils_1.addManagedEventListener)(this.options.transport, 'disconnected', (peerDescriptor) => this.onNodeDisconnected(peerDescriptor), this.abortController.signal);
70
- (0, utils_1.addManagedEventListener)(this.options.neighbors, 'nodeAdded', (id, remote) => {
71
- this.options.propagation.onNeighborJoined(id);
72
- this.options.connectionLocker.weakLockConnection((0, dht_1.toNodeId)(remote.getPeerDescriptor()), this.options.streamPartId);
73
- this.emit('neighborConnected', id);
74
- }, this.abortController.signal);
75
- (0, utils_1.addManagedEventListener)(this.options.neighbors, 'nodeRemoved', (_id, remote) => {
76
- this.options.connectionLocker.weakUnlockConnection((0, dht_1.toNodeId)(remote.getPeerDescriptor()), this.options.streamPartId);
77
- }, this.abortController.signal);
78
- if (this.options.proxyConnectionRpcLocal !== undefined) {
79
- (0, utils_1.addManagedEventListener)(this.options.proxyConnectionRpcLocal, 'newConnection', (id) => this.options.propagation.onNeighborJoined(id), this.abortController.signal);
80
- }
81
- if (this.options.plumtreeManager) {
82
- (0, utils_1.addManagedEventListener)(this.options.plumtreeManager, 'message', (msg) => this.emit('message', msg), this.abortController.signal);
83
- }
84
- this.options.neighborFinder.start();
85
- await this.options.neighborUpdateManager.start();
86
- }
87
- registerDefaultServerMethods() {
88
- this.options.rpcCommunicator.registerRpcNotification(NetworkRpc_1.StreamMessage, 'sendStreamMessage', (msg, context) => this.contentDeliveryRpcLocal.sendStreamMessage(msg, context));
89
- this.options.rpcCommunicator.registerRpcNotification(NetworkRpc_1.LeaveStreamPartNotice, 'leaveStreamPartNotice', (req, context) => this.contentDeliveryRpcLocal.leaveStreamPartNotice(req, context));
90
- this.options.rpcCommunicator.registerRpcMethod(NetworkRpc_1.TemporaryConnectionRequest, NetworkRpc_1.TemporaryConnectionResponse, 'openConnection', (req, context) => this.options.temporaryConnectionRpcLocal.openConnection(req, context));
91
- this.options.rpcCommunicator.registerRpcNotification(NetworkRpc_1.CloseTemporaryConnection, 'closeConnection', (req, context) => this.options.temporaryConnectionRpcLocal.closeConnection(req, context));
92
- }
93
- onRingContactsUpdated() {
94
- logger.trace('onRingContactsUpdated');
95
- if (this.isStopped()) {
96
- return;
97
- }
98
- const contacts = this.options.discoveryLayerNode.getRingContacts();
99
- this.options.leftNodeView.replaceAll(contacts.left.map((peer) => new ContentDeliveryRpcRemote_1.ContentDeliveryRpcRemote(this.options.localPeerDescriptor, peer, this.options.rpcCommunicator, NetworkRpc_client_1.ContentDeliveryRpcClient, this.options.rpcRequestTimeout)));
100
- this.options.rightNodeView.replaceAll(contacts.right.map((peer) => new ContentDeliveryRpcRemote_1.ContentDeliveryRpcRemote(this.options.localPeerDescriptor, peer, this.options.rpcCommunicator, NetworkRpc_client_1.ContentDeliveryRpcClient, this.options.rpcRequestTimeout)));
101
- }
102
- onNearbyContactAdded() {
103
- logger.trace(`New nearby contact found`);
104
- if (this.isStopped()) {
105
- return;
106
- }
107
- const closestContacts = this.options.discoveryLayerNode.getClosestContacts();
108
- this.updateNearbyNodeView(closestContacts);
109
- if (this.options.neighbors.size() < this.options.neighborTargetCount) {
110
- this.options.neighborFinder.start();
111
- }
112
- }
113
- onNearbyContactRemoved() {
114
- logger.trace(`Nearby contact removed`);
115
- if (this.isStopped()) {
116
- return;
117
- }
118
- const closestContacts = this.options.discoveryLayerNode.getClosestContacts();
119
- this.updateNearbyNodeView(closestContacts);
120
- }
121
- updateNearbyNodeView(nodes) {
122
- this.options.nearbyNodeView.replaceAll(Array.from(nodes).map((descriptor) => new ContentDeliveryRpcRemote_1.ContentDeliveryRpcRemote(this.options.localPeerDescriptor, descriptor, this.options.rpcCommunicator, NetworkRpc_client_1.ContentDeliveryRpcClient, this.options.rpcRequestTimeout)));
123
- for (const descriptor of this.options.discoveryLayerNode.getNeighbors()) {
124
- if (this.options.nearbyNodeView.size() >= this.options.nodeViewSize) {
125
- break;
126
- }
127
- this.options.nearbyNodeView.add(new ContentDeliveryRpcRemote_1.ContentDeliveryRpcRemote(this.options.localPeerDescriptor, descriptor, this.options.rpcCommunicator, NetworkRpc_client_1.ContentDeliveryRpcClient, this.options.rpcRequestTimeout));
128
- }
129
- }
130
- onRandomContactAdded() {
131
- if (this.isStopped()) {
132
- return;
133
- }
134
- const randomContacts = this.options.discoveryLayerNode.getRandomContacts(this.options.nodeViewSize);
135
- this.options.randomNodeView.replaceAll(randomContacts.map((descriptor) => new ContentDeliveryRpcRemote_1.ContentDeliveryRpcRemote(this.options.localPeerDescriptor, descriptor, this.options.rpcCommunicator, NetworkRpc_client_1.ContentDeliveryRpcClient, this.options.rpcRequestTimeout)));
136
- if (this.options.neighbors.size() < this.options.neighborTargetCount) {
137
- this.options.neighborFinder.start();
138
- }
139
- }
140
- onRandomContactRemoved() {
141
- logger.trace(`New random contact removed`);
142
- if (this.isStopped()) {
143
- return;
144
- }
145
- const randomContacts = this.options.discoveryLayerNode.getRandomContacts(this.options.nodeViewSize);
146
- this.options.randomNodeView.replaceAll(randomContacts.map((descriptor) => new ContentDeliveryRpcRemote_1.ContentDeliveryRpcRemote(this.options.localPeerDescriptor, descriptor, this.options.rpcCommunicator, NetworkRpc_client_1.ContentDeliveryRpcClient, this.options.rpcRequestTimeout)));
147
- }
148
- onNodeDisconnected(peerDescriptor) {
149
- const nodeId = (0, dht_1.toNodeId)(peerDescriptor);
150
- if (this.options.neighbors.has(nodeId)) {
151
- this.options.neighbors.remove(nodeId);
152
- this.options.neighborFinder.start([nodeId]);
153
- this.options.temporaryConnectionRpcLocal.removeNode(nodeId);
154
- }
155
- }
156
- hasProxyConnection(nodeId) {
157
- if (this.options.proxyConnectionRpcLocal) {
158
- return this.options.proxyConnectionRpcLocal.hasConnection(nodeId);
159
- }
160
- return false;
161
- }
162
- stop() {
163
- if (!this.started) {
164
- return;
165
- }
166
- this.abortController.abort();
167
- this.options.proxyConnectionRpcLocal?.stop();
168
- this.options.neighbors.getAll().map((remote) => {
169
- remote.leaveStreamPartNotice(this.options.streamPartId, this.options.isLocalNodeEntryPoint());
170
- this.options.connectionLocker.weakUnlockConnection((0, dht_1.toNodeId)(remote.getPeerDescriptor()), this.options.streamPartId);
171
- });
172
- this.options.rpcCommunicator.destroy();
173
- this.removeAllListeners();
174
- this.options.plumtreeManager?.stop();
175
- this.options.nearbyNodeView.stop();
176
- this.options.neighbors.stop();
177
- this.options.randomNodeView.stop();
178
- this.options.neighborFinder.stop();
179
- this.options.neighborUpdateManager.stop();
180
- this.options.inspector.stop();
181
- }
182
- broadcast(msg, previousNode) {
183
- if (!previousNode) {
184
- (0, utils_2.markAndCheckDuplicate)(this.duplicateDetectors, msg.messageId, msg.previousMessageRef);
185
- }
186
- this.emit('message', msg);
187
- const skipBackPropagation = previousNode !== undefined && !this.options.temporaryConnectionRpcLocal.hasNode(previousNode);
188
- this.options.propagation.feedUnseenMessage(msg, this.getPropagationTargets(msg), skipBackPropagation ? previousNode : null);
189
- this.messagesPropagated += 1;
190
- }
191
- inspect(peerDescriptor) {
192
- return this.options.inspector.inspect(peerDescriptor);
193
- }
194
- getPropagationTargets(msg) {
195
- let propagationTargets = this.options.neighbors.getIds();
196
- if (this.options.proxyConnectionRpcLocal) {
197
- propagationTargets = propagationTargets.concat(this.options.proxyConnectionRpcLocal.getPropagationTargets(msg));
198
- }
199
- propagationTargets = propagationTargets.concat(this.options.temporaryConnectionRpcLocal.getNodes().getIds());
200
- return propagationTargets;
201
- }
202
- getOwnNodeId() {
203
- return (0, dht_1.toNodeId)(this.options.localPeerDescriptor);
204
- }
205
- getOutgoingHandshakeCount() {
206
- return this.options.handshaker.getOngoingHandshakes().size;
207
- }
208
- getNeighbors() {
209
- if (!this.started && this.isStopped()) {
210
- return [];
211
- }
212
- return this.options.neighbors.getAll().map((n) => n.getPeerDescriptor());
213
- }
214
- getInfos() {
215
- return this.options.neighbors.getAll().map((n) => {
216
- return {
217
- peerDescriptor: n.getPeerDescriptor(),
218
- rtt: n.getRtt()
219
- };
220
- });
221
- }
222
- getNearbyNodeView() {
223
- return this.options.nearbyNodeView;
224
- }
225
- getDiagnosticInfo() {
226
- return {
227
- neighborCount: this.options.neighbors.size(),
228
- nearbyNodeViewCount: this.options.nearbyNodeView.size(),
229
- randomNodeViewCount: this.options.randomNodeView.size(),
230
- leftNodeViewCount: this.options.leftNodeView.size(),
231
- rightNodeViewCount: this.options.rightNodeView.size(),
232
- messagesPropagated: this.messagesPropagated
233
- };
234
- }
235
- isStopped() {
236
- return this.abortController.signal.aborted;
237
- }
238
- }
239
- exports.ContentDeliveryLayerNode = ContentDeliveryLayerNode;
240
- //# sourceMappingURL=ContentDeliveryLayerNode.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ContentDeliveryLayerNode.js","sourceRoot":"","sources":["../../../src/content-delivery-layer/ContentDeliveryLayerNode.ts"],"names":[],"mappings":";;;AAAA,sCAOqB;AACrB,0CAA8E;AAC9E,iDAA4C;AAC5C,+FAQuE;AACvE,6GAAgH;AAChH,uEAAmE;AACnE,yEAAqE;AAWrE,oCAAgD;AAqCnC,QAAA,sBAAsB,GAAG,EAAE,CAAA;AAC3B,QAAA,6BAA6B,GAAG,CAAC,CAAA;AACjC,QAAA,gCAAgC,GAAG,KAAK,CAAA;AAErD,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAEjC,MAAa,wBAAyB,SAAQ,4BAAoB;IAEtD,OAAO,GAAG,KAAK,CAAA;IACN,kBAAkB,CAAuC;IAClE,OAAO,CAAuC;IACrC,uBAAuB,CAAyB;IACzD,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AE;YACnD,kBAAkB,EAAE,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,EAAE;YACrD,kBAAkB,EAAE,IAAI,CAAC,kBAAkB;SAC9C,CAAA;IACL,CAAC;IAEO,SAAS;QACb,OAAO,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,OAAO,CAAA;IAC9C,CAAC;CAEJ;AA1WD,4DA0WC"}
@@ -1,23 +0,0 @@
1
- import { ServerCallContext } from '@protobuf-ts/runtime-rpc';
2
- import { DhtAddress, ListeningRpcCommunicator, PeerDescriptor } from '@streamr/dht';
3
- import { StreamPartID } from '@streamr/utils';
4
- import { Empty } from '../../generated/google/protobuf/empty';
5
- import { LeaveStreamPartNotice, MessageID, MessageRef, StreamMessage } from '../../generated/packages/trackerless-network/protos/NetworkRpc';
6
- import { IContentDeliveryRpc } from '../../generated/packages/trackerless-network/protos/NetworkRpc.server';
7
- import { PlumtreeManager } from './plumtree/PlumtreeManager';
8
- export interface ContentDeliveryRpcLocalOptions {
9
- localPeerDescriptor: PeerDescriptor;
10
- streamPartId: StreamPartID;
11
- markAndCheckDuplicate: (messageId: MessageID, previousMessageRef?: MessageRef) => boolean;
12
- broadcast: (message: StreamMessage, previousNode?: DhtAddress) => void;
13
- onLeaveNotice(remoteNodeId: DhtAddress, isLocalNodeEntryPoint: boolean): void;
14
- markForInspection(remoteNodeId: DhtAddress, messageId: MessageID): void;
15
- rpcCommunicator: ListeningRpcCommunicator;
16
- plumtreeManager?: PlumtreeManager;
17
- }
18
- export declare class ContentDeliveryRpcLocal implements IContentDeliveryRpc {
19
- private readonly options;
20
- constructor(options: ContentDeliveryRpcLocalOptions);
21
- sendStreamMessage(message: StreamMessage, context: ServerCallContext): Promise<Empty>;
22
- leaveStreamPartNotice(message: LeaveStreamPartNotice, context: ServerCallContext): Promise<Empty>;
23
- }
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ContentDeliveryRpcLocal = void 0;
4
- const dht_1 = require("@streamr/dht");
5
- const empty_1 = require("../../generated/google/protobuf/empty");
6
- class ContentDeliveryRpcLocal {
7
- options;
8
- constructor(options) {
9
- this.options = options;
10
- }
11
- async sendStreamMessage(message, context) {
12
- const previousNode = context.incomingSourceDescriptor;
13
- const previousNodeId = (0, dht_1.toNodeId)(previousNode);
14
- this.options.markForInspection(previousNodeId, message.messageId);
15
- if (this.options.plumtreeManager === undefined) {
16
- if (this.options.markAndCheckDuplicate(message.messageId, message.previousMessageRef)) {
17
- this.options.broadcast(message, previousNodeId);
18
- }
19
- }
20
- else if (this.options.markAndCheckDuplicate(message.messageId, message.previousMessageRef)) {
21
- // Message is not a duplicate, so we can broadcast it over the plumtree
22
- this.options.plumtreeManager.broadcast(message, previousNodeId);
23
- }
24
- else {
25
- // Message is a duplicate, so we need to pause the neighbor
26
- await this.options.plumtreeManager.pauseNeighbor(previousNode, message.messageId.messageChainId);
27
- }
28
- return empty_1.Empty;
29
- }
30
- async leaveStreamPartNotice(message, context) {
31
- if (message.streamPartId === this.options.streamPartId) {
32
- const sourcePeerDescriptor = context.incomingSourceDescriptor;
33
- const remoteNodeId = (0, dht_1.toNodeId)(sourcePeerDescriptor);
34
- this.options.onLeaveNotice(remoteNodeId, message.isEntryPoint);
35
- }
36
- return empty_1.Empty;
37
- }
38
- }
39
- exports.ContentDeliveryRpcLocal = ContentDeliveryRpcLocal;
40
- //# sourceMappingURL=ContentDeliveryRpcLocal.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ContentDeliveryRpcLocal.js","sourceRoot":"","sources":["../../../src/content-delivery-layer/ContentDeliveryRpcLocal.ts"],"names":[],"mappings":";;;AACA,sCAA6G;AAE7G,iEAA6D;AAqB7D,MAAa,uBAAuB;IAEf,OAAO,CAAgC;IAExD,YAAY,OAAuC;QAC/C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IAC1B,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,OAAsB,EAAE,OAA0B;QACt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;QACD,OAAO,aAAK,CAAA;IAChB,CAAC;CACJ;AAlCD,0DAkCC"}
@@ -1,11 +0,0 @@
1
- import { RpcRemote } from '@streamr/dht';
2
- import { StreamPartID } from '@streamr/utils';
3
- import { StreamMessage } from '../../generated/packages/trackerless-network/protos/NetworkRpc';
4
- import { ContentDeliveryRpcClient } from '../../generated/packages/trackerless-network/protos/NetworkRpc.client';
5
- export declare class ContentDeliveryRpcRemote extends RpcRemote<ContentDeliveryRpcClient> {
6
- private rtt?;
7
- sendStreamMessage(msg: StreamMessage, doNotBufferWhileConnecting?: boolean): Promise<void>;
8
- leaveStreamPartNotice(streamPartId: StreamPartID, isLocalNodeEntryPoint: boolean): void;
9
- setRtt(rtt: number): void;
10
- getRtt(): number | undefined;
11
- }
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ContentDeliveryRpcRemote = void 0;
4
- const dht_1 = require("@streamr/dht");
5
- const utils_1 = require("@streamr/utils");
6
- const logger = new utils_1.Logger(module);
7
- class ContentDeliveryRpcRemote extends dht_1.RpcRemote {
8
- rtt;
9
- async sendStreamMessage(msg, doNotBufferWhileConnecting) {
10
- const options = this.formDhtRpcOptions({
11
- notification: true,
12
- doNotBufferWhileConnecting
13
- });
14
- this.getClient().sendStreamMessage(msg, options).catch(() => {
15
- logger.trace('Failed to sendStreamMessage');
16
- });
17
- }
18
- leaveStreamPartNotice(streamPartId, isLocalNodeEntryPoint) {
19
- const notification = {
20
- streamPartId,
21
- isEntryPoint: isLocalNodeEntryPoint
22
- };
23
- const options = this.formDhtRpcOptions({
24
- notification: true
25
- });
26
- this.getClient().leaveStreamPartNotice(notification, options).catch(() => {
27
- logger.debug('Failed to send leaveStreamPartNotice');
28
- });
29
- }
30
- setRtt(rtt) {
31
- this.rtt = rtt;
32
- }
33
- getRtt() {
34
- return this.rtt;
35
- }
36
- }
37
- exports.ContentDeliveryRpcRemote = ContentDeliveryRpcRemote;
38
- //# sourceMappingURL=ContentDeliveryRpcRemote.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ContentDeliveryRpcRemote.js","sourceRoot":"","sources":["../../../src/content-delivery-layer/ContentDeliveryRpcRemote.ts"],"names":[],"mappings":";;;AAAA,sCAAwC;AACxC,0CAAqD;AAOrD,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAEjC,MAAa,wBAAyB,SAAQ,eAAmC;IAErE,GAAG,CAAS;IAEpB,KAAK,CAAC,iBAAiB,CAAC,GAAkB,EAAE,0BAAoC;QAC5E,MAAM,OAAO,GAAG,IAAI,CAAC,iBAAiB,CAAC;YACnC,YAAY,EAAE,IAAI;YAClB,0BAA0B;SAC7B,CAAC,CAAA;QACF,IAAI,CAAC,SAAS,EAAE,CAAC,iBAAiB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;YACxD,MAAM,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAA;QAC/C,CAAC,CAAC,CAAA;IACN,CAAC;IAED,qBAAqB,CAAC,YAA0B,EAAE,qBAA8B;QAC5E,MAAM,YAAY,GAA0B;YACxC,YAAY;YACZ,YAAY,EAAE,qBAAqB;SACtC,CAAA;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,iBAAiB,CAAC;YACnC,YAAY,EAAE,IAAI;SACrB,CAAC,CAAA;QACF,IAAI,CAAC,SAAS,EAAE,CAAC,qBAAqB,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;YACrE,MAAM,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAA;QACxD,CAAC,CAAC,CAAA;IACN,CAAC;IAED,MAAM,CAAC,GAAW;QACd,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;IAClB,CAAC;IAED,MAAM;QACF,OAAO,IAAI,CAAC,GAAG,CAAA;IACnB,CAAC;CACJ;AAlCD,4DAkCC"}
@@ -1,55 +0,0 @@
1
- /**
2
- * Represent a pair of numbers (a,b). Ordering between two pairs is defined as
3
- * follows. First compare first numbers. Compare second numbers if first are
4
- * equal.
5
- */
6
- export declare class NumberPair {
7
- private readonly a;
8
- private readonly b;
9
- constructor(a: number, b: number);
10
- greaterThanOrEqual(otherPair: NumberPair): boolean;
11
- greaterThan(otherPair: NumberPair): boolean;
12
- equalTo(otherPair: NumberPair): boolean;
13
- private compareTo;
14
- toString(): string;
15
- }
16
- export declare class InvalidNumberingError extends Error {
17
- constructor();
18
- }
19
- export declare class GapMisMatchError extends Error {
20
- constructor(state: string, previousNumber: NumberPair, number: NumberPair);
21
- }
22
- /**
23
- *
24
- * Keeps track of a stream's message numbers and reports already seen numbers
25
- * as duplicates.
26
- *
27
- * Leverages the fact that message are assigned numbers from a strictly
28
- * increasing integer sequence for lowered space complexity. For example,
29
- * if we know that all messages up to number N have been seen, we can only
30
- * store the number N to provide message identity check. This is because
31
- * anything less than N can be deemed a duplicate.
32
- *
33
- * Messages arriving out-of-order makes this a bit harder since gaps form.
34
- * Most of the code in this class is built to deal with this complexity.
35
- * Basically, we need to keep track of which intervals [N,M] could still
36
- * contain unseen messages. We should also remove intervals after we are sure
37
- * that they contain no unseen messages.
38
- *
39
- * In addition to the above, there needs to be a limit to the number of
40
- * intervals we store, as it could well be that some messages never
41
- * arrive. The strategy is to start removing the lowest numbered
42
- * intervals when storage limits are hit.
43
- *
44
- */
45
- export declare class DuplicateMessageDetector {
46
- private readonly maxGapCount;
47
- private readonly gaps;
48
- constructor(maxGapCount?: number);
49
- /**
50
- * returns true if number has not yet been seen (i.e. is not a duplicate)
51
- */
52
- markAndCheck(previousNumber: NumberPair | null, number: NumberPair): boolean | never;
53
- private dropLowestGapIfOverMaxGapCount;
54
- toString(): string;
55
- }
@@ -1,159 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DuplicateMessageDetector = exports.GapMisMatchError = exports.InvalidNumberingError = exports.NumberPair = void 0;
4
- /**
5
- * Represent a pair of numbers (a,b). Ordering between two pairs is defined as
6
- * follows. First compare first numbers. Compare second numbers if first are
7
- * equal.
8
- */
9
- class NumberPair {
10
- a;
11
- b;
12
- constructor(a, b) {
13
- this.a = a;
14
- this.b = b;
15
- }
16
- greaterThanOrEqual(otherPair) {
17
- return this.greaterThan(otherPair) || this.equalTo(otherPair);
18
- }
19
- greaterThan(otherPair) {
20
- return this.compareTo(otherPair) === 1;
21
- }
22
- equalTo(otherPair) {
23
- return this.compareTo(otherPair) === 0;
24
- }
25
- compareTo(otherPair) {
26
- if (this.a > otherPair.a) {
27
- return 1;
28
- }
29
- if (this.a < otherPair.a) {
30
- return -1;
31
- }
32
- if (this.b > otherPair.b) {
33
- return 1;
34
- }
35
- if (this.b < otherPair.b) {
36
- return -1;
37
- }
38
- return 0;
39
- }
40
- toString() {
41
- return `${this.a}|${this.b}`;
42
- }
43
- }
44
- exports.NumberPair = NumberPair;
45
- class InvalidNumberingError extends Error {
46
- constructor() {
47
- super('pre-condition: previousNumber < number');
48
- }
49
- }
50
- exports.InvalidNumberingError = InvalidNumberingError;
51
- class GapMisMatchError extends Error {
52
- constructor(state, previousNumber, number) {
53
- super('pre-condition: gap overlap in given numbers:'
54
- + ` previousNumber=${previousNumber.toString()}, number=${number.toString()}, state=${state}`);
55
- }
56
- }
57
- exports.GapMisMatchError = GapMisMatchError;
58
- /**
59
- *
60
- * Keeps track of a stream's message numbers and reports already seen numbers
61
- * as duplicates.
62
- *
63
- * Leverages the fact that message are assigned numbers from a strictly
64
- * increasing integer sequence for lowered space complexity. For example,
65
- * if we know that all messages up to number N have been seen, we can only
66
- * store the number N to provide message identity check. This is because
67
- * anything less than N can be deemed a duplicate.
68
- *
69
- * Messages arriving out-of-order makes this a bit harder since gaps form.
70
- * Most of the code in this class is built to deal with this complexity.
71
- * Basically, we need to keep track of which intervals [N,M] could still
72
- * contain unseen messages. We should also remove intervals after we are sure
73
- * that they contain no unseen messages.
74
- *
75
- * In addition to the above, there needs to be a limit to the number of
76
- * intervals we store, as it could well be that some messages never
77
- * arrive. The strategy is to start removing the lowest numbered
78
- * intervals when storage limits are hit.
79
- *
80
- */
81
- class DuplicateMessageDetector {
82
- maxGapCount;
83
- gaps;
84
- constructor(maxGapCount = 10000) {
85
- this.maxGapCount = maxGapCount;
86
- this.gaps = []; // ascending order of half-closed intervals (x,y] representing gaps that contain unseen message(s)
87
- }
88
- /**
89
- * returns true if number has not yet been seen (i.e. is not a duplicate)
90
- */
91
- markAndCheck(previousNumber, number) {
92
- if (previousNumber?.greaterThanOrEqual(number)) {
93
- throw new InvalidNumberingError();
94
- }
95
- if (this.gaps.length === 0) {
96
- this.gaps.push([number, new NumberPair(Infinity, Infinity)]);
97
- return true;
98
- }
99
- // Handle special case where previousNumber is not provided. Only
100
- // minimal duplicate detection is provided (comparing against latest
101
- // known message number).
102
- if (previousNumber === null) {
103
- if (number.greaterThan(this.gaps[this.gaps.length - 1][0])) {
104
- this.gaps[this.gaps.length - 1][0] = number;
105
- return true;
106
- }
107
- return false;
108
- }
109
- for (let i = this.gaps.length - 1; i >= 0; --i) {
110
- const [lowerBound, upperBound] = this.gaps[i]; // invariant: upperBound > lowerBound
111
- // implies number > upperBound (would've been handled in previous iteration if gap exists)
112
- if (previousNumber.greaterThanOrEqual(upperBound)) {
113
- return false;
114
- }
115
- if (previousNumber.greaterThanOrEqual(lowerBound)) {
116
- if (number.greaterThan(upperBound)) {
117
- throw new GapMisMatchError(this.toString(), previousNumber, number);
118
- }
119
- if (previousNumber.equalTo(lowerBound)) {
120
- if (number.equalTo(upperBound)) {
121
- this.gaps.splice(i, 1);
122
- }
123
- else {
124
- this.gaps[i] = [number, upperBound];
125
- }
126
- }
127
- else if (number.equalTo(upperBound)) {
128
- this.gaps[i] = [lowerBound, previousNumber];
129
- }
130
- else {
131
- this.gaps.splice(i, 1, [lowerBound, previousNumber], [number, upperBound]);
132
- }
133
- // invariants after:
134
- // - gaps are in ascending order
135
- // - the intersection between any two gaps is empty
136
- // - there are no gaps that define the empty set
137
- // - last gap is [n, Infinity]
138
- // - anything not covered by a gap is considered seen
139
- this.dropLowestGapIfOverMaxGapCount();
140
- return true;
141
- }
142
- if (number.greaterThan(lowerBound)) {
143
- throw new GapMisMatchError(this.toString(), previousNumber, number);
144
- }
145
- }
146
- return false;
147
- }
148
- dropLowestGapIfOverMaxGapCount() {
149
- // invariant: this.gaps.length <= this.maxGapCount + 1
150
- if (this.gaps.length > this.maxGapCount) {
151
- this.gaps.shift();
152
- }
153
- }
154
- toString() {
155
- return this.gaps.map(([lower, upper]) => `(${lower.toString()}, ${upper.toString()}]`).join(', ');
156
- }
157
- }
158
- exports.DuplicateMessageDetector = DuplicateMessageDetector;
159
- //# sourceMappingURL=DuplicateMessageDetector.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DuplicateMessageDetector.js","sourceRoot":"","sources":["../../../src/content-delivery-layer/DuplicateMessageDetector.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,MAAa,UAAU;IACF,CAAC,CAAA;IACD,CAAC,CAAA;IAElB,YAAY,CAAS,EAAE,CAAS;QAC5B,IAAI,CAAC,CAAC,GAAG,CAAC,CAAA;QACV,IAAI,CAAC,CAAC,GAAG,CAAC,CAAA;IACd,CAAC;IAED,kBAAkB,CAAC,SAAqB;QACpC,OAAO,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;IACjE,CAAC;IAED,WAAW,CAAC,SAAqB;QAC7B,OAAO,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IAC1C,CAAC;IAED,OAAO,CAAC,SAAqB;QACzB,OAAO,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IAC1C,CAAC;IAEO,SAAS,CAAC,SAAqB;QACnC,IAAI,IAAI,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,EAAE,CAAC;YACvB,OAAO,CAAC,CAAA;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O,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,QAAQ,EAAE,KAAK,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACrG,CAAC;CACJ;AAnFD,4DAmFC"}
@@ -1,26 +0,0 @@
1
- import { DhtAddress } from '@streamr/dht';
2
- import { ContentDeliveryRpcRemote } from './ContentDeliveryRpcRemote';
3
- import { EventEmitter } from 'eventemitter3';
4
- export interface Events {
5
- nodeAdded: (id: DhtAddress, remote: ContentDeliveryRpcRemote) => void;
6
- nodeRemoved: (id: DhtAddress, remote: ContentDeliveryRpcRemote) => void;
7
- }
8
- export declare class NodeList extends EventEmitter<Events> {
9
- private readonly nodes;
10
- private readonly limit;
11
- private ownId;
12
- constructor(ownId: DhtAddress, limit: number);
13
- add(remote: ContentDeliveryRpcRemote): void;
14
- remove(nodeId: DhtAddress): void;
15
- has(nodeId: DhtAddress): boolean;
16
- replaceAll(neighbors: ContentDeliveryRpcRemote[]): void;
17
- getIds(): DhtAddress[];
18
- get(id: DhtAddress): ContentDeliveryRpcRemote | undefined;
19
- size(exclude?: DhtAddress[]): number;
20
- getRandom(exclude: DhtAddress[]): ContentDeliveryRpcRemote | undefined;
21
- getFirst(exclude: DhtAddress[], wsOnly?: boolean): ContentDeliveryRpcRemote | undefined;
22
- getFirstAndLast(exclude: DhtAddress[]): ContentDeliveryRpcRemote[];
23
- getLast(exclude: DhtAddress[]): ContentDeliveryRpcRemote | undefined;
24
- getAll(): ContentDeliveryRpcRemote[];
25
- stop(): void;
26
- }