implement atomic pin reset rpc

pull/1/head
ansuz 8 years ago
parent 89bca1606b
commit e87992c7ec

@ -143,6 +143,17 @@ var getChannelList = function (store, publicKey, cb) {
Object.keys(pins).forEach(function (pin) {
pins[pin] = false;
});
if (!parsed[1] || parsed[1].length) {
break;
}
else {
parsed[1].forEach(function (channel) {
pins[channel] = true;
});
break;
}
break;
default:
console.error('invalid message read from store');
@ -236,8 +247,14 @@ var unpinChannel = function (store, publicKey, channel, cb) {
};
var resetUserPins = function (store, publicKey, channelList, cb) {
// TODO make this atomic
store.message(publicKey, JSON.stringify(['RESET']), cb);
store.message(publicKey, JSON.stringify(['RESET', channelList]),
function (e) {
if (e) { return void cb(e); }
getHash(store, publicKey, function (e, hash) {
cb(e, hash);
});
});
};
var expireSessions = function (Cookies) {
@ -324,18 +341,11 @@ RPC.create = function (config, cb) {
}
switch (msg[0]) {
case 'COOKIE':
return void Respond(void 0);
case 'ECHO':
return void Respond(void 0, msg);
/* TODO
reset should be atomic in case the operation is aborted */
case 'COOKIE': return void Respond(void 0);
case 'RESET':
return resetUserPins(store, safeKey, [], function (e) {
return void Respond(e);
return resetUserPins(store, safeKey, msg[1], function (e, hash) {
return void Respond(e, hash);
});
case 'PIN':
return pinChannel(store, safeKey, msg[1], function (e, hash) {
Respond(e, hash);

@ -41,7 +41,8 @@ define([
};
var reset = function (rpc, cb) {
rpc.send('RESET', undefined, cb);
var list = uniqueChannelList();
rpc.send('RESET', list, cb);
};
/*
@ -54,7 +55,6 @@ define([
UNPIN all, send all
*/
// Don't use create until Cryptpad is ready
// (use Cryptpad.ready)
var create = function (cb) {

@ -61,26 +61,9 @@ define([
call.reset(function (e, response) {
if (e) { return console.error(e); }
var list = call.uniqueChannelList();
var left = list.length;
// now start pinning...
list.forEach(function (channel) {
call.pin(channel, function (e, hash) {
left--;
if (!e) {
console.log('pinned channel [%s]. new hash is [%s]', channel, hash);
} else {
console.error(e);
}
if (left === 0) {
console.log('done pinning');
}
});
});
else {
return console.log('reset pin list. new hash is [%s]', response);
}
});
/*

Loading…
Cancel
Save