@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.
Files changed (255) hide show
  1. package/dist/src/connection/ConnectionLockHandler.d.ts +1 -1
  2. package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
  3. package/dist/src/connection/ConnectionLockRpcRemote.d.ts +10 -0
  4. package/dist/src/connection/{RemoteConnectionLocker.js → ConnectionLockRpcRemote.js} +21 -35
  5. package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -0
  6. package/dist/src/connection/ConnectionManager.d.ts +17 -41
  7. package/dist/src/connection/ConnectionManager.js +148 -212
  8. package/dist/src/connection/ConnectionManager.js.map +1 -1
  9. package/dist/src/connection/ConnectivityChecker.js +16 -13
  10. package/dist/src/connection/ConnectivityChecker.js.map +1 -1
  11. package/dist/src/connection/ConnectorFacade.d.ts +49 -0
  12. package/dist/src/connection/ConnectorFacade.js +83 -0
  13. package/dist/src/connection/ConnectorFacade.js.map +1 -0
  14. package/dist/src/connection/Handshaker.d.ts +1 -2
  15. package/dist/src/connection/Handshaker.js +1 -4
  16. package/dist/src/connection/Handshaker.js.map +1 -1
  17. package/dist/src/connection/ManagedConnection.d.ts +2 -6
  18. package/dist/src/connection/ManagedConnection.js +27 -36
  19. package/dist/src/connection/ManagedConnection.js.map +1 -1
  20. package/dist/src/connection/ManagedWebRtcConnection.d.ts +1 -1
  21. package/dist/src/connection/ManagedWebRtcConnection.js +2 -2
  22. package/dist/src/connection/ManagedWebRtcConnection.js.map +1 -1
  23. package/dist/src/connection/Simulator/Simulator.d.ts +0 -2
  24. package/dist/src/connection/Simulator/Simulator.js +0 -5
  25. package/dist/src/connection/Simulator/Simulator.js.map +1 -1
  26. package/dist/src/connection/Simulator/SimulatorConnection.js +16 -13
  27. package/dist/src/connection/Simulator/SimulatorConnection.js.map +1 -1
  28. package/dist/src/connection/Simulator/SimulatorConnector.d.ts +2 -3
  29. package/dist/src/connection/Simulator/SimulatorConnector.js +12 -14
  30. package/dist/src/connection/Simulator/SimulatorConnector.js.map +1 -1
  31. package/dist/src/connection/Simulator/SimulatorTransport.js +6 -1
  32. package/dist/src/connection/Simulator/SimulatorTransport.js.map +1 -1
  33. package/dist/src/connection/WebRTC/NodeWebRtcConnection.d.ts +3 -1
  34. package/dist/src/connection/WebRTC/NodeWebRtcConnection.js +12 -12
  35. package/dist/src/connection/WebRTC/NodeWebRtcConnection.js.map +1 -1
  36. package/dist/src/connection/WebRTC/{WebRtcConnector.d.ts → WebRtcConnectorRpcLocal.d.ts} +13 -13
  37. package/dist/src/connection/WebRTC/{WebRtcConnector.js → WebRtcConnectorRpcLocal.js} +46 -38
  38. package/dist/src/connection/WebRTC/WebRtcConnectorRpcLocal.js.map +1 -0
  39. package/dist/src/connection/WebRTC/WebRtcConnectorRpcRemote.d.ts +11 -0
  40. package/dist/src/connection/WebRTC/WebRtcConnectorRpcRemote.js +55 -0
  41. package/dist/src/connection/WebRTC/WebRtcConnectorRpcRemote.js.map +1 -0
  42. package/dist/src/connection/WebRTC/iceServerAsString.d.ts +1 -1
  43. package/dist/src/connection/WebSocket/{WebSocketConnector.d.ts → WebSocketConnectorRpcLocal.d.ts} +21 -11
  44. package/dist/src/connection/WebSocket/{WebSocketConnector.js → WebSocketConnectorRpcLocal.js} +80 -59
  45. package/dist/src/connection/WebSocket/WebSocketConnectorRpcLocal.js.map +1 -0
  46. package/dist/src/connection/WebSocket/WebSocketConnectorRpcRemote.d.ts +8 -0
  47. package/dist/src/connection/WebSocket/{RemoteWebSocketConnector.js → WebSocketConnectorRpcRemote.js} +12 -16
  48. package/dist/src/connection/WebSocket/WebSocketConnectorRpcRemote.js.map +1 -0
  49. package/dist/src/connection/WebSocket/WebSocketServer.d.ts +11 -1
  50. package/dist/src/connection/WebSocket/WebSocketServer.js +15 -10
  51. package/dist/src/connection/WebSocket/WebSocketServer.js.map +1 -1
  52. package/dist/src/dht/DhtNode.d.ts +18 -55
  53. package/dist/src/dht/DhtNode.js +122 -145
  54. package/dist/src/dht/DhtNode.js.map +1 -1
  55. package/dist/src/dht/{RemoteExternalApi.d.ts → ExternalApiRpcRemote.d.ts} +2 -2
  56. package/dist/src/dht/{RemoteExternalApi.js → ExternalApiRpcRemote.js} +5 -6
  57. package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -0
  58. package/dist/src/dht/{DhtPeer.d.ts → RemoteDhtNode.d.ts} +2 -3
  59. package/dist/src/dht/{DhtPeer.js → RemoteDhtNode.js} +21 -19
  60. package/dist/src/dht/RemoteDhtNode.js.map +1 -0
  61. package/dist/src/dht/contact/ContactList.d.ts +0 -1
  62. package/dist/src/dht/contact/ContactList.js +0 -3
  63. package/dist/src/dht/contact/ContactList.js.map +1 -1
  64. package/dist/src/dht/contact/RandomContactList.d.ts +0 -1
  65. package/dist/src/dht/contact/RandomContactList.js +0 -3
  66. package/dist/src/dht/contact/RandomContactList.js.map +1 -1
  67. package/dist/src/dht/contact/SortedContactList.d.ts +0 -3
  68. package/dist/src/dht/contact/SortedContactList.js +0 -9
  69. package/dist/src/dht/contact/SortedContactList.js.map +1 -1
  70. package/dist/src/dht/discovery/DiscoverySession.d.ts +5 -7
  71. package/dist/src/dht/discovery/DiscoverySession.js +9 -10
  72. package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
  73. package/dist/src/dht/discovery/PeerDiscovery.d.ts +12 -11
  74. package/dist/src/dht/discovery/PeerDiscovery.js +33 -37
  75. package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
  76. package/dist/src/dht/find/RecursiveFindSession.d.ts +9 -10
  77. package/dist/src/dht/find/RecursiveFindSession.js +13 -13
  78. package/dist/src/dht/find/RecursiveFindSession.js.map +1 -1
  79. package/dist/src/dht/find/RecursiveFinder.d.ts +9 -11
  80. package/dist/src/dht/find/RecursiveFinder.js +35 -36
  81. package/dist/src/dht/find/RecursiveFinder.js.map +1 -1
  82. package/dist/src/dht/find/RemoteRecursiveFindSession.d.ts +1 -1
  83. package/dist/src/dht/find/RemoteRecursiveFindSession.js +4 -4
  84. package/dist/src/dht/find/RemoteRecursiveFindSession.js.map +1 -1
  85. package/dist/src/dht/registerExternalApiRpcMethods.d.ts +1 -1
  86. package/dist/src/dht/registerExternalApiRpcMethods.js +4 -3
  87. package/dist/src/dht/registerExternalApiRpcMethods.js.map +1 -1
  88. package/dist/src/dht/routing/DuplicateDetector.d.ts +1 -2
  89. package/dist/src/dht/routing/DuplicateDetector.js +2 -7
  90. package/dist/src/dht/routing/DuplicateDetector.js.map +1 -1
  91. package/dist/src/dht/routing/Router.d.ts +12 -15
  92. package/dist/src/dht/routing/Router.js +30 -33
  93. package/dist/src/dht/routing/Router.js.map +1 -1
  94. package/dist/src/dht/routing/{RemoteRouter.d.ts → RouterRpcRemote.d.ts} +2 -2
  95. package/dist/src/dht/routing/{RemoteRouter.js → RouterRpcRemote.js} +5 -5
  96. package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -0
  97. package/dist/src/dht/routing/RoutingSession.d.ts +3 -4
  98. package/dist/src/dht/routing/RoutingSession.js +6 -5
  99. package/dist/src/dht/routing/RoutingSession.js.map +1 -1
  100. package/dist/src/dht/store/{DataStore.d.ts → StoreRpcLocal.d.ts} +6 -6
  101. package/dist/src/dht/store/{DataStore.js → StoreRpcLocal.js} +34 -34
  102. package/dist/src/dht/store/StoreRpcLocal.js.map +1 -0
  103. package/dist/src/dht/store/{RemoteStore.d.ts → StoreRpcRemote.d.ts} +2 -2
  104. package/dist/src/dht/store/{RemoteStore.js → StoreRpcRemote.js} +4 -4
  105. package/dist/src/dht/store/StoreRpcRemote.js.map +1 -0
  106. package/dist/src/exports.d.ts +2 -8
  107. package/dist/src/exports.js +2 -14
  108. package/dist/src/exports.js.map +1 -1
  109. package/dist/src/helpers/PeerID.d.ts +0 -1
  110. package/dist/src/helpers/PeerID.js +0 -6
  111. package/dist/src/helpers/PeerID.js.map +1 -1
  112. package/dist/src/helpers/browser/isBrowserEnvironment.d.ts +1 -0
  113. package/dist/src/helpers/browser/isBrowserEnvironment.js +6 -0
  114. package/dist/src/helpers/browser/isBrowserEnvironment.js.map +1 -0
  115. package/dist/src/helpers/browser/isBrowserEnvironment_override.d.ts +1 -0
  116. package/dist/src/helpers/browser/isBrowserEnvironment_override.js +7 -0
  117. package/dist/src/helpers/browser/isBrowserEnvironment_override.js.map +1 -0
  118. package/dist/src/helpers/kademliaId.d.ts +1 -0
  119. package/dist/src/helpers/kademliaId.js +14 -0
  120. package/dist/src/helpers/kademliaId.js.map +1 -0
  121. package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +1 -1
  122. package/dist/src/helpers/peerIdFromPeerDescriptor.js +3 -3
  123. package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -1
  124. package/dist/src/helpers/protoClasses.js +2 -2
  125. package/dist/src/helpers/protoClasses.js.map +1 -1
  126. package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +29 -29
  127. package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +39 -39
  128. package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
  129. package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +49 -162
  130. package/dist/src/proto/packages/dht/protos/DhtRpc.js +47 -88
  131. package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
  132. package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +15 -15
  133. package/dist/src/transport/RoutingRpcCommunicator.js +1 -0
  134. package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
  135. package/package.json +10 -9
  136. package/protos/DhtRpc.proto +30 -60
  137. package/src/connection/ConnectionLockHandler.ts +1 -1
  138. package/src/connection/ConnectionLockRpcRemote.ts +62 -0
  139. package/src/connection/ConnectionManager.ts +178 -274
  140. package/src/connection/ConnectivityChecker.ts +15 -12
  141. package/src/connection/ConnectorFacade.ts +140 -0
  142. package/src/connection/Handshaker.ts +0 -5
  143. package/src/connection/ManagedConnection.ts +26 -40
  144. package/src/connection/ManagedWebRtcConnection.ts +0 -2
  145. package/src/connection/Simulator/Simulator.ts +0 -7
  146. package/src/connection/Simulator/SimulatorConnection.ts +16 -13
  147. package/src/connection/Simulator/SimulatorConnector.ts +13 -19
  148. package/src/connection/Simulator/SimulatorTransport.ts +6 -1
  149. package/src/connection/WebRTC/NodeWebRtcConnection.ts +15 -14
  150. package/src/connection/WebRTC/{WebRtcConnector.ts → WebRtcConnectorRpcLocal.ts} +68 -56
  151. package/src/connection/WebRTC/WebRtcConnectorRpcRemote.ts +71 -0
  152. package/src/connection/WebRTC/iceServerAsString.ts +1 -1
  153. package/src/connection/WebSocket/{WebSocketConnector.ts → WebSocketConnectorRpcLocal.ts} +102 -79
  154. package/src/connection/WebSocket/WebSocketConnectorRpcRemote.ts +45 -0
  155. package/src/connection/WebSocket/WebSocketServer.ts +26 -8
  156. package/src/dht/DhtNode.ts +176 -203
  157. package/src/dht/{RemoteExternalApi.ts → ExternalApiRpcRemote.ts} +3 -4
  158. package/src/dht/{DhtPeer.ts → RemoteDhtNode.ts} +11 -9
  159. package/src/dht/contact/ContactList.ts +0 -4
  160. package/src/dht/contact/RandomContactList.ts +0 -4
  161. package/src/dht/contact/SortedContactList.ts +0 -12
  162. package/src/dht/discovery/DiscoverySession.ts +20 -23
  163. package/src/dht/discovery/PeerDiscovery.ts +47 -45
  164. package/src/dht/find/RecursiveFindSession.ts +21 -22
  165. package/src/dht/find/RecursiveFinder.ts +45 -49
  166. package/src/dht/find/RemoteRecursiveFindSession.ts +6 -6
  167. package/src/dht/registerExternalApiRpcMethods.ts +8 -5
  168. package/src/dht/routing/DuplicateDetector.ts +3 -10
  169. package/src/dht/routing/Router.ts +39 -45
  170. package/src/dht/routing/{RemoteRouter.ts → RouterRpcRemote.ts} +4 -4
  171. package/src/dht/routing/RoutingSession.ts +15 -15
  172. package/src/dht/store/{DataStore.ts → StoreRpcLocal.ts} +42 -42
  173. package/src/dht/store/{RemoteStore.ts → StoreRpcRemote.ts} +2 -2
  174. package/src/exports.ts +2 -8
  175. package/src/helpers/PeerID.ts +0 -7
  176. package/src/helpers/browser/isBrowserEnvironment.ts +1 -0
  177. package/src/helpers/browser/isBrowserEnvironment_override.ts +3 -0
  178. package/src/helpers/kademliaId.ts +8 -0
  179. package/src/helpers/peerIdFromPeerDescriptor.ts +1 -1
  180. package/src/helpers/protoClasses.ts +4 -4
  181. package/src/proto/packages/dht/protos/DhtRpc.client.ts +54 -54
  182. package/src/proto/packages/dht/protos/DhtRpc.server.ts +15 -15
  183. package/src/proto/packages/dht/protos/DhtRpc.ts +77 -216
  184. package/src/transport/RoutingRpcCommunicator.ts +1 -0
  185. package/test/benchmark/KademliaCorrectness.test.ts +4 -2
  186. package/test/benchmark/RecursiveFind.test.ts +6 -6
  187. package/test/end-to-end/Layer0-Layer1.test.ts +9 -9
  188. package/test/end-to-end/Layer0WebRTC-Layer1.test.ts +5 -5
  189. package/test/end-to-end/Layer0WebRTC.test.ts +5 -6
  190. package/test/end-to-end/Layer1-Scale-WebRTC.test.ts +13 -8
  191. package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +15 -10
  192. package/test/end-to-end/WebSocketConnectionRequest.test.ts +5 -5
  193. package/test/integration/ConnectionLocking.test.ts +32 -26
  194. package/test/integration/ConnectionManager.test.ts +90 -93
  195. package/test/integration/DhtJoinPeerDiscovery.test.ts +53 -0
  196. package/test/integration/DhtRpc.test.ts +4 -6
  197. package/test/integration/Layer1-scale.test.ts +8 -8
  198. package/test/integration/MigrateData.test.ts +9 -9
  199. package/test/integration/Mock-Layer1-Layer0.test.ts +1 -2
  200. package/test/integration/RecursiveFind.test.ts +5 -5
  201. package/test/integration/{DhtPeer.test.ts → RemoteDhtNode.test.ts} +11 -12
  202. package/test/integration/RouteMessage.test.ts +7 -9
  203. package/test/integration/{RemoteRouter.test.ts → RouterRpcRemote.test.ts} +13 -14
  204. package/test/integration/RpcErrors.test.ts +25 -10
  205. package/test/integration/ScaleDownDht.test.ts +8 -8
  206. package/test/integration/SimultaneousConnections.test.ts +35 -36
  207. package/test/integration/Store.test.ts +8 -9
  208. package/test/integration/StoreAndDelete.test.ts +11 -11
  209. package/test/integration/StoreOnDhtWithTwoNodes.test.ts +7 -7
  210. package/test/integration/{RemoteStore.test.ts → StoreRpcRemote.test.ts} +17 -18
  211. package/test/integration/WebRtcConnectionManagement.test.ts +26 -19
  212. package/test/integration/WebRtcConnectorRpc.test.ts +17 -32
  213. package/test/integration/WebSocket.test.ts +4 -2
  214. package/test/integration/WebSocketConnectionManagement.test.ts +30 -17
  215. package/test/integration/WebSocketConnectorRpc.test.ts +10 -15
  216. package/test/unit/DuplicateDetector.test.ts +3 -4
  217. package/test/unit/LocalDataStore.test.ts +6 -8
  218. package/test/unit/RandomContactList.test.ts +1 -1
  219. package/test/unit/RecursiveFinder.test.ts +13 -18
  220. package/test/unit/Router.test.ts +18 -21
  221. package/test/unit/WebSocketConnectorRpcLocal.test.ts +64 -0
  222. package/test/unit/WebSocketServer.test.ts +24 -12
  223. package/test/unit/{webrtcReplaceInternalIpWithExternalIp.ts → webrtcReplaceInternalIpWithExternalIp.test.ts} +1 -1
  224. package/test/utils/mock/RecursiveFinder.ts +2 -2
  225. package/test/utils/mock/Router.ts +9 -11
  226. package/test/utils/mock/Transport.ts +2 -2
  227. package/test/utils/utils.ts +55 -74
  228. package/dist/src/connection/RemoteConnectionLocker.d.ts +0 -13
  229. package/dist/src/connection/RemoteConnectionLocker.js.map +0 -1
  230. package/dist/src/connection/WebRTC/RemoteWebrtcConnector.d.ts +0 -12
  231. package/dist/src/connection/WebRTC/RemoteWebrtcConnector.js +0 -74
  232. package/dist/src/connection/WebRTC/RemoteWebrtcConnector.js.map +0 -1
  233. package/dist/src/connection/WebRTC/WebRtcConnector.js.map +0 -1
  234. package/dist/src/connection/WebSocket/RemoteWebSocketConnector.d.ts +0 -9
  235. package/dist/src/connection/WebSocket/RemoteWebSocketConnector.js.map +0 -1
  236. package/dist/src/connection/WebSocket/WebSocketConnector.js.map +0 -1
  237. package/dist/src/dht/DhtPeer.js.map +0 -1
  238. package/dist/src/dht/RemoteExternalApi.js.map +0 -1
  239. package/dist/src/dht/routing/RemoteRouter.js.map +0 -1
  240. package/dist/src/dht/store/DataStore.js.map +0 -1
  241. package/dist/src/dht/store/RemoteStore.js.map +0 -1
  242. package/dist/src/helpers/browser/isBrowser.d.ts +0 -1
  243. package/dist/src/helpers/browser/isBrowser.js +0 -6
  244. package/dist/src/helpers/browser/isBrowser.js.map +0 -1
  245. package/dist/src/helpers/browser/isNodeJS.d.ts +0 -1
  246. package/dist/src/helpers/browser/isNodeJS.js +0 -6
  247. package/dist/src/helpers/browser/isNodeJS.js.map +0 -1
  248. package/src/connection/RemoteConnectionLocker.ts +0 -84
  249. package/src/connection/WebRTC/RemoteWebrtcConnector.ts +0 -93
  250. package/src/connection/WebSocket/RemoteWebSocketConnector.ts +0 -49
  251. package/src/helpers/browser/isBrowser.ts +0 -1
  252. package/src/helpers/browser/isNodeJS.ts +0 -1
  253. package/test/integration/DhtWithMockConnectionLatencies.test.ts +0 -46
  254. package/test/integration/DhtWithMockConnections.test.ts +0 -46
  255. 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 incomingConnectionCallback: (connection: ManagedConnection) => boolean
21
+ private onIncomingConnection: (connection: ManagedConnection) => boolean
23
22
 
24
23
  constructor(
25
- protocolVersion: string,
26
24
  ownPeerDescriptor: PeerDescriptor,
27
25
  simulator: Simulator,
28
- incomingConnectionCallback: (connection: ManagedConnection) => boolean
26
+ onIncomingConnection: (connection: ManagedConnection) => boolean
29
27
  ) {
30
- this.protocolVersion = protocolVersion
31
28
  this.ownPeerDescriptor = ownPeerDescriptor
32
29
  this.simulator = simulator
33
- this.incomingConnectionCallback = incomingConnectionCallback
30
+ this.onIncomingConnection = onIncomingConnection
34
31
  }
35
32
 
36
33
  public connect(targetPeerDescriptor: PeerDescriptor): ManagedConnection {
37
- logger.trace('connect() ' + this.ownPeerDescriptor.nodeName + ',' + targetPeerDescriptor.nodeName)
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, this.protocolVersion,
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(' ' + this.ownPeerDescriptor.nodeName + ', ' + sourceConnection.ownPeerDescriptor.nodeName +
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, this.protocolVersion,
77
- ConnectionType.SIMULATOR_SERVER, undefined, connection)
71
+ const managedConnection = new ManagedConnection(this.ownPeerDescriptor, ConnectionType.SIMULATOR_SERVER, undefined, connection)
78
72
 
79
- logger.trace('connected, objectId: ' + managedConnection.objectId)
73
+ logger.trace('connected')
80
74
 
81
- managedConnection.once('handshakeRequest', (_peerDescriptor: PeerDescriptor) => {
82
- logger.trace(' ' + this.ownPeerDescriptor.nodeName + ', ' + sourceConnection.ownPeerDescriptor.nodeName + ' incoming handshake request')
83
- logger.trace('incoming handshake request objectId: ' + managedConnection.objectId)
75
+ managedConnection.once('handshakeRequest', () => {
76
+ logger.trace(keyFromPeerDescriptor(sourceConnection.ownPeerDescriptor) + ' incoming handshake request')
77
+ logger.trace('incoming handshake request')
84
78
 
85
- if (this.incomingConnectionCallback(managedConnection)) {
86
- logger.trace(' ' + this.ownPeerDescriptor.nodeName + ', ' + sourceConnection.ownPeerDescriptor.nodeName + ' calling acceptHandshake')
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({ ownPeerDescriptor: ownPeerDescriptor, simulator, serviceIdPrefix: 'simulator/' })
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 './WebRtcConnector'
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 || 2 ** 17
76
- this.bufferThresholdLow = params.bufferThresholdLow || 2 ** 15
77
- this.connectingTimeout = params.connectingTimeout || 20000
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.kademliaId.toString()}`)
84
- const hexId = keyFromPeerDescriptor(this.remotePeerDescriptor)
85
- logger.trace(`Staring new connection for peer: ${hexId} offering: ${isOffering}`)
86
- this.connection = new PeerConnection(hexId, {
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: MAX_MESSAGE_SIZE,
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((_state: string) => {})
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.kademliaId.toString()}`)
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 { RemoteWebrtcConnector } from './RemoteWebrtcConnector'
12
- import { WebRtcConnectorServiceClient } from '../../proto/packages/dht/protos/DhtRpc.client'
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 { IWebRtcConnectorService } from '../../proto/packages/dht/protos/DhtRpc.server'
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
- isSamePeerDescriptor,
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 WebRtcConnectorConfig {
41
- rpcTransport: ITransport
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 WebRtcConnector implements IWebRtcConnectorService {
61
- private static readonly WEBRTC_CONNECTOR_SERVICE_ID = 'system/webrtc_connector'
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: WebRtcConnectorConfig
69
- private incomingConnectionCallback: (connection: ManagedConnection) => boolean
70
+ private config: WebRtcConnectorRpcLocalConfig
71
+ private onIncomingConnection: (connection: ManagedConnection) => boolean
70
72
 
71
73
  constructor(
72
- config: WebRtcConnectorConfig,
73
- incomingConnectionCallback: (connection: ManagedConnection) => boolean
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.incomingConnectionCallback = incomingConnectionCallback
80
+ this.onIncomingConnection = onIncomingConnection
79
81
 
80
- this.rpcCommunicator = new ListeningRpcCommunicator(WebRtcConnector.WEBRTC_CONNECTOR_SERVICE_ID, config.rpcTransport, {
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 (isSamePeerDescriptor(targetPeerDescriptor, this.ownPeerDescriptor!)) {
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.kademliaId.toString()}`)
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!, this.config.protocolVersion, connection)
121
+ managedConnection = new ManagedWebRtcConnection(this.ownPeerDescriptor!, connection)
120
122
  } else {
121
- managedConnection = new ManagedWebRtcConnection(this.ownPeerDescriptor!, this.config.protocolVersion, undefined, connection)
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 RemoteWebrtcConnector(
140
+ const remoteConnector = new WebRtcConnectorRpcRemote(
141
+ this.ownPeerDescriptor!,
139
142
  targetPeerDescriptor,
140
- toProtoRpcClient(new WebRtcConnectorServiceClient(this.rpcCommunicator.getRpcClientTransport()))
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(this.ownPeerDescriptor!, candidate, mid, connection.connectionId.toString())
151
+ remoteConnector.sendIceCandidate(candidate, mid, connection.connectionId.toString())
149
152
  })
150
153
 
151
154
  if (offering) {
152
- connection.once('localDescription', (description: string, _type: string) => {
153
- remoteConnector.sendRtcOffer(this.ownPeerDescriptor!, description, connection.connectionId.toString())
155
+ connection.once('localDescription', (description: string) => {
156
+ remoteConnector.sendRtcOffer(description, connection.connectionId.toString())
154
157
  })
155
158
  } else {
156
- connection.once('localDescription', (description: string, _type: string) => {
157
- remoteConnector.sendRtcAnswer(this.ownPeerDescriptor!, description, connection.connectionId.toString())
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(this.ownPeerDescriptor!, connection.connectionId.toString())
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 || !isSamePeerDescriptor(targetPeer, this.ownPeerDescriptor!)) {
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!, this.config.protocolVersion, undefined, connection)
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.incomingConnectionCallback(managedConnection)
207
+ this.onIncomingConnection(managedConnection)
205
208
 
206
- const remoteConnector = new RemoteWebrtcConnector(
209
+ const remoteConnector = new WebRtcConnectorRpcRemote(
210
+ this.ownPeerDescriptor!,
207
211
  remotePeer,
208
- toProtoRpcClient(new WebRtcConnectorServiceClient(this.rpcCommunicator.getRpcClientTransport()))
212
+ toProtoRpcClient(new WebRtcConnectorRpcClient(this.rpcCommunicator.getRpcClientTransport()))
209
213
  )
210
214
 
211
215
  connection.on('localCandidate', (candidate: string, mid: string) => {
212
- remoteConnector.sendIceCandidate(this.ownPeerDescriptor!, candidate, mid, connection!.connectionId.toString())
216
+ remoteConnector.sendIceCandidate(candidate, mid, connection!.connectionId.toString())
213
217
  })
214
218
 
215
- connection.once('localDescription', (description: string, _type: string) => {
216
- remoteConnector.sendRtcAnswer(this.ownPeerDescriptor!, description, connection!.connectionId.toString())
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 || !isSamePeerDescriptor(targetPeerDescriptor, this.ownPeerDescriptor!)) {
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.incomingConnectionCallback(managedConnection)
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 || !isSamePeerDescriptor(targetPeerDescriptor, this.ownPeerDescriptor!)) {
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
- async requestConnection(request: WebRtcConnectionRequest, _context: ServerCallContext): Promise<Empty> {
305
- this.onConnectionRequest(request.requester!)
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, _context: ServerCallContext): Promise<Empty> {
310
- this.onRtcOffer(request.requester!, request.target!, request.description, request.connectionId)
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, _context: ServerCallContext): Promise<Empty> {
315
- this.onRtcAnswer(request.requester!, request.target!, request.description, request.connectionId)
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, _context: ServerCallContext): Promise<Empty> {
320
- this.onRemoteCandidate(request.requester!, request.target!, request.candidate, request.mid, request.connectionId)
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
+
@@ -1,4 +1,4 @@
1
- import { IceServer } from './WebRtcConnector'
1
+ import { IceServer } from './WebRtcConnectorRpcLocal'
2
2
 
3
3
  export function iceServerAsString({ url, port, username, password, tcp }: IceServer): string {
4
4
  const [protocol, hostname] = url.split(':')