Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3342358
D6923.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D6923.id.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D6923: [keyserver] Tunnelbroker integration - Adding Tunnelbroker publisher and connector
Attached
Detach File
Event Timeline
Log In to Comment