correct a few more places where the client expected hashes in pin responses
or where the server incorrectly provided them
This commit is contained in:
parent
8e725f3d7c
commit
76b90d3c8a
|
@ -145,7 +145,7 @@ var getFreeSpace = Pinning.getFreeSpace = function (Env, safeKey, cb) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var getHash = Pinning.getHash = function (Env, safeKey, cb) {
|
Pinning.getHash = function (Env, safeKey, cb) {
|
||||||
getChannelList(Env, safeKey, function (channels) {
|
getChannelList(Env, safeKey, function (channels) {
|
||||||
Env.hashChannelList(channels, cb);
|
Env.hashChannelList(channels, cb);
|
||||||
});
|
});
|
||||||
|
@ -166,7 +166,7 @@ Pinning.pinChannel = function (Env, safeKey, channels, cb) {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (toStore.length === 0) {
|
if (toStore.length === 0) {
|
||||||
return void getHash(Env, safeKey, cb);
|
return void cb();
|
||||||
}
|
}
|
||||||
|
|
||||||
getMultipleFileSize(Env, toStore, function (e, sizes) {
|
getMultipleFileSize(Env, toStore, function (e, sizes) {
|
||||||
|
@ -208,7 +208,7 @@ Pinning.unpinChannel = function (Env, safeKey, channels, cb) {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (toStore.length === 0) {
|
if (toStore.length === 0) {
|
||||||
return void getHash(Env, safeKey, cb);
|
return void cb();
|
||||||
}
|
}
|
||||||
|
|
||||||
Env.pinStore.message(safeKey, JSON.stringify(['UNPIN', toStore, +new Date()]),
|
Env.pinStore.message(safeKey, JSON.stringify(['UNPIN', toStore, +new Date()]),
|
||||||
|
@ -222,15 +222,14 @@ Pinning.unpinChannel = function (Env, safeKey, channels, cb) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Pinning.resetUserPins = function (Env, safeKey, channelList, cb) {
|
Pinning.resetUserPins = function (Env, safeKey, channelList, _cb) {
|
||||||
|
var cb = Util.once(Util.mkAsync(_cb));
|
||||||
if (!Array.isArray(channelList)) { return void cb('INVALID_PIN_LIST'); }
|
if (!Array.isArray(channelList)) { return void cb('INVALID_PIN_LIST'); }
|
||||||
var session = Core.getSession(Env.Sessions, safeKey);
|
var session = Core.getSession(Env.Sessions, safeKey);
|
||||||
|
|
||||||
if (!channelList.length) {
|
|
||||||
return void getHash(Env, safeKey, function (e, hash) {
|
if (!channelList.length) { // XXX wut
|
||||||
if (e) { return cb(e); }
|
return void cb();
|
||||||
cb(void 0, hash);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var pins = {};
|
var pins = {};
|
||||||
|
|
|
@ -122,14 +122,11 @@ var createUser = function (config, cb) {
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
}).nThen(function (w) {
|
}).nThen(function (w) {
|
||||||
user.rpc.reset([], w(function (err, hash) {
|
user.rpc.reset([], w(function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
w.abort();
|
w.abort();
|
||||||
user.shutdown();
|
user.shutdown();
|
||||||
return console.log("RESET_ERR");
|
return console.log("TEST_RESET_ERR");
|
||||||
}
|
|
||||||
if (!hash || hash !== EMPTY_ARRAY_HASH) {
|
|
||||||
throw new Error("EXPECTED EMPTY ARRAY HASH");
|
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}).nThen(function (w) {
|
}).nThen(function (w) {
|
||||||
|
@ -214,17 +211,17 @@ var createUser = function (config, cb) {
|
||||||
// TODO check your quota usage
|
// TODO check your quota usage
|
||||||
|
|
||||||
}).nThen(function (w) {
|
}).nThen(function (w) {
|
||||||
user.rpc.unpin([user.mailboxChannel], w(function (err, hash) {
|
user.rpc.unpin([user.mailboxChannel], w(function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
w.abort();
|
w.abort();
|
||||||
return void cb(err);
|
return void cb(err);
|
||||||
}
|
}
|
||||||
|
}));
|
||||||
|
}).nThen(function (w) {
|
||||||
|
user.rpc.getServerHash(w(function (err, hash) {
|
||||||
|
console.log(hash);
|
||||||
|
|
||||||
if (hash[0] !== EMPTY_ARRAY_HASH) {
|
user.latestPinHash = hash;
|
||||||
//console.log('UNPIN_RESPONSE', hash);
|
|
||||||
throw new Error("UNPIN_DIDNT_WORK");
|
|
||||||
}
|
|
||||||
user.latestPinHash = hash[0];
|
|
||||||
}));
|
}));
|
||||||
}).nThen(function (w) {
|
}).nThen(function (w) {
|
||||||
// clean up the pin list to avoid lots of accounts on the server
|
// clean up the pin list to avoid lots of accounts on the server
|
||||||
|
@ -304,7 +301,8 @@ nThen(function (w) {
|
||||||
}, w(function (err, roster) {
|
}, w(function (err, roster) {
|
||||||
if (err) {
|
if (err) {
|
||||||
w.abort();
|
w.abort();
|
||||||
return void console.trace(err);
|
console.error(err);
|
||||||
|
return void console.error("ROSTER_ERROR");
|
||||||
}
|
}
|
||||||
oscar.roster = roster;
|
oscar.roster = roster;
|
||||||
oscar.destroy.reg(function () {
|
oscar.destroy.reg(function () {
|
||||||
|
|
|
@ -26,23 +26,19 @@ var factory = function (Util, Rpc) {
|
||||||
exp.send = rpc.send;
|
exp.send = rpc.send;
|
||||||
|
|
||||||
// you can ask the server to pin a particular channel for you
|
// you can ask the server to pin a particular channel for you
|
||||||
exp.pin = function (channels, cb) {
|
exp.pin = function (channels, _cb) {
|
||||||
|
var cb = Util.once(Util.mkAsync(_cb));
|
||||||
if (!Array.isArray(channels)) {
|
if (!Array.isArray(channels)) {
|
||||||
setTimeout(function () {
|
return void cb('[TypeError] pin expects an array');
|
||||||
cb('[TypeError] pin expects an array');
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
rpc.send('PIN', channels, cb);
|
rpc.send('PIN', channels, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
// you can also ask to unpin a particular channel
|
// you can also ask to unpin a particular channel
|
||||||
exp.unpin = function (channels, cb) {
|
exp.unpin = function (channels, _cb) {
|
||||||
|
var cb = Util.once(Util.mkAsync(_cb));
|
||||||
if (!Array.isArray(channels)) {
|
if (!Array.isArray(channels)) {
|
||||||
setTimeout(function () {
|
return void cb('[TypeError] pin expects an array');
|
||||||
cb('[TypeError] pin expects an array');
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
rpc.send('UNPIN', channels, cb);
|
rpc.send('UNPIN', channels, cb);
|
||||||
};
|
};
|
||||||
|
@ -70,23 +66,12 @@ var factory = function (Util, Rpc) {
|
||||||
};
|
};
|
||||||
|
|
||||||
// if local and remote hashes don't match, send a reset
|
// if local and remote hashes don't match, send a reset
|
||||||
exp.reset = function (channels, cb) {
|
exp.reset = function (channels, _cb) {
|
||||||
|
var cb = Util.once(Util.mkAsync(_cb));
|
||||||
if (!Array.isArray(channels)) {
|
if (!Array.isArray(channels)) {
|
||||||
setTimeout(function () {
|
return void cb('[TypeError] pin expects an array');
|
||||||
cb('[TypeError] pin expects an array');
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
rpc.send('RESET', channels, function (e, response) {
|
rpc.send('RESET', channels, cb);
|
||||||
if (e) {
|
|
||||||
return void cb(e);
|
|
||||||
}
|
|
||||||
if (!response.length) {
|
|
||||||
console.log(response);
|
|
||||||
return void cb('INVALID_RESPONSE');
|
|
||||||
}
|
|
||||||
cb(e, response[0]);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// get the combined size of all channels (in bytes) for all the
|
// get the combined size of all channels (in bytes) for all the
|
||||||
|
|
Loading…
Reference in New Issue