Merge pull request #1614 from cryptpad/roster

Team roster channels slow down team members accounts
This commit is contained in:
yflory 2024-09-06 11:39:39 +02:00 committed by GitHub
commit 3698a5b7a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 145 additions and 4 deletions

View File

@ -135,8 +135,11 @@ define(req, function(AppConfig, Default, Language) {
return text;
}
};
Messages.team_autoTrim = "Removing unused history... Please wait."; // XXX
Messages.admin_mfa_confirm_enable = "Are you sure you want to enable Multi-Factor Authentication?"; // XXX
Messages.admin_mfa_confirm_disable = "Are you sure you want to disable Multi-Factor Authentication?"; // XXX
return Messages;
});

View File

@ -62,6 +62,19 @@ define([
return channels;
};
let getTeamChannels = function (ctx, teamId) {
let team = Util.find(ctx.store, ['proxy', 'teams', teamId]);
if (!team) { return []; }
let channels = [team.channel];
let roster = team.keys.roster;
channels.push({
channel: roster.channel,
lastKnownHash: roster.lastKnownHash
});
return channels;
};
var getEdPublic = function (ctx, teamId) {
if (!teamId) { return Util.find(ctx.store, ['proxy', 'edPublic']); }
@ -155,6 +168,8 @@ define([
// If account trim history, get the correct channels here
if (data.account) {
channels = getAccountChannels(ctx);
} else if (data.team) {
channels = getTeamChannels(ctx, data.team);
}
var size = 0;

View File

@ -694,7 +694,7 @@ var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto, Feedback)
// but since multiple users who can and should might be online at once
// and since they'll all trigger this process at the same time...
// we want to stagger attempts at random intervals
setTimeout(function () {
ref.internal.checkpointTimeout = setTimeout(function () {
ref.internal.pendingCheckpointId = roster.checkpoint(function (err) {
if (err) { console.error(err); }
});
@ -730,7 +730,10 @@ var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto, Feedback)
//console.log("Sending with id [%s]", id, msg);
//console.log();
response.expect(id, cb, TIMEOUT_INTERVAL);
response.expect(id, function (err, state) {
if (err) { return void cb(err); }
cb(void 0, state, id);
}, TIMEOUT_INTERVAL);
anon_rpc.send('WRITE_PRIVATE_MESSAGE', [
channel,
ciphertext

View File

@ -20,6 +20,9 @@ define([
'/common/userObject.js',
'/common/clipboard.js',
'/common/outer/login-block.js',
'/common/outer/roster.js',
'/common/rpc.js',
'/common/pinpad.js',
'/components/tweetnacl/nacl-fast.min.js',
@ -27,7 +30,7 @@ define([
'less!/customize/src/less2/pages/page-report.less',
], function ($, ApiConfig, h, Messages,
nThen, Hash, Util, Constants, Crypt, Cryptpad, Cache, UI, CPNetflux,
Crypto, UserObject, Clipboard, Block) {
Crypto, UserObject, Clipboard, Block, Roster, Rpc, Pinpad) {
var $report = $('#cp-report');
var blockHash = localStorage.Block_hash;
if (!blockHash) {
@ -41,6 +44,21 @@ define([
});
}
let report = true;
let fixRoster = false;
let urlHash = window.location.hash.slice(1);
if (urlHash) {
let s = urlHash.split('=');
let key = s[0];
let value = s[1];
if (key === "roster") {
report = false;
fixRoster = value; // teamid
}
}
var addReport = function (str) {
$report.append(h('div', str));
};
@ -153,6 +171,8 @@ define([
addReport('Teams: ' + Object.keys(proxy.teams || {}).join(', '));
addReport('-------------------');
if (!report) { return; }
var n = nThen;
Object.keys(drive.sharedFolders || {}).forEach(function (id) {
n = n(function (w) {
@ -188,16 +208,67 @@ define([
addReport('===================');
var n = nThen;
Object.keys(proxy.teams || {}).forEach(function (id) {
// If we're in "repair" mode, only load the affected team
var obj = proxy.teams[id];
if (!report && fixRoster !== obj.channel) { return; }
n = n(function (w) {
var next = w();
var obj = proxy.teams[id];
var team;
addReport('Load team. ID: ' + id + '. Channel ID: '+ obj.channel);
addReport('Roster channel: ' + obj.keys.roster.channel);
addReport('Roster lkh: ' + obj.keys.roster.lastKnownHash);
if (!obj.hash) { addReport("View only"); }
var teamSecret = Hash.getSecrets('team', obj.hash || obj.roHash, obj.password);
var cryptor = UserObject.createCryptor(teamSecret.keys.secondaryKey);
// Repair roster mode
if (!report) {
let roster = obj.keys.roster;
let rpc, anon_rpc;
if (!obj.owner || !roster.edit) {
return void addReport('Roster error: only owners can repair');
}
n(w => {
Rpc.createAnonymous(network, w(function (e, call) {
anon_rpc = call;
}));
Pinpad.create(network, proxy, w(function (e, call) {
rpc = call;
}));
}).nThen(w => {
if (!anon_rpc || !rpc) {
return void addReport('RPC error');
}
var rosterKeys = Crypto.Team.deriveMemberKeys(roster.edit, {
curvePublic: proxy.curvePublic,
curvePrivate: proxy.curvePrivate
});
let store = { anon_rpc };
Roster.create({
network: network,
channel: roster.channel,
keys: rosterKeys,
store: store,
lastKnownHash: roster.lastKnownHash
}, w(function (err, _roster) {
if (err) { return void addReport('Fix roster error', err); }
_roster.checkpoint(w((err, state, hash) => {
if (err) { addReport('Fix roster error', err); }
rpc.trimHistory({
channel: roster.channel,
hash
}, w(function (err) {
console.error(arguments);
if (err) { addReport('Trim roster error', err); }
}));
}));
}));
}).nThen(next);
return;
}
// Check team drive
nThen(function (ww) {
addReport('Team drive');

View File

@ -292,6 +292,15 @@
margin: 0;
}
}
.cp-team-trim {
display: flex;
align-items: center;
justify-content: center;
.fa {
font-size: 30px;
margin-right: 10px;
}
}
.cp-teams-invite-uses {
input {

View File

@ -191,6 +191,7 @@ define([
'cp-team-avatar',
'cp-team-export',
'cp-team-delete',
'cp-team-history',
],
};
@ -398,6 +399,43 @@ define([
]);
});
let AUTOTRIM_LIMIT = 102400; // 100kB history before auto trim
var trimHistory = function () {
var size;
var channels = [];
nThen(function(waitFor) {
APP.history.execCommand('GET_HISTORY_SIZE', {
team: APP.team,
channels: []
}, waitFor(function(obj) {
if (obj && obj.error) {
waitFor.abort();
console.error(obj.error);
return;
}
channels = obj.channels;
size = Number(obj.size);
}));
}).nThen(function() {
if (!size || size < AUTOTRIM_LIMIT) {
// Nothing to delete
return;
}
var div = h('div.cp-team-trim', [
h('span.fa.fa-spin.fa-spinner'),
h('span', Messages.team_autoTrim)
]);
UI.openCustomModal(UI.dialog.customModal(div, {buttons: []}));
console.log('Trimming team history', APP.team, size);
APP.history.execCommand('TRIM_HISTORY', {
channels: channels
}, function(obj) {
if (obj && obj.error) { console.error(obj.error); }
UI.removeModals();
});
});
};
var openTeam = function (common, id, team) {
var sframeChan = common.getSframeChannel();
APP.module.execCommand('SUBSCRIBE', id, function () {
@ -422,6 +460,7 @@ define([
APP.team = id;
APP.teamEdPublic = Util.find(team, ['keys', 'drive', 'edPublic']);
buildUI(common, true, team.owner);
if (team.owner) { trimHistory(common); }
});
});
};
@ -1556,6 +1595,7 @@ define([
}
};
APP.history = common.makeUniversal('history');
APP.module = common.makeUniversal('team', {
onEvent: onEvent
});