implement block archival

pull/1/head
ansuz 3 years ago
parent caece0123e
commit 9806d718d5

@ -86,6 +86,20 @@ var createLoginBlockPath = function (Env, publicKey) { // FIXME BLOCKS
return Path.join(Env.paths.block, safeKey.slice(0, 2), safeKey); return Path.join(Env.paths.block, safeKey.slice(0, 2), safeKey);
}; };
var createLoginBlockArchivePath = function (Env, publicKey) {
// prepare publicKey to be used as a file name
var safeKey = Util.escapeKeyCharacters(publicKey);
// validate safeKey
if (typeof(safeKey) !== 'string') {
return;
}
// derive the full path
// /home/cryptpad/cryptpad/block/fg/fg32kefksjdgjkewrjksdfksjdfsdfskdjfsfd
return Path.join(Env.paths.archive, 'block', safeKey.slice(0, 2), safeKey);
};
Block.validateAncestorProof = function (Env, proof, _cb) { Block.validateAncestorProof = function (Env, proof, _cb) {
var cb = Util.once(Util.mkAsync(_cb)); var cb = Util.once(Util.mkAsync(_cb));
/* prove that you own an existing block by signing for its publicKey */ /* prove that you own an existing block by signing for its publicKey */
@ -216,7 +230,7 @@ Block.writeLoginBlock = function (Env, safeKey, msg, _cb) { // FIXME BLOCKS
information, we can just sign some constant and use that as proof. information, we can just sign some constant and use that as proof.
*/ */
Block.removeLoginBlock = function (Env, safeKey, msg, cb) { // FIXME BLOCKS Block.removeLoginBlock = function (Env, safeKey, msg, cb) {
var publicKey = msg[0]; var publicKey = msg[0];
var signature = msg[1]; var signature = msg[1];
var block = Nacl.util.decodeUTF8('DELETE_BLOCK'); // clients and the server will have to agree on this constant var block = Nacl.util.decodeUTF8('DELETE_BLOCK'); // clients and the server will have to agree on this constant
@ -230,21 +244,28 @@ Block.removeLoginBlock = function (Env, safeKey, msg, cb) { // FIXME BLOCKS
validateLoginBlock(Env, publicKey, signature, block, function (e /*::, validatedBlock */) { validateLoginBlock(Env, publicKey, signature, block, function (e /*::, validatedBlock */) {
if (e) { return void cb(e); } if (e) { return void cb(e); }
// derive the filepath // derive the filepath
var path = createLoginBlockPath(Env, publicKey); var currentPath = createLoginBlockPath(Env, publicKey);
// make sure the path is valid // make sure the path is valid
if (typeof(path) !== 'string') { if (typeof(currentPath) !== 'string') {
return void cb('E_INVALID_BLOCK_PATH'); return void cb('E_INVALID_BLOCK_PATH');
} }
// FIXME COLDSTORAGE var archivePath = createLoginBlockArchivePath(Env, publicKey);
Fs.unlink(path, function (err) { // make sure the path is valid
Env.Log.info('DELETION_BLOCK_BY_OWNER_RPC', { if (typeof(archivePath) !== 'string') {
return void cb('E_INVALID_BLOCK_ARCHIVAL_PATH');
}
Fse.move(currentPath, archivePath, {
overwrite: true,
}, function (err) {
Env.Log.info('ARCHIVAL_BLOCK_BY_OWNER_RPC', {
publicKey: publicKey, publicKey: publicKey,
path: path, currentPath: currentPath,
archivePath: archivePath,
status: err? String(err): 'SUCCESS', status: err? String(err): 'SUCCESS',
}); });
if (err) { return void cb(err); } if (err) { return void cb(err); }
cb(); cb();
}); });

Loading…
Cancel
Save