@streamr/dht 0.0.1-tatum.6 → 0.0.1-tatum.8
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/dist/src/connection/ConnectionLockHandler.d.ts +1 -1
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.d.ts +10 -0
- package/dist/src/connection/{RemoteConnectionLocker.js → ConnectionLockRpcRemote.js} +21 -35
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -0
- package/dist/src/connection/ConnectionManager.d.ts +17 -41
- package/dist/src/connection/ConnectionManager.js +148 -212
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectivityChecker.js +16 -13
- package/dist/src/connection/ConnectivityChecker.js.map +1 -1
- package/dist/src/connection/ConnectorFacade.d.ts +49 -0
- package/dist/src/connection/ConnectorFacade.js +83 -0
- package/dist/src/connection/ConnectorFacade.js.map +1 -0
- package/dist/src/connection/Handshaker.d.ts +1 -2
- package/dist/src/connection/Handshaker.js +1 -4
- package/dist/src/connection/Handshaker.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +2 -6
- package/dist/src/connection/ManagedConnection.js +27 -36
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/ManagedWebRtcConnection.d.ts +1 -1
- package/dist/src/connection/ManagedWebRtcConnection.js +2 -2
- package/dist/src/connection/ManagedWebRtcConnection.js.map +1 -1
- package/dist/src/connection/Simulator/Simulator.d.ts +0 -2
- package/dist/src/connection/Simulator/Simulator.js +0 -5
- package/dist/src/connection/Simulator/Simulator.js.map +1 -1
- package/dist/src/connection/Simulator/SimulatorConnection.js +16 -13
- package/dist/src/connection/Simulator/SimulatorConnection.js.map +1 -1
- package/dist/src/connection/Simulator/SimulatorConnector.d.ts +2 -3
- package/dist/src/connection/Simulator/SimulatorConnector.js +12 -14
- package/dist/src/connection/Simulator/SimulatorConnector.js.map +1 -1
- package/dist/src/connection/Simulator/SimulatorTransport.js +6 -1
- package/dist/src/connection/Simulator/SimulatorTransport.js.map +1 -1
- package/dist/src/connection/WebRTC/NodeWebRtcConnection.d.ts +3 -1
- package/dist/src/connection/WebRTC/NodeWebRtcConnection.js +12 -12
- package/dist/src/connection/WebRTC/NodeWebRtcConnection.js.map +1 -1
- package/dist/src/connection/WebRTC/{WebRtcConnector.d.ts → WebRtcConnectorRpcLocal.d.ts} +13 -13
- package/dist/src/connection/WebRTC/{WebRtcConnector.js → WebRtcConnectorRpcLocal.js} +46 -38
- package/dist/src/connection/WebRTC/WebRtcConnectorRpcLocal.js.map +1 -0
- package/dist/src/connection/WebRTC/WebRtcConnectorRpcRemote.d.ts +11 -0
- package/dist/src/connection/WebRTC/WebRtcConnectorRpcRemote.js +55 -0
- package/dist/src/connection/WebRTC/WebRtcConnectorRpcRemote.js.map +1 -0
- package/dist/src/connection/WebRTC/iceServerAsString.d.ts +1 -1
- package/dist/src/connection/WebSocket/{WebSocketConnector.d.ts → WebSocketConnectorRpcLocal.d.ts} +21 -11
- package/dist/src/connection/WebSocket/{WebSocketConnector.js → WebSocketConnectorRpcLocal.js} +80 -59
- package/dist/src/connection/WebSocket/WebSocketConnectorRpcLocal.js.map +1 -0
- package/dist/src/connection/WebSocket/WebSocketConnectorRpcRemote.d.ts +8 -0
- package/dist/src/connection/WebSocket/{RemoteWebSocketConnector.js → WebSocketConnectorRpcRemote.js} +12 -16
- package/dist/src/connection/WebSocket/WebSocketConnectorRpcRemote.js.map +1 -0
- package/dist/src/connection/WebSocket/WebSocketServer.d.ts +11 -1
- package/dist/src/connection/WebSocket/WebSocketServer.js +15 -10
- package/dist/src/connection/WebSocket/WebSocketServer.js.map +1 -1
- package/dist/src/dht/DhtNode.d.ts +18 -55
- package/dist/src/dht/DhtNode.js +122 -145
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/{RemoteExternalApi.d.ts → ExternalApiRpcRemote.d.ts} +2 -2
- package/dist/src/dht/{RemoteExternalApi.js → ExternalApiRpcRemote.js} +5 -6
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -0
- package/dist/src/dht/{DhtPeer.d.ts → RemoteDhtNode.d.ts} +2 -3
- package/dist/src/dht/{DhtPeer.js → RemoteDhtNode.js} +21 -19
- package/dist/src/dht/RemoteDhtNode.js.map +1 -0
- package/dist/src/dht/contact/ContactList.d.ts +0 -1
- package/dist/src/dht/contact/ContactList.js +0 -3
- package/dist/src/dht/contact/ContactList.js.map +1 -1
- package/dist/src/dht/contact/RandomContactList.d.ts +0 -1
- package/dist/src/dht/contact/RandomContactList.js +0 -3
- package/dist/src/dht/contact/RandomContactList.js.map +1 -1
- package/dist/src/dht/contact/SortedContactList.d.ts +0 -3
- package/dist/src/dht/contact/SortedContactList.js +0 -9
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/discovery/DiscoverySession.d.ts +5 -7
- package/dist/src/dht/discovery/DiscoverySession.js +9 -10
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +12 -11
- package/dist/src/dht/discovery/PeerDiscovery.js +33 -37
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/find/RecursiveFindSession.d.ts +9 -10
- package/dist/src/dht/find/RecursiveFindSession.js +13 -13
- package/dist/src/dht/find/RecursiveFindSession.js.map +1 -1
- package/dist/src/dht/find/RecursiveFinder.d.ts +9 -11
- package/dist/src/dht/find/RecursiveFinder.js +35 -36
- package/dist/src/dht/find/RecursiveFinder.js.map +1 -1
- package/dist/src/dht/find/RemoteRecursiveFindSession.d.ts +1 -1
- package/dist/src/dht/find/RemoteRecursiveFindSession.js +4 -4
- package/dist/src/dht/find/RemoteRecursiveFindSession.js.map +1 -1
- package/dist/src/dht/registerExternalApiRpcMethods.d.ts +1 -1
- package/dist/src/dht/registerExternalApiRpcMethods.js +4 -3
- package/dist/src/dht/registerExternalApiRpcMethods.js.map +1 -1
- package/dist/src/dht/routing/DuplicateDetector.d.ts +1 -2
- package/dist/src/dht/routing/DuplicateDetector.js +2 -7
- package/dist/src/dht/routing/DuplicateDetector.js.map +1 -1
- package/dist/src/dht/routing/Router.d.ts +12 -15
- package/dist/src/dht/routing/Router.js +30 -33
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/{RemoteRouter.d.ts → RouterRpcRemote.d.ts} +2 -2
- package/dist/src/dht/routing/{RemoteRouter.js → RouterRpcRemote.js} +5 -5
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -0
- package/dist/src/dht/routing/RoutingSession.d.ts +3 -4
- package/dist/src/dht/routing/RoutingSession.js +6 -5
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/store/{DataStore.d.ts → StoreRpcLocal.d.ts} +6 -6
- package/dist/src/dht/store/{DataStore.js → StoreRpcLocal.js} +34 -34
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -0
- package/dist/src/dht/store/{RemoteStore.d.ts → StoreRpcRemote.d.ts} +2 -2
- package/dist/src/dht/store/{RemoteStore.js → StoreRpcRemote.js} +4 -4
- package/dist/src/dht/store/StoreRpcRemote.js.map +1 -0
- package/dist/src/exports.d.ts +2 -8
- package/dist/src/exports.js +2 -14
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/PeerID.d.ts +0 -1
- package/dist/src/helpers/PeerID.js +0 -6
- package/dist/src/helpers/PeerID.js.map +1 -1
- package/dist/src/helpers/browser/isBrowserEnvironment.d.ts +1 -0
- package/dist/src/helpers/browser/isBrowserEnvironment.js +6 -0
- package/dist/src/helpers/browser/isBrowserEnvironment.js.map +1 -0
- package/dist/src/helpers/browser/isBrowserEnvironment_override.d.ts +1 -0
- package/dist/src/helpers/browser/isBrowserEnvironment_override.js +7 -0
- package/dist/src/helpers/browser/isBrowserEnvironment_override.js.map +1 -0
- package/dist/src/helpers/kademliaId.d.ts +1 -0
- package/dist/src/helpers/kademliaId.js +14 -0
- package/dist/src/helpers/kademliaId.js.map +1 -0
- package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +1 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +3 -3
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -1
- package/dist/src/helpers/protoClasses.js +2 -2
- package/dist/src/helpers/protoClasses.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +29 -29
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +39 -39
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +49 -162
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +47 -88
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +15 -15
- package/dist/src/transport/RoutingRpcCommunicator.js +1 -0
- package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
- package/package.json +10 -9
- package/protos/DhtRpc.proto +30 -60
- package/src/connection/ConnectionLockHandler.ts +1 -1
- package/src/connection/ConnectionLockRpcRemote.ts +62 -0
- package/src/connection/ConnectionManager.ts +178 -274
- package/src/connection/ConnectivityChecker.ts +15 -12
- package/src/connection/ConnectorFacade.ts +140 -0
- package/src/connection/Handshaker.ts +0 -5
- package/src/connection/ManagedConnection.ts +26 -40
- package/src/connection/ManagedWebRtcConnection.ts +0 -2
- package/src/connection/Simulator/Simulator.ts +0 -7
- package/src/connection/Simulator/SimulatorConnection.ts +16 -13
- package/src/connection/Simulator/SimulatorConnector.ts +13 -19
- package/src/connection/Simulator/SimulatorTransport.ts +6 -1
- package/src/connection/WebRTC/NodeWebRtcConnection.ts +15 -14
- package/src/connection/WebRTC/{WebRtcConnector.ts → WebRtcConnectorRpcLocal.ts} +68 -56
- package/src/connection/WebRTC/WebRtcConnectorRpcRemote.ts +71 -0
- package/src/connection/WebRTC/iceServerAsString.ts +1 -1
- package/src/connection/WebSocket/{WebSocketConnector.ts → WebSocketConnectorRpcLocal.ts} +102 -79
- package/src/connection/WebSocket/WebSocketConnectorRpcRemote.ts +45 -0
- package/src/connection/WebSocket/WebSocketServer.ts +26 -8
- package/src/dht/DhtNode.ts +176 -203
- package/src/dht/{RemoteExternalApi.ts → ExternalApiRpcRemote.ts} +3 -4
- package/src/dht/{DhtPeer.ts → RemoteDhtNode.ts} +11 -9
- package/src/dht/contact/ContactList.ts +0 -4
- package/src/dht/contact/RandomContactList.ts +0 -4
- package/src/dht/contact/SortedContactList.ts +0 -12
- package/src/dht/discovery/DiscoverySession.ts +20 -23
- package/src/dht/discovery/PeerDiscovery.ts +47 -45
- package/src/dht/find/RecursiveFindSession.ts +21 -22
- package/src/dht/find/RecursiveFinder.ts +45 -49
- package/src/dht/find/RemoteRecursiveFindSession.ts +6 -6
- package/src/dht/registerExternalApiRpcMethods.ts +8 -5
- package/src/dht/routing/DuplicateDetector.ts +3 -10
- package/src/dht/routing/Router.ts +39 -45
- package/src/dht/routing/{RemoteRouter.ts → RouterRpcRemote.ts} +4 -4
- package/src/dht/routing/RoutingSession.ts +15 -15
- package/src/dht/store/{DataStore.ts → StoreRpcLocal.ts} +42 -42
- package/src/dht/store/{RemoteStore.ts → StoreRpcRemote.ts} +2 -2
- package/src/exports.ts +2 -8
- package/src/helpers/PeerID.ts +0 -7
- package/src/helpers/browser/isBrowserEnvironment.ts +1 -0
- package/src/helpers/browser/isBrowserEnvironment_override.ts +3 -0
- package/src/helpers/kademliaId.ts +8 -0
- package/src/helpers/peerIdFromPeerDescriptor.ts +1 -1
- package/src/helpers/protoClasses.ts +4 -4
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +54 -54
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +15 -15
- package/src/proto/packages/dht/protos/DhtRpc.ts +77 -216
- package/src/transport/RoutingRpcCommunicator.ts +1 -0
- package/test/benchmark/KademliaCorrectness.test.ts +4 -2
- package/test/benchmark/RecursiveFind.test.ts +6 -6
- package/test/end-to-end/Layer0-Layer1.test.ts +9 -9
- package/test/end-to-end/Layer0WebRTC-Layer1.test.ts +5 -5
- package/test/end-to-end/Layer0WebRTC.test.ts +5 -6
- package/test/end-to-end/Layer1-Scale-WebRTC.test.ts +13 -8
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +15 -10
- package/test/end-to-end/WebSocketConnectionRequest.test.ts +5 -5
- package/test/integration/ConnectionLocking.test.ts +32 -26
- package/test/integration/ConnectionManager.test.ts +90 -93
- package/test/integration/DhtJoinPeerDiscovery.test.ts +53 -0
- package/test/integration/DhtRpc.test.ts +4 -6
- package/test/integration/Layer1-scale.test.ts +8 -8
- package/test/integration/MigrateData.test.ts +9 -9
- package/test/integration/Mock-Layer1-Layer0.test.ts +1 -2
- package/test/integration/RecursiveFind.test.ts +5 -5
- package/test/integration/{DhtPeer.test.ts → RemoteDhtNode.test.ts} +11 -12
- package/test/integration/RouteMessage.test.ts +7 -9
- package/test/integration/{RemoteRouter.test.ts → RouterRpcRemote.test.ts} +13 -14
- package/test/integration/RpcErrors.test.ts +25 -10
- package/test/integration/ScaleDownDht.test.ts +8 -8
- package/test/integration/SimultaneousConnections.test.ts +35 -36
- package/test/integration/Store.test.ts +8 -9
- package/test/integration/StoreAndDelete.test.ts +11 -11
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +7 -7
- package/test/integration/{RemoteStore.test.ts → StoreRpcRemote.test.ts} +17 -18
- package/test/integration/WebRtcConnectionManagement.test.ts +26 -19
- package/test/integration/WebRtcConnectorRpc.test.ts +17 -32
- package/test/integration/WebSocket.test.ts +4 -2
- package/test/integration/WebSocketConnectionManagement.test.ts +30 -17
- package/test/integration/WebSocketConnectorRpc.test.ts +10 -15
- package/test/unit/DuplicateDetector.test.ts +3 -4
- package/test/unit/LocalDataStore.test.ts +6 -8
- package/test/unit/RandomContactList.test.ts +1 -1
- package/test/unit/RecursiveFinder.test.ts +13 -18
- package/test/unit/Router.test.ts +18 -21
- package/test/unit/WebSocketConnectorRpcLocal.test.ts +64 -0
- package/test/unit/WebSocketServer.test.ts +24 -12
- package/test/unit/{webrtcReplaceInternalIpWithExternalIp.ts → webrtcReplaceInternalIpWithExternalIp.test.ts} +1 -1
- package/test/utils/mock/RecursiveFinder.ts +2 -2
- package/test/utils/mock/Router.ts +9 -11
- package/test/utils/mock/Transport.ts +2 -2
- package/test/utils/utils.ts +55 -74
- package/dist/src/connection/RemoteConnectionLocker.d.ts +0 -13
- package/dist/src/connection/RemoteConnectionLocker.js.map +0 -1
- package/dist/src/connection/WebRTC/RemoteWebrtcConnector.d.ts +0 -12
- package/dist/src/connection/WebRTC/RemoteWebrtcConnector.js +0 -74
- package/dist/src/connection/WebRTC/RemoteWebrtcConnector.js.map +0 -1
- package/dist/src/connection/WebRTC/WebRtcConnector.js.map +0 -1
- package/dist/src/connection/WebSocket/RemoteWebSocketConnector.d.ts +0 -9
- package/dist/src/connection/WebSocket/RemoteWebSocketConnector.js.map +0 -1
- package/dist/src/connection/WebSocket/WebSocketConnector.js.map +0 -1
- package/dist/src/dht/DhtPeer.js.map +0 -1
- package/dist/src/dht/RemoteExternalApi.js.map +0 -1
- package/dist/src/dht/routing/RemoteRouter.js.map +0 -1
- package/dist/src/dht/store/DataStore.js.map +0 -1
- package/dist/src/dht/store/RemoteStore.js.map +0 -1
- package/dist/src/helpers/browser/isBrowser.d.ts +0 -1
- package/dist/src/helpers/browser/isBrowser.js +0 -6
- package/dist/src/helpers/browser/isBrowser.js.map +0 -1
- package/dist/src/helpers/browser/isNodeJS.d.ts +0 -1
- package/dist/src/helpers/browser/isNodeJS.js +0 -6
- package/dist/src/helpers/browser/isNodeJS.js.map +0 -1
- package/src/connection/RemoteConnectionLocker.ts +0 -84
- package/src/connection/WebRTC/RemoteWebrtcConnector.ts +0 -93
- package/src/connection/WebSocket/RemoteWebSocketConnector.ts +0 -49
- package/src/helpers/browser/isBrowser.ts +0 -1
- package/src/helpers/browser/isNodeJS.ts +0 -1
- package/test/integration/DhtWithMockConnectionLatencies.test.ts +0 -46
- package/test/integration/DhtWithMockConnections.test.ts +0 -46
- package/test/integration/DhtWithRealConnectionLatencies.test.ts +0 -47
|
@@ -16,25 +16,22 @@ export class SimulatorConnector {
|
|
|
16
16
|
|
|
17
17
|
private connectingConnections: Map<PeerIDKey, ManagedConnection> = new Map()
|
|
18
18
|
private stopped = false
|
|
19
|
-
private protocolVersion: string
|
|
20
19
|
private ownPeerDescriptor: PeerDescriptor
|
|
21
20
|
private simulator: Simulator
|
|
22
|
-
private
|
|
21
|
+
private onIncomingConnection: (connection: ManagedConnection) => boolean
|
|
23
22
|
|
|
24
23
|
constructor(
|
|
25
|
-
protocolVersion: string,
|
|
26
24
|
ownPeerDescriptor: PeerDescriptor,
|
|
27
25
|
simulator: Simulator,
|
|
28
|
-
|
|
26
|
+
onIncomingConnection: (connection: ManagedConnection) => boolean
|
|
29
27
|
) {
|
|
30
|
-
this.protocolVersion = protocolVersion
|
|
31
28
|
this.ownPeerDescriptor = ownPeerDescriptor
|
|
32
29
|
this.simulator = simulator
|
|
33
|
-
this.
|
|
30
|
+
this.onIncomingConnection = onIncomingConnection
|
|
34
31
|
}
|
|
35
32
|
|
|
36
33
|
public connect(targetPeerDescriptor: PeerDescriptor): ManagedConnection {
|
|
37
|
-
logger.trace('connect() ' +
|
|
34
|
+
logger.trace('connect() ' + keyFromPeerDescriptor(targetPeerDescriptor))
|
|
38
35
|
const peerKey = keyFromPeerDescriptor(targetPeerDescriptor)
|
|
39
36
|
const existingConnection = this.connectingConnections.get(peerKey)
|
|
40
37
|
if (existingConnection) {
|
|
@@ -43,8 +40,7 @@ export class SimulatorConnector {
|
|
|
43
40
|
|
|
44
41
|
const connection = new SimulatorConnection(this.ownPeerDescriptor, targetPeerDescriptor, ConnectionType.SIMULATOR_CLIENT, this.simulator)
|
|
45
42
|
|
|
46
|
-
const managedConnection = new ManagedConnection(this.ownPeerDescriptor,
|
|
47
|
-
ConnectionType.SIMULATOR_CLIENT, connection, undefined)
|
|
43
|
+
const managedConnection = new ManagedConnection(this.ownPeerDescriptor, ConnectionType.SIMULATOR_CLIENT, connection, undefined)
|
|
48
44
|
managedConnection.setPeerDescriptor(targetPeerDescriptor)
|
|
49
45
|
|
|
50
46
|
this.connectingConnections.set(peerKey, managedConnection)
|
|
@@ -65,25 +61,23 @@ export class SimulatorConnector {
|
|
|
65
61
|
}
|
|
66
62
|
|
|
67
63
|
public handleIncomingConnection(sourceConnection: SimulatorConnection): void {
|
|
68
|
-
logger.trace(
|
|
69
|
-
' incoming connection, stopped: ' + this.stopped)
|
|
64
|
+
logger.trace(keyFromPeerDescriptor(sourceConnection.ownPeerDescriptor) + ' incoming connection, stopped: ' + this.stopped)
|
|
70
65
|
if (this.stopped) {
|
|
71
66
|
return
|
|
72
67
|
}
|
|
73
68
|
const connection = new SimulatorConnection(this.ownPeerDescriptor,
|
|
74
69
|
sourceConnection.ownPeerDescriptor, ConnectionType.SIMULATOR_SERVER, this.simulator)
|
|
75
70
|
|
|
76
|
-
const managedConnection = new ManagedConnection(this.ownPeerDescriptor,
|
|
77
|
-
ConnectionType.SIMULATOR_SERVER, undefined, connection)
|
|
71
|
+
const managedConnection = new ManagedConnection(this.ownPeerDescriptor, ConnectionType.SIMULATOR_SERVER, undefined, connection)
|
|
78
72
|
|
|
79
|
-
logger.trace('connected
|
|
73
|
+
logger.trace('connected')
|
|
80
74
|
|
|
81
|
-
managedConnection.once('handshakeRequest', (
|
|
82
|
-
logger.trace(
|
|
83
|
-
logger.trace('incoming handshake request
|
|
75
|
+
managedConnection.once('handshakeRequest', () => {
|
|
76
|
+
logger.trace(keyFromPeerDescriptor(sourceConnection.ownPeerDescriptor) + ' incoming handshake request')
|
|
77
|
+
logger.trace('incoming handshake request')
|
|
84
78
|
|
|
85
|
-
if (this.
|
|
86
|
-
logger.trace(
|
|
79
|
+
if (this.onIncomingConnection(managedConnection)) {
|
|
80
|
+
logger.trace(keyFromPeerDescriptor(sourceConnection.ownPeerDescriptor) + ' calling acceptHandshake')
|
|
87
81
|
managedConnection.acceptHandshake()
|
|
88
82
|
} else {
|
|
89
83
|
managedConnection.rejectHandshake('Duplicate connection')
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import { MetricsContext } from '@streamr/utils'
|
|
1
2
|
import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
|
|
2
3
|
import { ConnectionManager } from '../ConnectionManager'
|
|
3
4
|
import { Simulator } from './Simulator'
|
|
5
|
+
import { SimulatorConnectorFacade } from '../ConnectorFacade'
|
|
4
6
|
|
|
5
7
|
export class SimulatorTransport extends ConnectionManager {
|
|
6
8
|
constructor(ownPeerDescriptor: PeerDescriptor, simulator: Simulator) {
|
|
7
|
-
super({
|
|
9
|
+
super({
|
|
10
|
+
createConnectorFacade: () => new SimulatorConnectorFacade(ownPeerDescriptor, simulator),
|
|
11
|
+
metricsContext: new MetricsContext()
|
|
12
|
+
})
|
|
8
13
|
}
|
|
9
14
|
}
|
|
@@ -8,13 +8,11 @@ import { IllegalRTCPeerConnectionState } from '../../helpers/errors'
|
|
|
8
8
|
import { keyFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
9
9
|
import { DisconnectionType } from '../../transport/ITransport'
|
|
10
10
|
import { iceServerAsString } from './iceServerAsString'
|
|
11
|
-
import { IceServer } from './
|
|
11
|
+
import { IceServer } from './WebRtcConnectorRpcLocal'
|
|
12
12
|
import { PortRange } from '../ConnectionManager'
|
|
13
13
|
|
|
14
14
|
const logger = new Logger(module)
|
|
15
15
|
|
|
16
|
-
const MAX_MESSAGE_SIZE = 1048576
|
|
17
|
-
|
|
18
16
|
export const WEB_RTC_CLEANUP = new class {
|
|
19
17
|
// eslint-disable-next-line class-methods-use-this
|
|
20
18
|
cleanUp(): void {
|
|
@@ -27,6 +25,7 @@ export interface Params {
|
|
|
27
25
|
bufferThresholdHigh?: number
|
|
28
26
|
bufferThresholdLow?: number
|
|
29
27
|
connectingTimeout?: number
|
|
28
|
+
maxMessageSize?: number
|
|
30
29
|
iceServers?: IceServer[]
|
|
31
30
|
portRange?: PortRange
|
|
32
31
|
}
|
|
@@ -65,27 +64,29 @@ export class NodeWebRtcConnection extends EventEmitter<Events> implements IConne
|
|
|
65
64
|
private readonly connectingTimeout: number
|
|
66
65
|
private readonly remotePeerDescriptor: PeerDescriptor
|
|
67
66
|
private readonly portRange?: PortRange
|
|
67
|
+
private readonly maxMessageSize?: number
|
|
68
68
|
private closed = false
|
|
69
69
|
|
|
70
70
|
constructor(params: Params) {
|
|
71
71
|
super()
|
|
72
72
|
this.connectionId = new ConnectionID()
|
|
73
|
-
this.iceServers = params.iceServers
|
|
73
|
+
this.iceServers = params.iceServers ?? []
|
|
74
74
|
// eslint-disable-next-line no-underscore-dangle
|
|
75
|
-
this._bufferThresholdHigh = params.bufferThresholdHigh
|
|
76
|
-
this.bufferThresholdLow = params.bufferThresholdLow
|
|
77
|
-
this.connectingTimeout = params.connectingTimeout
|
|
75
|
+
this._bufferThresholdHigh = params.bufferThresholdHigh ?? 2 ** 17
|
|
76
|
+
this.bufferThresholdLow = params.bufferThresholdLow ?? 2 ** 15
|
|
77
|
+
this.connectingTimeout = params.connectingTimeout ?? 20000
|
|
78
78
|
this.remotePeerDescriptor = params.remotePeerDescriptor
|
|
79
|
+
this.maxMessageSize = params.maxMessageSize ?? 1048576
|
|
79
80
|
this.portRange = params.portRange
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
public start(isOffering: boolean): void {
|
|
83
|
-
logger.trace(`Staring new connection for peer: ${this.remotePeerDescriptor
|
|
84
|
-
const
|
|
85
|
-
logger.trace(`Staring new connection for peer: ${
|
|
86
|
-
this.connection = new PeerConnection(
|
|
84
|
+
logger.trace(`Staring new connection for peer: ${keyFromPeerDescriptor(this.remotePeerDescriptor)}`)
|
|
85
|
+
const peerIdKey = keyFromPeerDescriptor(this.remotePeerDescriptor)
|
|
86
|
+
logger.trace(`Staring new connection for peer: ${peerIdKey} offering: ${isOffering}`)
|
|
87
|
+
this.connection = new PeerConnection(peerIdKey, {
|
|
87
88
|
iceServers: this.iceServers.map(iceServerAsString),
|
|
88
|
-
maxMessageSize:
|
|
89
|
+
maxMessageSize: this.maxMessageSize,
|
|
89
90
|
portRangeBegin: this.portRange?.min,
|
|
90
91
|
portRangeEnd: this.portRange?.max,
|
|
91
92
|
})
|
|
@@ -96,7 +97,7 @@ export class NodeWebRtcConnection extends EventEmitter<Events> implements IConne
|
|
|
96
97
|
}, this.connectingTimeout)
|
|
97
98
|
|
|
98
99
|
this.connection.onStateChange((state: string) => this.onStateChange(state))
|
|
99
|
-
this.connection.onGatheringStateChange((
|
|
100
|
+
this.connection.onGatheringStateChange(() => {})
|
|
100
101
|
|
|
101
102
|
this.connection.onLocalDescription((description: string, type: DescriptionType) => {
|
|
102
103
|
this.emit('localDescription', description, type.toString())
|
|
@@ -232,7 +233,7 @@ export class NodeWebRtcConnection extends EventEmitter<Events> implements IConne
|
|
|
232
233
|
clearTimeout(this.connectingTimeoutRef)
|
|
233
234
|
}
|
|
234
235
|
this.dataChannel = dataChannel
|
|
235
|
-
logger.trace(`DataChannel opened for peer ${this.remotePeerDescriptor
|
|
236
|
+
logger.trace(`DataChannel opened for peer ${keyFromPeerDescriptor(this.remotePeerDescriptor)}`)
|
|
236
237
|
this.emit('connected')
|
|
237
238
|
}
|
|
238
239
|
|
|
@@ -8,23 +8,24 @@ import { Empty } from '../../proto/google/protobuf/empty'
|
|
|
8
8
|
import { ITransport } from '../../transport/ITransport'
|
|
9
9
|
import { ListeningRpcCommunicator } from '../../transport/ListeningRpcCommunicator'
|
|
10
10
|
import { NodeWebRtcConnection } from './NodeWebRtcConnection'
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
11
|
+
import { WebRtcConnectorRpcRemote } from './WebRtcConnectorRpcRemote'
|
|
12
|
+
import { WebRtcConnectorRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
|
|
13
13
|
import { PeerIDKey } from '../../helpers/PeerID'
|
|
14
14
|
import { ManagedWebRtcConnection } from '../ManagedWebRtcConnection'
|
|
15
15
|
import { Logger } from '@streamr/utils'
|
|
16
16
|
import * as Err from '../../helpers/errors'
|
|
17
|
-
import {
|
|
18
|
-
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
17
|
+
import { IWebRtcConnectorRpc } from '../../proto/packages/dht/protos/DhtRpc.server'
|
|
19
18
|
import { ManagedConnection } from '../ManagedConnection'
|
|
20
19
|
import { toProtoRpcClient } from '@streamr/proto-rpc'
|
|
21
20
|
import {
|
|
22
|
-
|
|
21
|
+
areEqualPeerDescriptors,
|
|
23
22
|
keyFromPeerDescriptor,
|
|
24
23
|
peerIdFromPeerDescriptor
|
|
25
24
|
} from '../../helpers/peerIdFromPeerDescriptor'
|
|
26
25
|
import { getAddressFromIceCandidate, isPrivateIPv4 } from '../../helpers/AddressTools'
|
|
27
26
|
import { PortRange } from '../ConnectionManager'
|
|
27
|
+
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
28
|
+
import { DhtCallContext } from '../../rpc-protocol/DhtCallContext'
|
|
28
29
|
|
|
29
30
|
const logger = new Logger(module)
|
|
30
31
|
|
|
@@ -37,13 +38,13 @@ export const replaceInternalIpWithExternalIp = (candidate: string, ip: string):
|
|
|
37
38
|
return parsed.join(' ')
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
export interface
|
|
41
|
-
|
|
42
|
-
protocolVersion: string
|
|
41
|
+
export interface WebRtcConnectorRpcLocalConfig {
|
|
42
|
+
transport: ITransport
|
|
43
43
|
iceServers?: IceServer[]
|
|
44
44
|
allowPrivateAddresses?: boolean
|
|
45
45
|
bufferThresholdLow?: number
|
|
46
46
|
bufferThresholdHigh?: number
|
|
47
|
+
maxMessageSize?: number
|
|
47
48
|
connectionTimeout?: number
|
|
48
49
|
externalIp?: string
|
|
49
50
|
portRange?: PortRange
|
|
@@ -57,45 +58,46 @@ export interface IceServer {
|
|
|
57
58
|
tcp?: boolean
|
|
58
59
|
}
|
|
59
60
|
|
|
60
|
-
export class
|
|
61
|
-
|
|
61
|
+
export class WebRtcConnectorRpcLocal implements IWebRtcConnectorRpc {
|
|
62
|
+
|
|
63
|
+
private static readonly WEBRTC_CONNECTOR_SERVICE_ID = 'system/webrtc-connector'
|
|
62
64
|
private readonly rpcCommunicator: ListeningRpcCommunicator
|
|
63
65
|
private readonly ongoingConnectAttempts: Map<PeerIDKey, ManagedWebRtcConnection> = new Map()
|
|
64
66
|
private ownPeerDescriptor?: PeerDescriptor
|
|
65
67
|
private stopped = false
|
|
66
68
|
private iceServers: IceServer[]
|
|
67
69
|
private allowPrivateAddresses: boolean
|
|
68
|
-
private config:
|
|
69
|
-
private
|
|
70
|
+
private config: WebRtcConnectorRpcLocalConfig
|
|
71
|
+
private onIncomingConnection: (connection: ManagedConnection) => boolean
|
|
70
72
|
|
|
71
73
|
constructor(
|
|
72
|
-
config:
|
|
73
|
-
|
|
74
|
+
config: WebRtcConnectorRpcLocalConfig,
|
|
75
|
+
onIncomingConnection: (connection: ManagedConnection) => boolean
|
|
74
76
|
) {
|
|
75
77
|
this.config = config
|
|
76
78
|
this.iceServers = config.iceServers || []
|
|
77
79
|
this.allowPrivateAddresses = config.allowPrivateAddresses || true
|
|
78
|
-
this.
|
|
80
|
+
this.onIncomingConnection = onIncomingConnection
|
|
79
81
|
|
|
80
|
-
this.rpcCommunicator = new ListeningRpcCommunicator(
|
|
82
|
+
this.rpcCommunicator = new ListeningRpcCommunicator(WebRtcConnectorRpcLocal.WEBRTC_CONNECTOR_SERVICE_ID, config.transport, {
|
|
81
83
|
rpcRequestTimeout: 15000
|
|
82
84
|
})
|
|
83
85
|
this.rpcCommunicator.registerRpcNotification(RtcOffer, 'rtcOffer',
|
|
84
|
-
(req: RtcOffer, context) => this.rtcOffer(req, context))
|
|
86
|
+
(req: RtcOffer, context: ServerCallContext) => this.rtcOffer(req, context))
|
|
85
87
|
this.rpcCommunicator.registerRpcNotification(RtcAnswer, 'rtcAnswer',
|
|
86
|
-
(req: RtcAnswer, context) => this.rtcAnswer(req, context))
|
|
88
|
+
(req: RtcAnswer, context: ServerCallContext) => this.rtcAnswer(req, context))
|
|
87
89
|
this.rpcCommunicator.registerRpcNotification(IceCandidate, 'iceCandidate',
|
|
88
|
-
(req: IceCandidate, context) => this.iceCandidate(req, context))
|
|
90
|
+
(req: IceCandidate, context: ServerCallContext) => this.iceCandidate(req, context))
|
|
89
91
|
this.rpcCommunicator.registerRpcNotification(WebRtcConnectionRequest, 'requestConnection',
|
|
90
|
-
(req: WebRtcConnectionRequest, context) => this.requestConnection(req, context))
|
|
92
|
+
(req: WebRtcConnectionRequest, context: ServerCallContext) => this.requestConnection(req, context))
|
|
91
93
|
}
|
|
92
94
|
|
|
93
95
|
connect(targetPeerDescriptor: PeerDescriptor): ManagedConnection {
|
|
94
|
-
if (
|
|
96
|
+
if (areEqualPeerDescriptors(targetPeerDescriptor, this.ownPeerDescriptor!)) {
|
|
95
97
|
throw new Err.CannotConnectToSelf('Cannot open WebRTC Connection to self')
|
|
96
98
|
}
|
|
97
99
|
|
|
98
|
-
logger.trace(`Opening WebRTC connection to ${targetPeerDescriptor
|
|
100
|
+
logger.trace(`Opening WebRTC connection to ${keyFromPeerDescriptor(targetPeerDescriptor)}`)
|
|
99
101
|
|
|
100
102
|
const peerKey = keyFromPeerDescriptor(targetPeerDescriptor)
|
|
101
103
|
const existingConnection = this.ongoingConnectAttempts.get(peerKey)
|
|
@@ -103,7 +105,7 @@ export class WebRtcConnector implements IWebRtcConnectorService {
|
|
|
103
105
|
return existingConnection
|
|
104
106
|
}
|
|
105
107
|
|
|
106
|
-
const connection = new NodeWebRtcConnection({
|
|
108
|
+
const connection = new NodeWebRtcConnection({
|
|
107
109
|
remotePeerDescriptor: targetPeerDescriptor,
|
|
108
110
|
iceServers: this.iceServers,
|
|
109
111
|
bufferThresholdLow: this.config.bufferThresholdLow,
|
|
@@ -116,9 +118,9 @@ export class WebRtcConnector implements IWebRtcConnectorService {
|
|
|
116
118
|
let managedConnection: ManagedWebRtcConnection
|
|
117
119
|
|
|
118
120
|
if (offering) {
|
|
119
|
-
managedConnection = new ManagedWebRtcConnection(this.ownPeerDescriptor!,
|
|
121
|
+
managedConnection = new ManagedWebRtcConnection(this.ownPeerDescriptor!, connection)
|
|
120
122
|
} else {
|
|
121
|
-
managedConnection = new ManagedWebRtcConnection(this.ownPeerDescriptor!,
|
|
123
|
+
managedConnection = new ManagedWebRtcConnection(this.ownPeerDescriptor!, undefined, connection)
|
|
122
124
|
}
|
|
123
125
|
|
|
124
126
|
managedConnection.setPeerDescriptor(targetPeerDescriptor)
|
|
@@ -135,9 +137,10 @@ export class WebRtcConnector implements IWebRtcConnectorService {
|
|
|
135
137
|
connection.on('disconnected', delFunc)
|
|
136
138
|
managedConnection.on('handshakeCompleted', delFunc)
|
|
137
139
|
|
|
138
|
-
const remoteConnector = new
|
|
140
|
+
const remoteConnector = new WebRtcConnectorRpcRemote(
|
|
141
|
+
this.ownPeerDescriptor!,
|
|
139
142
|
targetPeerDescriptor,
|
|
140
|
-
toProtoRpcClient(new
|
|
143
|
+
toProtoRpcClient(new WebRtcConnectorRpcClient(this.rpcCommunicator.getRpcClientTransport()))
|
|
141
144
|
)
|
|
142
145
|
|
|
143
146
|
connection.on('localCandidate', (candidate: string, mid: string) => {
|
|
@@ -145,23 +148,23 @@ export class WebRtcConnector implements IWebRtcConnectorService {
|
|
|
145
148
|
candidate = replaceInternalIpWithExternalIp(candidate, this.config.externalIp)
|
|
146
149
|
logger.debug(`onLocalCandidate injected external ip ${candidate} ${mid}`)
|
|
147
150
|
}
|
|
148
|
-
remoteConnector.sendIceCandidate(
|
|
151
|
+
remoteConnector.sendIceCandidate(candidate, mid, connection.connectionId.toString())
|
|
149
152
|
})
|
|
150
153
|
|
|
151
154
|
if (offering) {
|
|
152
|
-
connection.once('localDescription', (description: string
|
|
153
|
-
remoteConnector.sendRtcOffer(
|
|
155
|
+
connection.once('localDescription', (description: string) => {
|
|
156
|
+
remoteConnector.sendRtcOffer(description, connection.connectionId.toString())
|
|
154
157
|
})
|
|
155
158
|
} else {
|
|
156
|
-
connection.once('localDescription', (description: string
|
|
157
|
-
remoteConnector.sendRtcAnswer(
|
|
159
|
+
connection.once('localDescription', (description: string) => {
|
|
160
|
+
remoteConnector.sendRtcAnswer(description, connection.connectionId.toString())
|
|
158
161
|
})
|
|
159
162
|
}
|
|
160
163
|
|
|
161
164
|
connection.start(offering)
|
|
162
165
|
|
|
163
166
|
if (!offering) {
|
|
164
|
-
remoteConnector.requestConnection(
|
|
167
|
+
remoteConnector.requestConnection(connection.connectionId.toString())
|
|
165
168
|
}
|
|
166
169
|
|
|
167
170
|
return managedConnection
|
|
@@ -171,7 +174,7 @@ export class WebRtcConnector implements IWebRtcConnectorService {
|
|
|
171
174
|
this.ownPeerDescriptor = peerDescriptor
|
|
172
175
|
}
|
|
173
176
|
|
|
174
|
-
isIceCandidateAllowed(candidate: string): boolean {
|
|
177
|
+
private isIceCandidateAllowed(candidate: string): boolean {
|
|
175
178
|
if (!this.allowPrivateAddresses) {
|
|
176
179
|
const address = getAddressFromIceCandidate(candidate)
|
|
177
180
|
if (address && isPrivateIPv4(address)) {
|
|
@@ -187,7 +190,7 @@ export class WebRtcConnector implements IWebRtcConnectorService {
|
|
|
187
190
|
description: string,
|
|
188
191
|
connectionId: string
|
|
189
192
|
): void {
|
|
190
|
-
if (this.stopped || !
|
|
193
|
+
if (this.stopped || !areEqualPeerDescriptors(targetPeer, this.ownPeerDescriptor!)) {
|
|
191
194
|
return
|
|
192
195
|
}
|
|
193
196
|
const peerKey = keyFromPeerDescriptor(remotePeer)
|
|
@@ -196,24 +199,25 @@ export class WebRtcConnector implements IWebRtcConnectorService {
|
|
|
196
199
|
|
|
197
200
|
if (!managedConnection) {
|
|
198
201
|
connection = new NodeWebRtcConnection({ remotePeerDescriptor: remotePeer })
|
|
199
|
-
managedConnection = new ManagedWebRtcConnection(this.ownPeerDescriptor!,
|
|
200
|
-
|
|
202
|
+
managedConnection = new ManagedWebRtcConnection(this.ownPeerDescriptor!, undefined, connection)
|
|
203
|
+
|
|
201
204
|
managedConnection.setPeerDescriptor(remotePeer)
|
|
202
205
|
|
|
203
206
|
this.ongoingConnectAttempts.set(peerKey, managedConnection)
|
|
204
|
-
this.
|
|
207
|
+
this.onIncomingConnection(managedConnection)
|
|
205
208
|
|
|
206
|
-
const remoteConnector = new
|
|
209
|
+
const remoteConnector = new WebRtcConnectorRpcRemote(
|
|
210
|
+
this.ownPeerDescriptor!,
|
|
207
211
|
remotePeer,
|
|
208
|
-
toProtoRpcClient(new
|
|
212
|
+
toProtoRpcClient(new WebRtcConnectorRpcClient(this.rpcCommunicator.getRpcClientTransport()))
|
|
209
213
|
)
|
|
210
214
|
|
|
211
215
|
connection.on('localCandidate', (candidate: string, mid: string) => {
|
|
212
|
-
remoteConnector.sendIceCandidate(
|
|
216
|
+
remoteConnector.sendIceCandidate(candidate, mid, connection!.connectionId.toString())
|
|
213
217
|
})
|
|
214
218
|
|
|
215
|
-
connection.once('localDescription', (description: string
|
|
216
|
-
remoteConnector.sendRtcAnswer(
|
|
219
|
+
connection.once('localDescription', (description: string) => {
|
|
220
|
+
remoteConnector.sendRtcAnswer(description, connection!.connectionId.toString())
|
|
217
221
|
})
|
|
218
222
|
|
|
219
223
|
connection.start(false)
|
|
@@ -223,7 +227,7 @@ export class WebRtcConnector implements IWebRtcConnectorService {
|
|
|
223
227
|
// Always use offerers connectionId
|
|
224
228
|
connection!.setConnectionId(connectionId)
|
|
225
229
|
connection!.setRemoteDescription(description, 'offer')
|
|
226
|
-
|
|
230
|
+
|
|
227
231
|
managedConnection.on('handshakeRequest', () => {
|
|
228
232
|
if (this.ongoingConnectAttempts.has(peerKey)) {
|
|
229
233
|
this.ongoingConnectAttempts.delete(peerKey)
|
|
@@ -238,7 +242,7 @@ export class WebRtcConnector implements IWebRtcConnectorService {
|
|
|
238
242
|
description: string,
|
|
239
243
|
connectionId: string
|
|
240
244
|
): void {
|
|
241
|
-
if (this.stopped || !
|
|
245
|
+
if (this.stopped || !areEqualPeerDescriptors(targetPeerDescriptor, this.ownPeerDescriptor!)) {
|
|
242
246
|
return
|
|
243
247
|
}
|
|
244
248
|
const peerKey = keyFromPeerDescriptor(remotePeerDescriptor)
|
|
@@ -259,7 +263,7 @@ export class WebRtcConnector implements IWebRtcConnectorService {
|
|
|
259
263
|
const managedConnection = this.connect(targetPeerDescriptor)
|
|
260
264
|
managedConnection.setPeerDescriptor(targetPeerDescriptor)
|
|
261
265
|
|
|
262
|
-
this.
|
|
266
|
+
this.onIncomingConnection(managedConnection)
|
|
263
267
|
}
|
|
264
268
|
private onRemoteCandidate(
|
|
265
269
|
remotePeerDescriptor: PeerDescriptor,
|
|
@@ -268,7 +272,7 @@ export class WebRtcConnector implements IWebRtcConnectorService {
|
|
|
268
272
|
mid: string,
|
|
269
273
|
connectionId: string
|
|
270
274
|
): void {
|
|
271
|
-
if (this.stopped || !
|
|
275
|
+
if (this.stopped || !areEqualPeerDescriptors(targetPeerDescriptor, this.ownPeerDescriptor!)) {
|
|
272
276
|
return
|
|
273
277
|
}
|
|
274
278
|
const peerKey = keyFromPeerDescriptor(remotePeerDescriptor)
|
|
@@ -290,7 +294,7 @@ export class WebRtcConnector implements IWebRtcConnectorService {
|
|
|
290
294
|
|
|
291
295
|
const attempts = Array.from(this.ongoingConnectAttempts.values())
|
|
292
296
|
await Promise.allSettled(attempts.map((conn) => conn.close('OTHER')))
|
|
293
|
-
|
|
297
|
+
|
|
294
298
|
this.rpcCommunicator.stop()
|
|
295
299
|
}
|
|
296
300
|
|
|
@@ -301,23 +305,31 @@ export class WebRtcConnector implements IWebRtcConnectorService {
|
|
|
301
305
|
}
|
|
302
306
|
|
|
303
307
|
// IWebRTCConnector implementation
|
|
304
|
-
|
|
305
|
-
|
|
308
|
+
// TODO should we read connectionId from WebRtcConnectionRequest (or remove the field)?
|
|
309
|
+
async requestConnection(_request: WebRtcConnectionRequest, context: ServerCallContext): Promise<Empty> {
|
|
310
|
+
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
311
|
+
this.onConnectionRequest(senderPeerDescriptor)
|
|
306
312
|
return {}
|
|
307
313
|
}
|
|
308
314
|
|
|
309
|
-
async rtcOffer(request: RtcOffer,
|
|
310
|
-
|
|
315
|
+
async rtcOffer(request: RtcOffer, context: ServerCallContext): Promise<Empty> {
|
|
316
|
+
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
317
|
+
const receiverPeerDescriptor = (context as DhtCallContext).incomingTargetDescriptor!
|
|
318
|
+
this.onRtcOffer(senderPeerDescriptor, receiverPeerDescriptor, request.description, request.connectionId)
|
|
311
319
|
return {}
|
|
312
320
|
}
|
|
313
321
|
|
|
314
|
-
async rtcAnswer(request: RtcAnswer,
|
|
315
|
-
|
|
322
|
+
async rtcAnswer(request: RtcAnswer, context: ServerCallContext): Promise<Empty> {
|
|
323
|
+
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
324
|
+
const receiverPeerDescriptor = (context as DhtCallContext).incomingTargetDescriptor!
|
|
325
|
+
this.onRtcAnswer(senderPeerDescriptor, receiverPeerDescriptor, request.description, request.connectionId)
|
|
316
326
|
return {}
|
|
317
327
|
}
|
|
318
328
|
|
|
319
|
-
async iceCandidate(request: IceCandidate,
|
|
320
|
-
|
|
329
|
+
async iceCandidate(request: IceCandidate, context: ServerCallContext): Promise<Empty> {
|
|
330
|
+
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
331
|
+
const receiverPeerDescriptor = (context as DhtCallContext).incomingTargetDescriptor!
|
|
332
|
+
this.onRemoteCandidate(senderPeerDescriptor, receiverPeerDescriptor, request.candidate, request.mid, request.connectionId)
|
|
321
333
|
return {}
|
|
322
334
|
}
|
|
323
335
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Remote } from '../../dht/contact/Remote'
|
|
2
|
+
import {
|
|
3
|
+
IceCandidate,
|
|
4
|
+
PeerDescriptor,
|
|
5
|
+
RtcAnswer,
|
|
6
|
+
RtcOffer,
|
|
7
|
+
WebRtcConnectionRequest
|
|
8
|
+
} from '../../proto/packages/dht/protos/DhtRpc'
|
|
9
|
+
import { IWebRtcConnectorRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
|
|
10
|
+
import { ProtoRpcClient } from '@streamr/proto-rpc'
|
|
11
|
+
import { Logger } from '@streamr/utils'
|
|
12
|
+
|
|
13
|
+
const logger = new Logger(module)
|
|
14
|
+
|
|
15
|
+
export class WebRtcConnectorRpcRemote extends Remote<IWebRtcConnectorRpcClient> {
|
|
16
|
+
|
|
17
|
+
constructor(
|
|
18
|
+
localPeerDescriptor: PeerDescriptor,
|
|
19
|
+
remotePeerDescriptor: PeerDescriptor,
|
|
20
|
+
client: ProtoRpcClient<IWebRtcConnectorRpcClient>
|
|
21
|
+
) {
|
|
22
|
+
super(localPeerDescriptor, remotePeerDescriptor, 'DUMMY', client)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
requestConnection(connectionId: string): void {
|
|
26
|
+
const request: WebRtcConnectionRequest = {
|
|
27
|
+
connectionId
|
|
28
|
+
}
|
|
29
|
+
const options = this.formDhtRpcOptions({
|
|
30
|
+
notification: true
|
|
31
|
+
})
|
|
32
|
+
this.getClient().requestConnection(request, options).catch((_e) => {
|
|
33
|
+
logger.trace('Failed to send requestConnection')
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
sendRtcOffer(description: string, connectionId: string): void {
|
|
38
|
+
const request: RtcOffer = {
|
|
39
|
+
connectionId,
|
|
40
|
+
description
|
|
41
|
+
}
|
|
42
|
+
const options = this.formDhtRpcOptions()
|
|
43
|
+
this.getClient().rtcOffer(request, options).catch((_e) => {
|
|
44
|
+
logger.trace('Failed to send rtcOffer')
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
sendRtcAnswer(description: string, connectionId: string): void {
|
|
49
|
+
const request: RtcAnswer = {
|
|
50
|
+
connectionId,
|
|
51
|
+
description
|
|
52
|
+
}
|
|
53
|
+
const options = this.formDhtRpcOptions()
|
|
54
|
+
this.getClient().rtcAnswer(request, options).catch((_e) => {
|
|
55
|
+
logger.trace('Failed to send rtcAnswer')
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
sendIceCandidate(candidate: string, mid: string, connectionId: string): void {
|
|
60
|
+
const request: IceCandidate = {
|
|
61
|
+
connectionId,
|
|
62
|
+
mid,
|
|
63
|
+
candidate
|
|
64
|
+
}
|
|
65
|
+
const options = this.formDhtRpcOptions()
|
|
66
|
+
this.getClient().iceCandidate(request, options).catch((_e) => {
|
|
67
|
+
logger.trace('Failed to send iceCandidate')
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|