Page MenuHomePhabricator

D7691.id27328.diff
No OneTemporary

D7691.id27328.diff

diff --git a/keyserver/package.json b/keyserver/package.json
--- a/keyserver/package.json
+++ b/keyserver/package.json
@@ -82,7 +82,8 @@
"twin-bcrypt": "^2.1.1",
"uuid": "^3.4.0",
"web": "0.0.1",
- "web-push": "^3.5.0"
+ "web-push": "^3.5.0",
+ "ws": "^8.13.0"
},
"optionalDependencies": {
"bufferutil": "^4.0.5",
diff --git a/keyserver/src/keyserver.js b/keyserver/src/keyserver.js
--- a/keyserver/src/keyserver.js
+++ b/keyserver/src/keyserver.js
@@ -25,6 +25,7 @@
} from './responders/website-responders.js';
import { webWorkerResponder } from './responders/webworker-responders.js';
import { onConnection } from './socket/socket.js';
+import { createTunnelbrokerWebsocket } from './socket/tunnelbroker.js';
import {
multerProcessor,
multimediaUploadResponder,
@@ -63,6 +64,7 @@
cluster.fork();
}
cluster.on('exit', () => cluster.fork());
+ createTunnelbrokerWebsocket();
} else {
const server = express();
expressWs(server);
diff --git a/keyserver/src/socket/tunnelbroker.js b/keyserver/src/socket/tunnelbroker.js
new file mode 100644
--- /dev/null
+++ b/keyserver/src/socket/tunnelbroker.js
@@ -0,0 +1,34 @@
+// @flow
+
+import WebSocket from 'ws';
+
+function createTunnelbrokerWebsocket() {
+ try {
+ const tunnelbrokerSocket = new WebSocket('ws://localhost:51001');
+ tunnelbrokerSocket.on('open', () => {
+ // TODO: Replace keyserver details with actual details
+ const message = {
+ type: 'sessionRequest',
+ accessToken: 'foobar',
+ deviceId: 'foo',
+ deviceType: 'keyserver',
+ };
+ console.log(
+ 'Sending message to tunnelbroker: ' + JSON.stringify(message),
+ );
+ tunnelbrokerSocket.send(JSON.stringify(message));
+ });
+
+ tunnelbrokerSocket.on('close', () => {
+ console.log('Connection to tunnelbroker closed');
+ });
+
+ tunnelbrokerSocket.on('error', (error: Error) => {
+ console.error('Tunnelbroker socket error: ' + error.message);
+ });
+ } catch (err) {
+ console.log('Failed to open connection with tunnelbroker');
+ }
+}
+
+export { createTunnelbrokerWebsocket };
diff --git a/yarn.lock b/yarn.lock
--- a/yarn.lock
+++ b/yarn.lock
@@ -24033,6 +24033,11 @@
resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.9.tgz#54fa7db29f4c7cec68b1ddd3a89de099942bb591"
integrity sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q==
+ws@^8.13.0:
+ version "8.13.0"
+ resolved "https://registry.yarnpkg.com/ws/-/ws-8.13.0.tgz#9a9fb92f93cf41512a0735c8f4dd09b8a1211cd0"
+ integrity sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==
+
ws@^8.4.2:
version "8.12.0"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.12.0.tgz#485074cc392689da78e1828a9ff23585e06cddd8"

File Metadata

Mime Type
text/plain
Expires
Mon, Nov 25, 6:48 PM (21 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2580706
Default Alt Text
D7691.id27328.diff (2 KB)

Event Timeline