@streamr/dht 0.0.1-tatum.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.
- package/.eslintignore +5 -0
- package/.eslintrc +3 -0
- package/README.md +38 -0
- package/dist/src/connection/Connection.d.ts +11 -0
- package/dist/src/connection/Connection.js +23 -0
- package/dist/src/connection/Connection.js.map +1 -0
- package/dist/src/connection/ConnectionLockHandler.d.ts +23 -0
- package/dist/src/connection/ConnectionLockHandler.js +94 -0
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -0
- package/dist/src/connection/ConnectionManager.d.ts +94 -0
- package/dist/src/connection/ConnectionManager.js +554 -0
- package/dist/src/connection/ConnectionManager.js.map +1 -0
- package/dist/src/connection/ConnectivityChecker.d.ts +17 -0
- package/dist/src/connection/ConnectivityChecker.js +187 -0
- package/dist/src/connection/ConnectivityChecker.js.map +1 -0
- package/dist/src/connection/Handshaker.d.ts +19 -0
- package/dist/src/connection/Handshaker.js +77 -0
- package/dist/src/connection/Handshaker.js.map +1 -0
- package/dist/src/connection/IConnection.d.ts +38 -0
- package/dist/src/connection/IConnection.js +19 -0
- package/dist/src/connection/IConnection.js.map +1 -0
- package/dist/src/connection/IConnectionSource.d.ts +4 -0
- package/dist/src/connection/IConnectionSource.js +3 -0
- package/dist/src/connection/IConnectionSource.js.map +1 -0
- package/dist/src/connection/ManagedConnection.d.ts +60 -0
- package/dist/src/connection/ManagedConnection.js +352 -0
- package/dist/src/connection/ManagedConnection.js.map +1 -0
- package/dist/src/connection/ManagedWebRtcConnection.d.ts +7 -0
- package/dist/src/connection/ManagedWebRtcConnection.js +20 -0
- package/dist/src/connection/ManagedWebRtcConnection.js.map +1 -0
- package/dist/src/connection/RemoteConnectionLocker.d.ts +14 -0
- package/dist/src/connection/RemoteConnectionLocker.js +93 -0
- package/dist/src/connection/RemoteConnectionLocker.js.map +1 -0
- package/dist/src/connection/Simulator/Simulator.d.ts +42 -0
- package/dist/src/connection/Simulator/Simulator.js +325 -0
- package/dist/src/connection/Simulator/Simulator.js.map +1 -0
- package/dist/src/connection/Simulator/SimulatorConnection.d.ts +19 -0
- package/dist/src/connection/Simulator/SimulatorConnection.js +118 -0
- package/dist/src/connection/Simulator/SimulatorConnection.js.map +1 -0
- package/dist/src/connection/Simulator/SimulatorConnector.d.ts +17 -0
- package/dist/src/connection/Simulator/SimulatorConnector.js +72 -0
- package/dist/src/connection/Simulator/SimulatorConnector.js.map +1 -0
- package/dist/src/connection/Simulator/SimulatorTransport.d.ts +6 -0
- package/dist/src/connection/Simulator/SimulatorTransport.js +11 -0
- package/dist/src/connection/Simulator/SimulatorTransport.js.map +1 -0
- package/dist/src/connection/Simulator/pings.d.ts +21 -0
- package/dist/src/connection/Simulator/pings.js +61 -0
- package/dist/src/connection/Simulator/pings.js.map +1 -0
- package/dist/src/connection/WebRTC/IWebRtcConnection.d.ts +20 -0
- package/dist/src/connection/WebRTC/IWebRtcConnection.js +9 -0
- package/dist/src/connection/WebRTC/IWebRtcConnection.js.map +1 -0
- package/dist/src/connection/WebRTC/NodeWebRtcConnection.d.ts +47 -0
- package/dist/src/connection/WebRTC/NodeWebRtcConnection.js +233 -0
- package/dist/src/connection/WebRTC/NodeWebRtcConnection.js.map +1 -0
- package/dist/src/connection/WebRTC/RemoteWebrtcConnector.d.ts +12 -0
- package/dist/src/connection/WebRTC/RemoteWebrtcConnector.js +74 -0
- package/dist/src/connection/WebRTC/RemoteWebrtcConnector.js.map +1 -0
- package/dist/src/connection/WebRTC/WebRtcConnector.d.ts +47 -0
- package/dist/src/connection/WebRTC/WebRtcConnector.js +227 -0
- package/dist/src/connection/WebRTC/WebRtcConnector.js.map +1 -0
- package/dist/src/connection/WebRTC/iceServerAsString.d.ts +2 -0
- package/dist/src/connection/WebRTC/iceServerAsString.js +18 -0
- package/dist/src/connection/WebRTC/iceServerAsString.js.map +1 -0
- package/dist/src/connection/WebSocket/ClientWebSocket.d.ts +15 -0
- package/dist/src/connection/WebSocket/ClientWebSocket.js +113 -0
- package/dist/src/connection/WebSocket/ClientWebSocket.js.map +1 -0
- package/dist/src/connection/WebSocket/RemoteWebSocketConnector.d.ts +9 -0
- package/dist/src/connection/WebSocket/RemoteWebSocketConnector.js +63 -0
- package/dist/src/connection/WebSocket/RemoteWebSocketConnector.js.map +1 -0
- package/dist/src/connection/WebSocket/ServerWebSocket.d.ts +18 -0
- package/dist/src/connection/WebSocket/ServerWebSocket.js +103 -0
- package/dist/src/connection/WebSocket/ServerWebSocket.js.map +1 -0
- package/dist/src/connection/WebSocket/WebSocketConnector.d.ts +31 -0
- package/dist/src/connection/WebSocket/WebSocketConnector.js +202 -0
- package/dist/src/connection/WebSocket/WebSocketConnector.js.map +1 -0
- package/dist/src/connection/WebSocket/WebSocketServer.d.ts +9 -0
- package/dist/src/connection/WebSocket/WebSocketServer.js +101 -0
- package/dist/src/connection/WebSocket/WebSocketServer.js.map +1 -0
- package/dist/src/dht/DhtNode.d.ts +153 -0
- package/dist/src/dht/DhtNode.js +599 -0
- package/dist/src/dht/DhtNode.js.map +1 -0
- package/dist/src/dht/DhtPeer.d.ts +18 -0
- package/dist/src/dht/DhtPeer.js +74 -0
- package/dist/src/dht/DhtPeer.js.map +1 -0
- package/dist/src/dht/ExternalApi.d.ts +8 -0
- package/dist/src/dht/ExternalApi.js +26 -0
- package/dist/src/dht/ExternalApi.js.map +1 -0
- package/dist/src/dht/RemoteExternalApi.d.ts +6 -0
- package/dist/src/dht/RemoteExternalApi.js +26 -0
- package/dist/src/dht/RemoteExternalApi.js.map +1 -0
- package/dist/src/dht/contact/Contact.d.ts +22 -0
- package/dist/src/dht/contact/Contact.js +25 -0
- package/dist/src/dht/contact/Contact.js.map +1 -0
- package/dist/src/dht/contact/RandomContactList.d.ts +20 -0
- package/dist/src/dht/contact/RandomContactList.js +78 -0
- package/dist/src/dht/contact/RandomContactList.js.map +1 -0
- package/dist/src/dht/contact/Remote.d.ts +15 -0
- package/dist/src/dht/contact/Remote.js +24 -0
- package/dist/src/dht/contact/Remote.js.map +1 -0
- package/dist/src/dht/contact/SortedContactList.d.ts +35 -0
- package/dist/src/dht/contact/SortedContactList.js +156 -0
- package/dist/src/dht/contact/SortedContactList.js.map +1 -0
- package/dist/src/dht/discovery/DiscoverySession.d.ts +36 -0
- package/dist/src/dht/discovery/DiscoverySession.js +116 -0
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -0
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +42 -0
- package/dist/src/dht/discovery/PeerDiscovery.js +157 -0
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -0
- package/dist/src/dht/find/RecursiveFindSession.d.ts +46 -0
- package/dist/src/dht/find/RecursiveFindSession.js +142 -0
- package/dist/src/dht/find/RecursiveFindSession.js.map +1 -0
- package/dist/src/dht/find/RecursiveFinder.d.ts +54 -0
- package/dist/src/dht/find/RecursiveFinder.js +180 -0
- package/dist/src/dht/find/RecursiveFinder.js.map +1 -0
- package/dist/src/dht/find/RemoteRecursiveFindSession.d.ts +6 -0
- package/dist/src/dht/find/RemoteRecursiveFindSession.js +25 -0
- package/dist/src/dht/find/RemoteRecursiveFindSession.js.map +1 -0
- package/dist/src/dht/routing/DuplicateDetector.d.ts +13 -0
- package/dist/src/dht/routing/DuplicateDetector.js +41 -0
- package/dist/src/dht/routing/DuplicateDetector.js.map +1 -0
- package/dist/src/dht/routing/RemoteRouter.d.ts +8 -0
- package/dist/src/dht/routing/RemoteRouter.js +106 -0
- package/dist/src/dht/routing/RemoteRouter.js.map +1 -0
- package/dist/src/dht/routing/Router.d.ts +60 -0
- package/dist/src/dht/routing/Router.js +207 -0
- package/dist/src/dht/routing/Router.js.map +1 -0
- package/dist/src/dht/routing/RoutingSession.d.ts +42 -0
- package/dist/src/dht/routing/RoutingSession.js +178 -0
- package/dist/src/dht/routing/RoutingSession.js.map +1 -0
- package/dist/src/dht/store/DataStore.d.ts +45 -0
- package/dist/src/dht/store/DataStore.js +244 -0
- package/dist/src/dht/store/DataStore.js.map +1 -0
- package/dist/src/dht/store/LocalDataStore.d.ts +19 -0
- package/dist/src/dht/store/LocalDataStore.js +104 -0
- package/dist/src/dht/store/LocalDataStore.js.map +1 -0
- package/dist/src/dht/store/RemoteStore.d.ts +8 -0
- package/dist/src/dht/store/RemoteStore.js +44 -0
- package/dist/src/dht/store/RemoteStore.js.map +1 -0
- package/dist/src/exports.d.ts +19 -0
- package/dist/src/exports.js +41 -0
- package/dist/src/exports.js.map +1 -0
- package/dist/src/helpers/AddressTools.d.ts +2 -0
- package/dist/src/helpers/AddressTools.js +31 -0
- package/dist/src/helpers/AddressTools.js.map +1 -0
- package/dist/src/helpers/PeerID.d.ts +25 -0
- package/dist/src/helpers/PeerID.js +84 -0
- package/dist/src/helpers/PeerID.js.map +1 -0
- package/dist/src/helpers/UUID.d.ts +7 -0
- package/dist/src/helpers/UUID.js +32 -0
- package/dist/src/helpers/UUID.js.map +1 -0
- package/dist/src/helpers/debugHelpers.d.ts +3 -0
- package/dist/src/helpers/debugHelpers.js +11 -0
- package/dist/src/helpers/debugHelpers.js.map +1 -0
- package/dist/src/helpers/errors.d.ts +72 -0
- package/dist/src/helpers/errors.js +95 -0
- package/dist/src/helpers/errors.js.map +1 -0
- package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +5 -0
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +17 -0
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -0
- package/dist/src/helpers/protoClasses.d.ts +2 -0
- package/dist/src/helpers/protoClasses.js +35 -0
- package/dist/src/helpers/protoClasses.js.map +1 -0
- package/dist/src/helpers/protoToString.d.ts +2 -0
- package/dist/src/helpers/protoToString.js +20 -0
- package/dist/src/helpers/protoToString.js.map +1 -0
- package/dist/src/proto/google/protobuf/any.d.ts +173 -0
- package/dist/src/proto/google/protobuf/any.js +155 -0
- package/dist/src/proto/google/protobuf/any.js.map +1 -0
- package/dist/src/proto/google/protobuf/empty.d.ts +32 -0
- package/dist/src/proto/google/protobuf/empty.js +34 -0
- package/dist/src/proto/google/protobuf/empty.js.map +1 -0
- package/dist/src/proto/google/protobuf/timestamp.d.ts +149 -0
- package/dist/src/proto/google/protobuf/timestamp.js +136 -0
- package/dist/src/proto/google/protobuf/timestamp.js.map +1 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +320 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +245 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +1089 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +710 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +145 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.js +3 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.js.map +1 -0
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.d.ts +87 -0
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +66 -0
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js.map +1 -0
- package/dist/src/proto/tests.d.ts +39 -0
- package/dist/src/proto/tests.js +34 -0
- package/dist/src/proto/tests.js.map +1 -0
- package/dist/src/rpc-protocol/DhtCallContext.d.ts +12 -0
- package/dist/src/rpc-protocol/DhtCallContext.js +8 -0
- package/dist/src/rpc-protocol/DhtCallContext.js.map +1 -0
- package/dist/src/rpc-protocol/DhtRpcOptions.d.ts +8 -0
- package/dist/src/rpc-protocol/DhtRpcOptions.js +3 -0
- package/dist/src/rpc-protocol/DhtRpcOptions.js.map +1 -0
- package/dist/src/transport/ITransport.d.ts +22 -0
- package/dist/src/transport/ITransport.js +3 -0
- package/dist/src/transport/ITransport.js.map +1 -0
- package/dist/src/transport/ListeningRpcCommunicator.d.ts +6 -0
- package/dist/src/transport/ListeningRpcCommunicator.js +14 -0
- package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -0
- package/dist/src/transport/RoutingRpcCommunicator.d.ts +8 -0
- package/dist/src/transport/RoutingRpcCommunicator.js +52 -0
- package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -0
- package/jest.config.js +2 -0
- package/karma.config.js +20 -0
- package/package.json +64 -0
- package/proto.sh +3 -0
- package/protos/DhtRpc.proto +330 -0
- package/protos/tests.proto +16 -0
- package/src/connection/Connection.ts +23 -0
- package/src/connection/ConnectionLockHandler.ts +105 -0
- package/src/connection/ConnectionManager.ts +676 -0
- package/src/connection/ConnectivityChecker.ts +173 -0
- package/src/connection/Handshaker.ts +92 -0
- package/src/connection/IConnection.ts +47 -0
- package/src/connection/IConnectionSource.ts +6 -0
- package/src/connection/ManagedConnection.ts +398 -0
- package/src/connection/ManagedWebRtcConnection.ts +27 -0
- package/src/connection/RemoteConnectionLocker.ts +88 -0
- package/src/connection/Simulator/Simulator.ts +399 -0
- package/src/connection/Simulator/SimulatorConnection.ts +137 -0
- package/src/connection/Simulator/SimulatorConnector.ts +104 -0
- package/src/connection/Simulator/SimulatorTransport.ts +9 -0
- package/src/connection/Simulator/pings.ts +42 -0
- package/src/connection/WebRTC/BrowserWebRtcConnection.ts +227 -0
- package/src/connection/WebRTC/IWebRtcConnection.ts +24 -0
- package/src/connection/WebRTC/NodeWebRtcConnection.ts +256 -0
- package/src/connection/WebRTC/RemoteWebrtcConnector.ts +93 -0
- package/src/connection/WebRTC/WebRtcConnector.ts +306 -0
- package/src/connection/WebRTC/iceServerAsString.ts +15 -0
- package/src/connection/WebSocket/ClientWebSocket.ts +118 -0
- package/src/connection/WebSocket/RemoteWebSocketConnector.ts +49 -0
- package/src/connection/WebSocket/ServerWebSocket.ts +119 -0
- package/src/connection/WebSocket/WebSocketConnector.ts +264 -0
- package/src/connection/WebSocket/WebSocketServer.ts +97 -0
- package/src/dht/DhtNode.ts +776 -0
- package/src/dht/DhtPeer.ts +96 -0
- package/src/dht/ExternalApi.ts +29 -0
- package/src/dht/RemoteExternalApi.ts +25 -0
- package/src/dht/contact/Contact.ts +36 -0
- package/src/dht/contact/RandomContactList.ts +92 -0
- package/src/dht/contact/Remote.ts +40 -0
- package/src/dht/contact/SortedContactList.ts +196 -0
- package/src/dht/discovery/DiscoverySession.ts +150 -0
- package/src/dht/discovery/PeerDiscovery.ts +162 -0
- package/src/dht/find/RecursiveFindSession.ts +178 -0
- package/src/dht/find/RecursiveFinder.ts +272 -0
- package/src/dht/find/RemoteRecursiveFindSession.ts +33 -0
- package/src/dht/routing/DuplicateDetector.ts +53 -0
- package/src/dht/routing/RemoteRouter.ts +115 -0
- package/src/dht/routing/Router.ts +266 -0
- package/src/dht/routing/RoutingSession.ts +222 -0
- package/src/dht/store/DataStore.ts +321 -0
- package/src/dht/store/LocalDataStore.ts +114 -0
- package/src/dht/store/RemoteStore.ts +58 -0
- package/src/exports.ts +19 -0
- package/src/helpers/AddressTools.ts +26 -0
- package/src/helpers/PeerID.ts +95 -0
- package/src/helpers/UUID.ts +30 -0
- package/src/helpers/debugHelpers.ts +9 -0
- package/src/helpers/errors.ts +49 -0
- package/src/helpers/peerIdFromPeerDescriptor.ts +14 -0
- package/src/helpers/protoClasses.ts +63 -0
- package/src/helpers/protoToString.ts +21 -0
- package/src/proto/google/protobuf/any.ts +319 -0
- package/src/proto/google/protobuf/empty.ts +84 -0
- package/src/proto/google/protobuf/timestamp.ts +281 -0
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +373 -0
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +148 -0
- package/src/proto/packages/dht/protos/DhtRpc.ts +1399 -0
- package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +108 -0
- package/src/proto/tests.ts +52 -0
- package/src/rpc-protocol/DhtCallContext.ts +15 -0
- package/src/rpc-protocol/DhtRpcOptions.ts +9 -0
- package/src/transport/ITransport.ts +31 -0
- package/src/transport/ListeningRpcCommunicator.ts +14 -0
- package/src/transport/RoutingRpcCommunicator.ts +59 -0
- package/src/types/glogal.d.ts +1 -0
- package/src/types/textencoding.d.ts +7 -0
- package/test/RandomGraphSimulation.ts +52 -0
- package/test/benchmark/KademliaCorrectness.test.ts +115 -0
- package/test/benchmark/RecursiveFind.test.ts +87 -0
- package/test/benchmark/any.test.ts +28 -0
- package/test/benchmark/kademlia-simulation/Contact.ts +32 -0
- package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +94 -0
- package/test/benchmark/kademlia-simulation/SimulationNode.ts +125 -0
- package/test/data/generateGroundTruthData.ts +70 -0
- package/test/end-to-end/Layer0-Layer1.test.ts +87 -0
- package/test/end-to-end/Layer0.test.ts +60 -0
- package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +94 -0
- package/test/end-to-end/Layer0WebRTC-Layer1.test.ts +134 -0
- package/test/end-to-end/Layer0WebRTC.test.ts +98 -0
- package/test/end-to-end/Layer1-Scale-WebRTC.test.ts +69 -0
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +73 -0
- package/test/end-to-end/WebSocketConnectionRequest.test.ts +62 -0
- package/test/integration/ConnectionLocking.test.ts +166 -0
- package/test/integration/ConnectionManager.test.ts +291 -0
- package/test/integration/DhtNodeExternalAPI.test.ts +43 -0
- package/test/integration/DhtPeer.test.ts +73 -0
- package/test/integration/DhtRpc.test.ts +131 -0
- package/test/integration/DhtWithMockConnectionLatencies.test.ts +46 -0
- package/test/integration/DhtWithMockConnections.test.ts +46 -0
- package/test/integration/DhtWithRealConnectionLatencies.test.ts +47 -0
- package/test/integration/Layer1-scale.test.ts +200 -0
- package/test/integration/MigrateData.test.ts +203 -0
- package/test/integration/Mock-Layer1-Layer0.test.ts +106 -0
- package/test/integration/MultipleEntryPointJoining.test.ts +105 -0
- package/test/integration/RecursiveFind.test.ts +50 -0
- package/test/integration/RemoteRouter.test.ts +83 -0
- package/test/integration/RemoteStore.test.ts +66 -0
- package/test/integration/RouteMessage.test.ts +254 -0
- package/test/integration/RpcErrors.test.ts +153 -0
- package/test/integration/ScaleDownDht.test.ts +66 -0
- package/test/integration/SimultaneousConnections.test.ts +308 -0
- package/test/integration/Store.test.ts +72 -0
- package/test/integration/StoreAndDelete.test.ts +93 -0
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +71 -0
- package/test/integration/WebRtcConnectionManagement.test.ts +205 -0
- package/test/integration/WebRtcConnectorRpc.test.ts +145 -0
- package/test/integration/WebSocket.test.ts +64 -0
- package/test/integration/WebSocketConnectionManagement.test.ts +131 -0
- package/test/integration/WebSocketConnectorRpc.test.ts +86 -0
- package/test/kademlia-simulation/data/nodeids.json +13002 -0
- package/test/kademlia-simulation/data/orderedneighbors.json +1001 -0
- package/test/unit/AddressTools.test.ts +40 -0
- package/test/unit/DuplicateDetector.test.ts +29 -0
- package/test/unit/LocalDataStore.test.ts +107 -0
- package/test/unit/PeerID.test.ts +22 -0
- package/test/unit/ProtobufMessage.test.ts +21 -0
- package/test/unit/RandomContactList.test.ts +87 -0
- package/test/unit/RecursiveFinder.test.ts +112 -0
- package/test/unit/Router.test.ts +124 -0
- package/test/unit/SortedContactList.test.ts +127 -0
- package/test/unit/UUID.test.ts +49 -0
- package/test/unit/WebSocketServer.test.ts +42 -0
- package/test/utils/mock/RecursiveFinder.ts +19 -0
- package/test/utils/mock/Router.ts +53 -0
- package/test/utils/mock/Transport.ts +26 -0
- package/test/utils/utils.ts +311 -0
- package/tsconfig.browser.json +15 -0
- package/tsconfig.jest.json +19 -0
- package/tsconfig.json +3 -0
- package/tsconfig.node.json +18 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// @generated by protobuf-ts 2.8.2 with parameter server_generic,generate_dependencies,long_type_number
|
|
2
|
+
// @generated from protobuf file "packages/proto-rpc/protos/ProtoRpc.proto" (package "protorpc", syntax proto3)
|
|
3
|
+
// tslint:disable
|
|
4
|
+
import { MessageType } from "@protobuf-ts/runtime";
|
|
5
|
+
import { Empty } from "../../../google/protobuf/empty";
|
|
6
|
+
import { Any } from "../../../google/protobuf/any";
|
|
7
|
+
/**
|
|
8
|
+
* @generated from protobuf message protorpc.RpcMessage
|
|
9
|
+
*/
|
|
10
|
+
export interface RpcMessage {
|
|
11
|
+
/**
|
|
12
|
+
* @generated from protobuf field: map<string, string> header = 1;
|
|
13
|
+
*/
|
|
14
|
+
header: {
|
|
15
|
+
[key: string]: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* @generated from protobuf field: google.protobuf.Any body = 2;
|
|
19
|
+
*/
|
|
20
|
+
body?: Any;
|
|
21
|
+
/**
|
|
22
|
+
* @generated from protobuf field: string requestId = 3;
|
|
23
|
+
*/
|
|
24
|
+
requestId: string;
|
|
25
|
+
/**
|
|
26
|
+
* @generated from protobuf field: optional protorpc.RpcErrorType errorType = 4;
|
|
27
|
+
*/
|
|
28
|
+
errorType?: RpcErrorType;
|
|
29
|
+
/**
|
|
30
|
+
* @generated from protobuf field: optional string errorClassName = 5;
|
|
31
|
+
*/
|
|
32
|
+
errorClassName?: string;
|
|
33
|
+
/**
|
|
34
|
+
* @generated from protobuf field: optional string errorCode = 6;
|
|
35
|
+
*/
|
|
36
|
+
errorCode?: string;
|
|
37
|
+
/**
|
|
38
|
+
* @generated from protobuf field: optional string errorMessage = 7;
|
|
39
|
+
*/
|
|
40
|
+
errorMessage?: string;
|
|
41
|
+
}
|
|
42
|
+
// Dummy message to force the generation of the typescript class "google.prototype.Empty"
|
|
43
|
+
// We need this generated class in RpcCommunicator
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @generated from protobuf message protorpc.Mnfo2uhnf92hvqi2nviouq2hv9puhq
|
|
47
|
+
*/
|
|
48
|
+
export interface Mnfo2uhnf92hvqi2nviouq2hv9puhq {
|
|
49
|
+
/**
|
|
50
|
+
* @generated from protobuf field: google.protobuf.Empty empty = 1;
|
|
51
|
+
*/
|
|
52
|
+
empty?: Empty;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* @generated from protobuf enum protorpc.RpcErrorType
|
|
56
|
+
*/
|
|
57
|
+
export enum RpcErrorType {
|
|
58
|
+
/**
|
|
59
|
+
* @generated from protobuf enum value: SERVER_TIMEOUT = 0;
|
|
60
|
+
*/
|
|
61
|
+
SERVER_TIMEOUT = 0,
|
|
62
|
+
/**
|
|
63
|
+
* @generated from protobuf enum value: CLIENT_TIMEOUT = 1;
|
|
64
|
+
*/
|
|
65
|
+
CLIENT_TIMEOUT = 1,
|
|
66
|
+
/**
|
|
67
|
+
* @generated from protobuf enum value: UNKNOWN_RPC_METHOD = 2;
|
|
68
|
+
*/
|
|
69
|
+
UNKNOWN_RPC_METHOD = 2,
|
|
70
|
+
/**
|
|
71
|
+
* @generated from protobuf enum value: CLIENT_ERROR = 3;
|
|
72
|
+
*/
|
|
73
|
+
CLIENT_ERROR = 3,
|
|
74
|
+
/**
|
|
75
|
+
* @generated from protobuf enum value: SERVER_ERROR = 4;
|
|
76
|
+
*/
|
|
77
|
+
SERVER_ERROR = 4
|
|
78
|
+
}
|
|
79
|
+
// @generated message type with reflection information, may provide speed optimized methods
|
|
80
|
+
class RpcMessage$Type extends MessageType<RpcMessage> {
|
|
81
|
+
constructor() {
|
|
82
|
+
super("protorpc.RpcMessage", [
|
|
83
|
+
{ no: 1, name: "header", kind: "map", K: 9 /*ScalarType.STRING*/, V: { kind: "scalar", T: 9 /*ScalarType.STRING*/ } },
|
|
84
|
+
{ no: 2, name: "body", kind: "message", T: () => Any },
|
|
85
|
+
{ no: 3, name: "requestId", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
|
|
86
|
+
{ no: 4, name: "errorType", kind: "enum", opt: true, T: () => ["protorpc.RpcErrorType", RpcErrorType] },
|
|
87
|
+
{ no: 5, name: "errorClassName", kind: "scalar", opt: true, T: 9 /*ScalarType.STRING*/ },
|
|
88
|
+
{ no: 6, name: "errorCode", kind: "scalar", opt: true, T: 9 /*ScalarType.STRING*/ },
|
|
89
|
+
{ no: 7, name: "errorMessage", kind: "scalar", opt: true, T: 9 /*ScalarType.STRING*/ }
|
|
90
|
+
]);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* @generated MessageType for protobuf message protorpc.RpcMessage
|
|
95
|
+
*/
|
|
96
|
+
export const RpcMessage = new RpcMessage$Type();
|
|
97
|
+
// @generated message type with reflection information, may provide speed optimized methods
|
|
98
|
+
class Mnfo2uhnf92hvqi2nviouq2hv9puhq$Type extends MessageType<Mnfo2uhnf92hvqi2nviouq2hv9puhq> {
|
|
99
|
+
constructor() {
|
|
100
|
+
super("protorpc.Mnfo2uhnf92hvqi2nviouq2hv9puhq", [
|
|
101
|
+
{ no: 1, name: "empty", kind: "message", T: () => Empty }
|
|
102
|
+
]);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* @generated MessageType for protobuf message protorpc.Mnfo2uhnf92hvqi2nviouq2hv9puhq
|
|
107
|
+
*/
|
|
108
|
+
export const Mnfo2uhnf92hvqi2nviouq2hv9puhq = new Mnfo2uhnf92hvqi2nviouq2hv9puhq$Type();
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// @generated by protobuf-ts 2.8.0 with parameter server_generic,generate_dependencies
|
|
2
|
+
// @generated from protobuf file "tests.proto" (package "tests", syntax proto3)
|
|
3
|
+
// tslint:disable
|
|
4
|
+
import { MessageType } from "@protobuf-ts/runtime";
|
|
5
|
+
import { Any } from "./google/protobuf/any";
|
|
6
|
+
/**
|
|
7
|
+
* @generated from protobuf message tests.TestMessage
|
|
8
|
+
*/
|
|
9
|
+
export interface TestMessage {
|
|
10
|
+
/**
|
|
11
|
+
* @generated from protobuf field: string messageId = 1;
|
|
12
|
+
*/
|
|
13
|
+
messageId: string;
|
|
14
|
+
/**
|
|
15
|
+
* @generated from protobuf field: google.protobuf.Any body = 2;
|
|
16
|
+
*/
|
|
17
|
+
body?: Any;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @generated from protobuf message tests.SomeMessage
|
|
21
|
+
*/
|
|
22
|
+
export interface SomeMessage {
|
|
23
|
+
/**
|
|
24
|
+
* @generated from protobuf field: string juttu = 1;
|
|
25
|
+
*/
|
|
26
|
+
juttu: string;
|
|
27
|
+
}
|
|
28
|
+
// @generated message type with reflection information, may provide speed optimized methods
|
|
29
|
+
class TestMessage$Type extends MessageType<TestMessage> {
|
|
30
|
+
constructor() {
|
|
31
|
+
super("tests.TestMessage", [
|
|
32
|
+
{ no: 1, name: "messageId", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
|
|
33
|
+
{ no: 2, name: "body", kind: "message", T: () => Any }
|
|
34
|
+
]);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* @generated MessageType for protobuf message tests.TestMessage
|
|
39
|
+
*/
|
|
40
|
+
export const TestMessage = new TestMessage$Type();
|
|
41
|
+
// @generated message type with reflection information, may provide speed optimized methods
|
|
42
|
+
class SomeMessage$Type extends MessageType<SomeMessage> {
|
|
43
|
+
constructor() {
|
|
44
|
+
super("tests.SomeMessage", [
|
|
45
|
+
{ no: 1, name: "juttu", kind: "scalar", T: 9 /*ScalarType.STRING*/ }
|
|
46
|
+
]);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* @generated MessageType for protobuf message tests.SomeMessage
|
|
51
|
+
*/
|
|
52
|
+
export const SomeMessage = new SomeMessage$Type();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ProtoCallContext } from '@streamr/proto-rpc'
|
|
2
|
+
import { PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc'
|
|
3
|
+
import { DhtRpcOptions } from './DhtRpcOptions'
|
|
4
|
+
|
|
5
|
+
export class DhtCallContext extends ProtoCallContext implements DhtRpcOptions {
|
|
6
|
+
// used by client
|
|
7
|
+
targetDescriptor?: PeerDescriptor
|
|
8
|
+
sourceDescriptor?: PeerDescriptor
|
|
9
|
+
notification?: boolean
|
|
10
|
+
clientId?: number
|
|
11
|
+
doNotConnect?: boolean
|
|
12
|
+
//used in incoming calls
|
|
13
|
+
incomingTargetDescriptor?: PeerDescriptor
|
|
14
|
+
incomingSourceDescriptor?: PeerDescriptor
|
|
15
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ProtoRpcOptions } from '@streamr/proto-rpc'
|
|
2
|
+
import { PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc'
|
|
3
|
+
|
|
4
|
+
export interface DhtRpcOptions extends ProtoRpcOptions {
|
|
5
|
+
targetDescriptor?: PeerDescriptor
|
|
6
|
+
sourceDescriptor?: PeerDescriptor
|
|
7
|
+
clientId?: number
|
|
8
|
+
doNotConnect?: boolean
|
|
9
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Message, PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc'
|
|
2
|
+
|
|
3
|
+
export type DisconnectionType = 'OUTGOING_GRACEFUL_DISCONNECT' | 'OUTGOING_GRACEFUL_LEAVE' |
|
|
4
|
+
'INCOMING_GRACEFUL_DISCONNECT' | 'INCOMING_GRACEFUL_LEAVE' | 'OTHER'
|
|
5
|
+
|
|
6
|
+
export interface TransportEvents {
|
|
7
|
+
disconnected: (peerDescriptor: PeerDescriptor, disconnectionType: DisconnectionType) => void
|
|
8
|
+
message: (message: Message) => void
|
|
9
|
+
connected: (peerDescriptor: PeerDescriptor) => void
|
|
10
|
+
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ITransport {
|
|
14
|
+
on<T extends keyof TransportEvents>(eventName: T, listener: (message: Message) => void): void
|
|
15
|
+
on<T extends keyof TransportEvents>(eventName: T, listener: (peerDescriptor: PeerDescriptor) => void): void
|
|
16
|
+
on<T extends keyof TransportEvents>(eventName: T, listener: (peerDescriptor: PeerDescriptor, disconnectionType: DisconnectionType) => void): void
|
|
17
|
+
|
|
18
|
+
once<T extends keyof TransportEvents>(eventName: T, listener: (message: Message) => void): void
|
|
19
|
+
once<T extends keyof TransportEvents>(eventName: T, listener: (peerDescriptor: PeerDescriptor) => void): void
|
|
20
|
+
once<T extends keyof TransportEvents>(eventName: T, listener: (peerDescriptor: PeerDescriptor,
|
|
21
|
+
disconnectionType: DisconnectionType) => void): void
|
|
22
|
+
|
|
23
|
+
off<T extends keyof TransportEvents>(eventName: T, listener: (message: Message) => void): void
|
|
24
|
+
off<T extends keyof TransportEvents>(eventName: T, listener: (peerDescriptor: PeerDescriptor) => void): void
|
|
25
|
+
off<T extends keyof TransportEvents>(eventName: T, listener: (peerDescriptor: PeerDescriptor, disconnectionType: DisconnectionType) => void): void
|
|
26
|
+
|
|
27
|
+
send(msg: Message, doNotConnect?: boolean): Promise<void>
|
|
28
|
+
getPeerDescriptor(): PeerDescriptor
|
|
29
|
+
getAllConnectionPeerDescriptors(): PeerDescriptor[]
|
|
30
|
+
stop(): void | Promise<void>
|
|
31
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ITransport } from './ITransport'
|
|
2
|
+
import { RoutingRpcCommunicator } from './RoutingRpcCommunicator'
|
|
3
|
+
import { RpcCommunicatorConfig } from '@streamr/proto-rpc'
|
|
4
|
+
import { Message } from '../proto/packages/dht/protos/DhtRpc'
|
|
5
|
+
|
|
6
|
+
export class ListeningRpcCommunicator extends RoutingRpcCommunicator {
|
|
7
|
+
constructor(ownServiceId: string, transport: ITransport, config?: RpcCommunicatorConfig) {
|
|
8
|
+
super(ownServiceId, transport.send, config)
|
|
9
|
+
|
|
10
|
+
transport.on('message', (msg: Message) => {
|
|
11
|
+
this.handleMessageFromPeer(msg)
|
|
12
|
+
})
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Message, MessageType, PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc'
|
|
2
|
+
import { v4 } from 'uuid'
|
|
3
|
+
import { RpcCommunicator, RpcCommunicatorConfig } from '@streamr/proto-rpc'
|
|
4
|
+
import { DhtCallContext } from '../rpc-protocol/DhtCallContext'
|
|
5
|
+
import { RpcMessage } from '../proto/packages/proto-rpc/protos/ProtoRpc'
|
|
6
|
+
|
|
7
|
+
export class RoutingRpcCommunicator extends RpcCommunicator {
|
|
8
|
+
private ownServiceId: string
|
|
9
|
+
private sendFn: (msg: Message, doNotConnect?: boolean, doNotMindStopped?: boolean) => Promise<void>
|
|
10
|
+
|
|
11
|
+
constructor(
|
|
12
|
+
ownServiceId: string,
|
|
13
|
+
sendFn: (msg: Message, doNotConnect?: boolean) => Promise<void>,
|
|
14
|
+
config?: RpcCommunicatorConfig
|
|
15
|
+
) {
|
|
16
|
+
super(config)
|
|
17
|
+
this.ownServiceId = ownServiceId
|
|
18
|
+
this.sendFn = sendFn
|
|
19
|
+
|
|
20
|
+
this.setOutgoingMessageListener((msg: RpcMessage, _requestId: string, callContext?: DhtCallContext) => {
|
|
21
|
+
let targetDescriptor: PeerDescriptor
|
|
22
|
+
// rpc call message
|
|
23
|
+
|
|
24
|
+
if (callContext!.targetDescriptor) {
|
|
25
|
+
targetDescriptor = callContext!.targetDescriptor!
|
|
26
|
+
} else { // rpc reply message
|
|
27
|
+
targetDescriptor = callContext!.incomingSourceDescriptor!
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const message: Message = {
|
|
31
|
+
messageId: v4(),
|
|
32
|
+
serviceId: this.ownServiceId,
|
|
33
|
+
body: {
|
|
34
|
+
oneofKind: 'rpcMessage',
|
|
35
|
+
rpcMessage: msg
|
|
36
|
+
},
|
|
37
|
+
messageType: MessageType.RPC,
|
|
38
|
+
targetDescriptor: targetDescriptor
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (msg.header.response || callContext && callContext.doNotConnect && callContext.doNotMindStopped ) {
|
|
42
|
+
return this.sendFn(message, true, true)
|
|
43
|
+
} else if (msg.header.response || callContext && callContext.doNotConnect) {
|
|
44
|
+
return this.sendFn(message, true)
|
|
45
|
+
} else {
|
|
46
|
+
return this.sendFn(message)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public handleMessageFromPeer(message: Message): void {
|
|
53
|
+
if (message.serviceId == this.ownServiceId && message.body.oneofKind === 'rpcMessage') {
|
|
54
|
+
const context = new DhtCallContext()
|
|
55
|
+
context.incomingSourceDescriptor = message.sourceDescriptor
|
|
56
|
+
this.handleIncomingMessage(message.body.rpcMessage, context)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'jest-extended'
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
|
|
3
|
+
import KBucket from 'k-bucket'
|
|
4
|
+
import { range } from 'lodash'
|
|
5
|
+
|
|
6
|
+
const compareIds = (id1: Uint8Array, id2: Uint8Array) => {
|
|
7
|
+
const sorted = [id1, id2].sort()
|
|
8
|
+
return KBucket.distance(sorted[0], sorted[1])
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const generateIDs = (count: number): Uint8Array[] => {
|
|
12
|
+
return range(count).map((i) => new Uint8Array([i, 1, 1]))
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const count = 9
|
|
16
|
+
const ids = generateIDs(count)
|
|
17
|
+
|
|
18
|
+
const distances = ids.map((id1) => ids.map((id2) => {
|
|
19
|
+
return {
|
|
20
|
+
distance: compareIds(id1, id2),
|
|
21
|
+
id: id2.toString()
|
|
22
|
+
}
|
|
23
|
+
}))
|
|
24
|
+
|
|
25
|
+
const graph: any[] = []
|
|
26
|
+
for (let i = 0; i < count; i++) {
|
|
27
|
+
const sorted = distances[i].sort((a, b) => a.distance - b.distance)
|
|
28
|
+
graph.push([sorted[1], sorted[2], sorted[3], sorted[4]])
|
|
29
|
+
}
|
|
30
|
+
const result = new Map<string, number>()
|
|
31
|
+
ids.forEach((key) => {
|
|
32
|
+
result.set(key.toString(), 0)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
for (let i = 0; i < count; i++) {
|
|
36
|
+
graph[i].forEach((val: any) => {
|
|
37
|
+
result.set(val.id, result.get(val.id)! + 1)
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const bidirectional = ids.map((id, i) => {
|
|
42
|
+
const stringId = id.toString()
|
|
43
|
+
const allFound = graph[i].some((obj: any) => {
|
|
44
|
+
const neighborId = obj.id
|
|
45
|
+
const neighborIndex = parseInt(neighborId.split(',')[0])
|
|
46
|
+
return graph[neighborIndex].some((obj: any) => obj.id === stringId)
|
|
47
|
+
})
|
|
48
|
+
return allFound
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
console.log(bidirectional)
|
|
52
|
+
console.log(graph)
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { Simulator } from '../../src/connection/Simulator/Simulator'
|
|
3
|
+
import { DhtNode } from '../../src/dht/DhtNode'
|
|
4
|
+
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
5
|
+
import { createMockConnectionDhtNode } from '../utils/utils'
|
|
6
|
+
import { execSync } from 'child_process'
|
|
7
|
+
import fs from 'fs'
|
|
8
|
+
|
|
9
|
+
describe('Kademlia correctness', () => {
|
|
10
|
+
let entryPoint: DhtNode
|
|
11
|
+
let nodes: DhtNode[]
|
|
12
|
+
let entrypointDescriptor: PeerDescriptor
|
|
13
|
+
const simulator = new Simulator()
|
|
14
|
+
const NUM_NODES = 1000
|
|
15
|
+
|
|
16
|
+
const nodeIndicesById: Record<string, number> = {}
|
|
17
|
+
|
|
18
|
+
if (!fs.existsSync('test/data/nodeids.json')) {
|
|
19
|
+
console.log('gound truth data does not exist yet, generating..')
|
|
20
|
+
execSync('npm run prepare-kademlia-simulation')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const dhtIds: Array<{ type: string, data: Array<number> }> = JSON.parse(fs.readFileSync('test/data/nodeids.json').toString())
|
|
24
|
+
const groundTruth: Record<string, Array<{ name: string, distance: number, id: { type: string, data: Array<number> } }>>
|
|
25
|
+
= JSON.parse(fs.readFileSync('test/data/orderedneighbors.json').toString())
|
|
26
|
+
|
|
27
|
+
beforeEach(async () => {
|
|
28
|
+
|
|
29
|
+
nodes = []
|
|
30
|
+
const entryPointId = '0'
|
|
31
|
+
entryPoint = await createMockConnectionDhtNode(entryPointId, simulator, Uint8Array.from(dhtIds[0].data), 8)
|
|
32
|
+
nodes.push(entryPoint)
|
|
33
|
+
nodeIndicesById[entryPoint.getNodeId().toKey()] = 0
|
|
34
|
+
entrypointDescriptor = {
|
|
35
|
+
kademliaId: entryPoint.getNodeId().value,
|
|
36
|
+
type: NodeType.NODEJS
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
for (let i = 1; i < NUM_NODES; i++) {
|
|
40
|
+
const nodeId = `${i}`
|
|
41
|
+
|
|
42
|
+
const node = await createMockConnectionDhtNode(nodeId, simulator, Uint8Array.from(dhtIds[i].data))
|
|
43
|
+
nodeIndicesById[node.getNodeId().toKey()] = i
|
|
44
|
+
nodes.push(node)
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
afterEach(async () => {
|
|
49
|
+
await Promise.all([
|
|
50
|
+
entryPoint.stop(),
|
|
51
|
+
...nodes.map(async (node) => await node.stop())
|
|
52
|
+
])
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('Can find correct neighbors', async () => {
|
|
56
|
+
await entryPoint.joinDht([entrypointDescriptor])
|
|
57
|
+
|
|
58
|
+
await Promise.allSettled(
|
|
59
|
+
nodes.map((node) => node.joinDht([entrypointDescriptor]))
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
let minimumCorrectNeighbors = Number.MAX_SAFE_INTEGER
|
|
63
|
+
let sumCorrectNeighbors = 0
|
|
64
|
+
let sumKbucketSize = 1
|
|
65
|
+
|
|
66
|
+
for (let i = nodes.length - 1; i >= 0; i--) {
|
|
67
|
+
let groundTruthString = 'groundTruthNeighb: '
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/prefer-for-of
|
|
69
|
+
for (let j = 0; j < groundTruth[i + ''].length; j++) {
|
|
70
|
+
groundTruthString += groundTruth[i + ''][j].name + ','
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const kademliaNeighbors = nodes[i].getNeighborList().getContactIds()
|
|
74
|
+
|
|
75
|
+
let kadString = 'kademliaNeighbors: '
|
|
76
|
+
kademliaNeighbors.forEach((neighbor) => {
|
|
77
|
+
kadString += nodeIndicesById[neighbor.toKey()] + ','
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
let correctNeighbors = 0
|
|
81
|
+
try {
|
|
82
|
+
for (let j = 0; j < groundTruth[i + ''].length; j++) {
|
|
83
|
+
if (groundTruth[i + ''][j].name != (nodeIndicesById[kademliaNeighbors[j].toKey()] + '')) {
|
|
84
|
+
break
|
|
85
|
+
}
|
|
86
|
+
correctNeighbors++
|
|
87
|
+
}
|
|
88
|
+
} catch (e) {
|
|
89
|
+
console.error('Node ' + nodes[i].getNodeName() + ' had only ' + kademliaNeighbors.length + ' kademlia neighbors')
|
|
90
|
+
}
|
|
91
|
+
if (correctNeighbors === 0) {
|
|
92
|
+
console.log('No correct neighbors found for node ' + i)
|
|
93
|
+
console.log(groundTruthString)
|
|
94
|
+
console.log(kadString)
|
|
95
|
+
}
|
|
96
|
+
if (correctNeighbors < minimumCorrectNeighbors) {
|
|
97
|
+
console.log('NEW MIN', i, correctNeighbors)
|
|
98
|
+
minimumCorrectNeighbors = correctNeighbors
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (i > 0) {
|
|
102
|
+
sumKbucketSize += nodes[i].getBucketSize()
|
|
103
|
+
sumCorrectNeighbors += correctNeighbors
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const avgKbucketSize = sumKbucketSize / (NUM_NODES - 1)
|
|
108
|
+
const avgCorrectNeighbors = sumCorrectNeighbors / (NUM_NODES - 1)
|
|
109
|
+
|
|
110
|
+
console.log('----------- Simulation results ------------------')
|
|
111
|
+
console.log('Minimum correct neighbors: ' + minimumCorrectNeighbors)
|
|
112
|
+
console.log('Average correct neighbors: ' + avgCorrectNeighbors)
|
|
113
|
+
console.log('Average Kbucket size: ' + avgKbucketSize)
|
|
114
|
+
})
|
|
115
|
+
})
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { LatencyType, Simulator } from '../../src/connection/Simulator/Simulator'
|
|
3
|
+
import { DhtNode } from '../../src/dht/DhtNode'
|
|
4
|
+
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
5
|
+
import { createMockConnectionDhtNode } from '../utils/utils'
|
|
6
|
+
import { execSync } from 'child_process'
|
|
7
|
+
import fs from 'fs'
|
|
8
|
+
import { PeerID, peerIdFromPeerDescriptor } from '../../src/exports'
|
|
9
|
+
import { Logger, wait } from '@streamr/utils'
|
|
10
|
+
import { debugVars } from '../../src/helpers/debugHelpers'
|
|
11
|
+
|
|
12
|
+
const logger = new Logger(module)
|
|
13
|
+
|
|
14
|
+
describe('Recursive find correctness', () => {
|
|
15
|
+
let entryPoint: DhtNode
|
|
16
|
+
let nodes: DhtNode[]
|
|
17
|
+
let entrypointDescriptor: PeerDescriptor
|
|
18
|
+
const simulator = new Simulator(LatencyType.NONE)
|
|
19
|
+
const NUM_NODES = 1000
|
|
20
|
+
|
|
21
|
+
const nodeIndicesById: Record<string, number> = {}
|
|
22
|
+
|
|
23
|
+
if (!fs.existsSync('test/data/nodeids.json')) {
|
|
24
|
+
console.log('ground truth data does not exist yet, generating..')
|
|
25
|
+
execSync('npm run prepare-kademlia-simulation')
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const dhtIds: Array<{ type: string, data: Array<number> }> = JSON.parse(fs.readFileSync('test/data/nodeids.json').toString())
|
|
29
|
+
|
|
30
|
+
beforeEach(async () => {
|
|
31
|
+
|
|
32
|
+
nodes = []
|
|
33
|
+
const entryPointId = '0'
|
|
34
|
+
entryPoint = await createMockConnectionDhtNode(entryPointId, simulator, Uint8Array.from(dhtIds[0].data), undefined, entryPointId)
|
|
35
|
+
nodes.push(entryPoint)
|
|
36
|
+
nodeIndicesById[entryPoint.getNodeId().toKey()] = 0
|
|
37
|
+
entrypointDescriptor = {
|
|
38
|
+
kademliaId: entryPoint.getNodeId().value,
|
|
39
|
+
type: NodeType.NODEJS,
|
|
40
|
+
nodeName: entryPointId
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
for (let i = 1; i < NUM_NODES; i++) {
|
|
44
|
+
const nodeId = `${i}`
|
|
45
|
+
|
|
46
|
+
const node = await createMockConnectionDhtNode(nodeId, simulator, Uint8Array.from(dhtIds[i].data), undefined, nodeId)
|
|
47
|
+
nodeIndicesById[node.getNodeId().toKey()] = i
|
|
48
|
+
nodes.push(node)
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
afterEach(async () => {
|
|
53
|
+
await Promise.all([
|
|
54
|
+
entryPoint.stop(),
|
|
55
|
+
...nodes.map(async (node) => await node.stop())
|
|
56
|
+
])
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('Entrypoint can find a node from the network (exact match)', async () => {
|
|
60
|
+
await entryPoint.joinDht([entrypointDescriptor])
|
|
61
|
+
|
|
62
|
+
await Promise.all(
|
|
63
|
+
nodes.map((node) => node.joinDht([entrypointDescriptor]))
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
logger.info('waiting 120s')
|
|
67
|
+
debugVars['waiting'] = true
|
|
68
|
+
|
|
69
|
+
await wait(120000)
|
|
70
|
+
debugVars['waiting'] = false
|
|
71
|
+
logger.info('waiting over')
|
|
72
|
+
|
|
73
|
+
nodes.forEach((node) => logger.info(node.getNodeName() + ': connections:' +
|
|
74
|
+
node.getNumberOfConnections() + ', kbucket: ' + node.getBucketSize()
|
|
75
|
+
+ ', localLocked: ' + node.getNumberOfLocalLockedConnections()
|
|
76
|
+
+ ', remoteLocked: ' + node.getNumberOfRemoteLockedConnections()
|
|
77
|
+
+ ', weakLocked: ' + node.getNumberOfWeakLockedConnections()))
|
|
78
|
+
|
|
79
|
+
logger.info('starting recursive find')
|
|
80
|
+
const kademliaIdToFind = Uint8Array.from(dhtIds[9].data)
|
|
81
|
+
const results = await nodes[159].startRecursiveFind(kademliaIdToFind)
|
|
82
|
+
logger.info('recursive find over')
|
|
83
|
+
expect(results.closestNodes).toBeGreaterThanOrEqual(5)
|
|
84
|
+
expect(PeerID.fromValue(kademliaIdToFind).equals(peerIdFromPeerDescriptor(results.closestNodes[0])))
|
|
85
|
+
|
|
86
|
+
}, 180000)
|
|
87
|
+
})
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Logger } from '@streamr/utils'
|
|
2
|
+
import { Any } from '../../src/proto/google/protobuf/any'
|
|
3
|
+
import { SomeMessage, TestMessage } from '../../src/proto/tests'
|
|
4
|
+
|
|
5
|
+
const logger = new Logger(module)
|
|
6
|
+
|
|
7
|
+
const some: SomeMessage = SomeMessage.create({
|
|
8
|
+
juttu: 'kivaa'
|
|
9
|
+
})
|
|
10
|
+
logger.info(SomeMessage.typeName)
|
|
11
|
+
|
|
12
|
+
const message: TestMessage = TestMessage.create({
|
|
13
|
+
messageId: 'jee',
|
|
14
|
+
body: Any.pack(some, SomeMessage)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
const binary = TestMessage.toBinary(message)
|
|
18
|
+
|
|
19
|
+
const recovered = TestMessage.fromBinary(binary)
|
|
20
|
+
const jee = Any.unpack(recovered.body!, SomeMessage)
|
|
21
|
+
logger.info(JSON.stringify(jee))
|
|
22
|
+
|
|
23
|
+
logger.info(TestMessage.toJsonString(recovered, {
|
|
24
|
+
typeRegistry: [
|
|
25
|
+
TestMessage,
|
|
26
|
+
SomeMessage
|
|
27
|
+
]
|
|
28
|
+
}))
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { PeerID } from '../../../src/helpers/PeerID'
|
|
2
|
+
import type { SimulationNode } from './SimulationNode'
|
|
3
|
+
import { NodeType, PeerDescriptor } from '../../../src/proto/packages/dht/protos/DhtRpc'
|
|
4
|
+
|
|
5
|
+
export class Contact {
|
|
6
|
+
private static counter = 0
|
|
7
|
+
|
|
8
|
+
public peerId: PeerID
|
|
9
|
+
public id: Uint8Array
|
|
10
|
+
public vectorClock = 0
|
|
11
|
+
public dhtNode: SimulationNode | undefined
|
|
12
|
+
|
|
13
|
+
constructor(ownId: PeerID, dhtNode?: SimulationNode) {
|
|
14
|
+
this.peerId = ownId
|
|
15
|
+
this.vectorClock = Contact.counter++
|
|
16
|
+
this.dhtNode = dhtNode
|
|
17
|
+
this.id = ownId.value
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
getPeerDescriptor(): PeerDescriptor {
|
|
21
|
+
const peerDescriptor: PeerDescriptor = {
|
|
22
|
+
kademliaId: this.peerId.value,
|
|
23
|
+
type: NodeType.NODEJS
|
|
24
|
+
}
|
|
25
|
+
return peerDescriptor
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
getPeerId(): PeerID {
|
|
29
|
+
return this.peerId
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
}
|