Skip to content

Commit 222fea9

Browse files
committed
Merge branch 'poljar/seshat-pr' into develop
2 parents daacd90 + e5956de commit 222fea9

5 files changed

Lines changed: 328 additions & 1 deletion

File tree

‎docs/labs.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,11 @@ improves the device verification experience by allowing you to verify a user
7373
instead of verifying each of their devices.
7474

7575
This feature is still in development and will be landing in several chunks.
76+
77+
## Event indexing and E2EE search support using Seshat (`feature_event_indexing`)
78+
79+
Adds support for search in E2E encrypted rooms. This enables an event indexer
80+
that downloads, stores, and indexes room messages for E2E encrypted rooms.
81+
82+
The existing search will transparently work for encrypted rooms just like it
83+
does for non-encrypted.

‎docs/native-node-modules.md‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Native Node Modules
2+
3+
For some features, the desktop version of Riot can make use of native Node
4+
modules. These allow Riot to integrate with the desktop in ways that a browser
5+
cannot.
6+
7+
While native modules enable powerful new features, they must be complied for
8+
each operating system. For official Riot releases, we will always build these
9+
modules from source to ensure we can trust the compiled output. In the future,
10+
we may offer a pre-compiled path for those who want to use these features in a
11+
custom build of Riot without installing the various build tools required.
12+
13+
Do note that compiling a module for a particular operating system
14+
(Linux/macOS/Windows) will need to be done on that operating system.
15+
Cross-compiling from a host OS for a different target OS may be possible, but
16+
we don't support this flow with Riot dependencies at this time.
17+
18+
At the moment, we need to make some changes to the Riot release process before
19+
we can support native Node modules at release time, so these features are
20+
currently disabled by default until that is resolved. The following sections
21+
explain the manual steps you can use with a custom build of Riot to enable
22+
these features if you'd like to try them out.
23+
24+
## Adding Seshat for search in E2E encrypted rooms
25+
26+
Seshat is a native Node module that adds support for local event indexing and
27+
full text search in E2E encrypted rooms.
28+
29+
Since Seshat is written in Rust, the Rust compiler and related tools need to be
30+
installed before installing Seshat itself. To install Rust please consult the
31+
official Rust [documentation](https://www.rust-lang.org/tools/install).
32+
33+
Seshat also depends on the SQLCipher library to store its data in encrypted form
34+
on disk. You'll need to install it via your OS package manager.
35+
36+
After installing the Rust compiler and SQLCipher, Seshat support can be added
37+
using yarn inside the `electron_app/` directory:
38+
39+
yarn add matrix-seshat
40+
41+
After this is done the Electron version of Riot can be run from the main folder
42+
as usual using:
43+
44+
yarn electron
45+
46+
If for some reason recompilation of Seshat is needed, e.g. when using a
47+
development version of Seshat using `yarn link`, or if the initial compilation was
48+
done for the wrong electron version, Seshat can be recompiled with the
49+
`electron-build-env` tool. Again from the `electron_app/` directory:
50+
51+
yarn add electron-build-env
52+
53+
Recompiling Seshat itself can be done like so:
54+
55+
yarn run electron-build-env -- --electron 6.1.1 -- neon build matrix-seshat --release`
56+
57+
Please make sure to include all the `--` as well as the `--release` command line
58+
switch at the end. Modify your electron version accordingly depending on the
59+
version that is installed on your system.

‎electron_app/src/electron-main.js‎

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ const { migrateFromOldOrigin } = require('./originMigrator');
4040
const windowStateKeeper = require('electron-window-state');
4141
const Store = require('electron-store');
4242

43+
const fs = require('fs');
44+
const afs = fs.promises;
45+
46+
let Seshat = null;
47+
48+
try {
49+
Seshat = require('matrix-seshat');
50+
} catch (e) {
51+
}
52+
4353
if (argv["help"]) {
4454
console.log("Options:");
4555
console.log(" --profile-dir {path}: Path to where to store the profile.");
@@ -94,8 +104,11 @@ try {
94104
// Could not load local config, this is expected in most cases.
95105
}
96106

107+
const eventStorePath = path.join(app.getPath('userData'), 'EventStore');
97108
const store = new Store({ name: "electron-config" });
98109

110+
let eventIndex = null;
111+
99112
let mainWindow = null;
100113
global.appQuitting = false;
101114

@@ -225,6 +238,7 @@ ipcMain.on('ipcCall', async function(ev, payload) {
225238
case 'getConfig':
226239
ret = vectorConfig;
227240
break;
241+
228242
default:
229243
mainWindow.webContents.send('ipcReply', {
230244
id: payload.id,
@@ -239,6 +253,154 @@ ipcMain.on('ipcCall', async function(ev, payload) {
239253
});
240254
});
241255

256+
ipcMain.on('seshat', async function(ev, payload) {
257+
if (!mainWindow) return;
258+
259+
const sendError = (id, e) => {
260+
const error = {
261+
message: e.message
262+
}
263+
264+
mainWindow.webContents.send('seshatReply', {
265+
id:id,
266+
error: error
267+
});
268+
}
269+
270+
const args = payload.args || [];
271+
let ret;
272+
273+
switch (payload.name) {
274+
case 'supportsEventIndexing':
275+
if (Seshat === null) ret = false;
276+
else ret = true;
277+
break;
278+
279+
case 'initEventIndex':
280+
if (eventIndex === null) {
281+
try {
282+
await afs.mkdir(eventStorePath, {recursive: true});
283+
eventIndex = new Seshat(eventStorePath, {passphrase: "DEFAULT_PASSPHRASE"});
284+
} catch (e) {
285+
sendError(payload.id, e);
286+
return;
287+
}
288+
}
289+
break;
290+
291+
case 'closeEventIndex':
292+
eventIndex = null;
293+
break;
294+
295+
case 'deleteEventIndex':
296+
const deleteFolderRecursive = async(p) => {
297+
for (let entry of await afs.readdir(p)) {
298+
const curPath = path.join(p, entry);
299+
await afs.unlink(curPath);
300+
}
301+
}
302+
303+
try {
304+
await deleteFolderRecursive(eventStorePath);
305+
} catch (e) {
306+
}
307+
308+
break;
309+
310+
case 'isEventIndexEmpty':
311+
if (eventIndex === null) ret = true;
312+
else ret = await eventIndex.isEmpty();
313+
break;
314+
315+
case 'addEventToIndex':
316+
try {
317+
eventIndex.addEvent(args[0], args[1]);
318+
} catch (e) {
319+
sendError(payload.id, e);
320+
return;
321+
}
322+
break;
323+
324+
case 'commitLiveEvents':
325+
try {
326+
ret = await eventIndex.commit();
327+
} catch (e) {
328+
sendError(payload.id, e);
329+
return;
330+
}
331+
break;
332+
333+
case 'searchEventIndex':
334+
try {
335+
ret = await eventIndex.search(args[0]);
336+
} catch (e) {
337+
sendError(payload.id, e);
338+
return;
339+
}
340+
break;
341+
342+
case 'addHistoricEvents':
343+
if (eventIndex === null) ret = false;
344+
else {
345+
try {
346+
ret = await eventIndex.addHistoricEvents(
347+
args[0], args[1], args[2]);
348+
} catch (e) {
349+
sendError(payload.id, e);
350+
return;
351+
}
352+
}
353+
break;
354+
355+
case 'removeCrawlerCheckpoint':
356+
if (eventIndex === null) ret = false;
357+
else {
358+
try {
359+
ret = await eventIndex.removeCrawlerCheckpoint(args[0]);
360+
} catch (e) {
361+
sendError(payload.id, e);
362+
return;
363+
}
364+
}
365+
break;
366+
367+
case 'addCrawlerCheckpoint':
368+
if (eventIndex === null) ret = false;
369+
else {
370+
try {
371+
ret = await eventIndex.addCrawlerCheckpoint(args[0]);
372+
} catch (e) {
373+
sendError(payload.id, e);
374+
return;
375+
}
376+
}
377+
break;
378+
379+
case 'loadCheckpoints':
380+
if (eventIndex === null) ret = [];
381+
else {
382+
try {
383+
ret = await eventIndex.loadCheckpoints();
384+
} catch (e) {
385+
ret = [];
386+
}
387+
}
388+
break;
389+
390+
default:
391+
mainWindow.webContents.send('seshatReply', {
392+
id: payload.id,
393+
error: "Unknown IPC Call: " + payload.name,
394+
});
395+
return;
396+
}
397+
398+
mainWindow.webContents.send('seshatReply', {
399+
id: payload.id,
400+
reply: ret,
401+
});
402+
});
403+
242404
app.commandLine.appendSwitch('--enable-usermedia-screen-capturing');
243405

244406
const gotLock = app.requestSingleInstanceLock();

‎riot.im/develop/config.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"feature_many_integration_managers": "labs",
2121
"feature_mjolnir": "labs",
2222
"feature_dm_verification": "labs",
23-
"feature_cross_signing": "labs"
23+
"feature_cross_signing": "labs",
24+
"feature_event_indexing": "labs"
2425
},
2526
"welcomeUserId": "@riot-bot:matrix.org",
2627
"piwik": {

‎src/vector/platform/ElectronPlatform.js‎

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ limitations under the License.
2020
*/
2121

2222
import VectorBasePlatform, {updateCheckStatusEnum} from './VectorBasePlatform';
23+
import BaseEventIndexManager from 'matrix-react-sdk/lib/indexing/BaseEventIndexManager';
2324
import dis from 'matrix-react-sdk/lib/dispatcher';
2425
import { _t } from 'matrix-react-sdk/lib/languageHandler';
2526
import rageshake from 'matrix-react-sdk/lib/rageshake/rageshake';
@@ -65,12 +66,104 @@ function getUpdateCheckStatus(status) {
6566
}
6667
}
6768

69+
class SeshatIndexManager extends BaseEventIndexManager {
70+
constructor() {
71+
super();
72+
73+
this._pendingIpcCalls = {};
74+
this._nextIpcCallId = 0;
75+
ipcRenderer.on('seshatReply', this._onIpcReply.bind(this));
76+
}
77+
78+
async _ipcCall(name: string, ...args: []): Promise<{}> {
79+
// TODO this should be moved into the preload.js file.
80+
const ipcCallId = ++this._nextIpcCallId;
81+
return new Promise((resolve, reject) => {
82+
this._pendingIpcCalls[ipcCallId] = {resolve, reject};
83+
window.ipcRenderer.send('seshat', {id: ipcCallId, name, args});
84+
});
85+
}
86+
87+
_onIpcReply(ev: {}, payload: {}) {
88+
if (payload.id === undefined) {
89+
console.warn("Ignoring IPC reply with no ID");
90+
return;
91+
}
92+
93+
if (this._pendingIpcCalls[payload.id] === undefined) {
94+
console.warn("Unknown IPC payload ID: " + payload.id);
95+
return;
96+
}
97+
98+
const callbacks = this._pendingIpcCalls[payload.id];
99+
delete this._pendingIpcCalls[payload.id];
100+
if (payload.error) {
101+
callbacks.reject(payload.error);
102+
} else {
103+
callbacks.resolve(payload.reply);
104+
}
105+
}
106+
107+
async supportsEventIndexing(): Promise<boolean> {
108+
return this._ipcCall('supportsEventIndexing');
109+
}
110+
111+
async initEventIndex(): Promise<> {
112+
return this._ipcCall('initEventIndex');
113+
}
114+
115+
async addEventToIndex(ev: MatrixEvent, profile: MatrixProfile): Promise<> {
116+
return this._ipcCall('addEventToIndex', ev, profile);
117+
}
118+
119+
async isEventIndexEmpty(): Promise<boolean> {
120+
return this._ipcCall('isEventIndexEmpty');
121+
}
122+
123+
async commitLiveEvents(): Promise<> {
124+
return this._ipcCall('commitLiveEvents');
125+
}
126+
127+
async searchEventIndex(searchConfig: SearchConfig): Promise<SearchResult> {
128+
return this._ipcCall('searchEventIndex', searchConfig);
129+
}
130+
131+
async addHistoricEvents(
132+
events: [HistoricEvent],
133+
checkpoint: CrawlerCheckpoint | null,
134+
oldCheckpoint: CrawlerCheckpoint | null,
135+
): Promise<> {
136+
return this._ipcCall('addHistoricEvents', events, checkpoint, oldCheckpoint);
137+
}
138+
139+
async addCrawlerCheckpoint(checkpoint: CrawlerCheckpoint): Promise<> {
140+
return this._ipcCall('addCrawlerCheckpoint', checkpoint);
141+
}
142+
143+
async removeCrawlerCheckpoint(checkpoint: CrawlerCheckpoint): Promise<> {
144+
return this._ipcCall('removeCrawlerCheckpoint', checkpoint);
145+
}
146+
147+
async loadCheckpoints(): Promise<[CrawlerCheckpoint]> {
148+
return this._ipcCall('loadCheckpoints');
149+
}
150+
151+
async closeEventIndex(): Promise<> {
152+
return this._ipcCall('closeEventIndex');
153+
}
154+
155+
async deleteEventIndex(): Promise<> {
156+
return this._ipcCall('deleteEventIndex');
157+
}
158+
}
159+
68160
export default class ElectronPlatform extends VectorBasePlatform {
69161
constructor() {
70162
super();
71163

72164
this._pendingIpcCalls = {};
73165
this._nextIpcCallId = 0;
166+
this.eventIndexManager = new SeshatIndexManager();
74167

75168
dis.register(_onAction);
76169
/*
@@ -294,4 +387,8 @@ export default class ElectronPlatform extends VectorBasePlatform {
294387
callbacks.resolve(payload.reply);
295388
}
296389
}
390+
391+
getEventIndexingManager(): BaseEventIndexManager | null {
392+
return this.eventIndexManager;
393+
}
297394
}

0 commit comments

Comments
 (0)