Page MenuHomePhabricator

D6923.id.diff
No OneTemporary

D6923.id.diff

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/version-responders.js';
import { websiteResponder } from './responders/website-responders.js';
import { onConnection } from './socket/socket.js';
+import { tunnelbrokerPublisher } from './socket/tunnelbroker.js';
import {
multerProcessor,
multimediaUploadResponder,
@@ -170,6 +171,7 @@
}
})();
+ tunnelbrokerPublisher.connect();
server.listen(parseInt(process.env.PORT, 10) || 3000, listenAddress);
}
})();
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,37 @@
+// @flow
+
+import { getRustAPI } from 'rust-node-addon';
+
+import type { TunnelbrokerClientClass } from 'lib/types/rust-binding-types.js';
+
+class TunnelbrokerPublisher {
+ client: ?TunnelbrokerClientClass;
+
+ async connect() {
+ if (!this.client) {
+ const rustBinding = await getRustAPI();
+ const tbClientBinding = rustBinding.TunnelbrokerClient;
+ this.client = new tbClientBinding('keyserver', err => {
+ if (err) {
+ console.error('Error in Tunnelbroker publisher: ', err);
+ return;
+ }
+ });
+ }
+ console.error('Tunnelbroker client is already connected');
+ }
+
+ async publish(toDeviceId: string, payload: string): Promise<void> {
+ if (!this.client) {
+ console.error('Tunnelbroker client is not available on publish');
+ this.connect();
+ return;
+ }
+ return await this.client.publish(toDeviceId, payload);
+ }
+}
+
+const tunnelbrokerPublisher: TunnelbrokerPublisher =
+ new TunnelbrokerPublisher();
+
+export { tunnelbrokerPublisher };
diff --git a/lib/types/rust-binding-types.js b/lib/types/rust-binding-types.js
--- a/lib/types/rust-binding-types.js
+++ b/lib/types/rust-binding-types.js
@@ -25,4 +25,4 @@
+TunnelbrokerClient: Class<TunnelbrokerClientClass>,
};
-export type { RustNativeBindingAPI };
+export type { RustNativeBindingAPI, TunnelbrokerClientClass };

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 23, 1:21 AM (13 h, 27 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2566997
Default Alt Text
D6923.id.diff (2 KB)

Event Timeline