Merge branch 'staging' into team
This commit is contained in:
commit
9e43e8226f
@ -190,14 +190,13 @@ var createUser = function (config, cb) {
|
|||||||
}));
|
}));
|
||||||
}).nThen(function () {
|
}).nThen(function () {
|
||||||
/*
|
/*
|
||||||
// XXX race condition because both users try to pin things...
|
// FIXME race condition because both users try to pin things...
|
||||||
user.team_rpc.getServerHash(w(function (err, hash) {
|
user.team_rpc.getServerHash(w(function (err, hash) {
|
||||||
if (err) {
|
if (err) {
|
||||||
w.abort();
|
w.abort();
|
||||||
return void cb(err);
|
return void cb(err);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
/*
|
|
||||||
if (!hash || hash[0] !== EMPTY_ARRAY_HASH) {
|
if (!hash || hash[0] !== EMPTY_ARRAY_HASH) {
|
||||||
console.error("EXPECTED EMPTY ARRAY HASH");
|
console.error("EXPECTED EMPTY ARRAY HASH");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
|||||||
@ -74,7 +74,8 @@ var isFile = function (filePath, cb) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var makeFileStream = function (full, cb) {
|
var makeFileStream = function (full, _cb) {
|
||||||
|
var cb = Util.once(Util.mkAsync(_cb));
|
||||||
Fse.mkdirp(Path.dirname(full), function (e) {
|
Fse.mkdirp(Path.dirname(full), function (e) {
|
||||||
if (e || !full) { // !full for pleasing flow, it's already checked
|
if (e || !full) { // !full for pleasing flow, it's already checked
|
||||||
return void cb(e ? e.message : 'INTERNAL_ERROR');
|
return void cb(e ? e.message : 'INTERNAL_ERROR');
|
||||||
@ -89,10 +90,8 @@ var makeFileStream = function (full, cb) {
|
|||||||
stream.on('open', function () {
|
stream.on('open', function () {
|
||||||
cb(void 0, stream);
|
cb(void 0, stream);
|
||||||
});
|
});
|
||||||
stream.on('error', function (/* e */) {
|
stream.on('error', function (err) {
|
||||||
//console.error("MAKE_FILE_STREAM", full);
|
cb(err);
|
||||||
// XXX ERROR
|
|
||||||
//WARN('stream error', e);
|
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
cb('BAD_STREAM');
|
cb('BAD_STREAM');
|
||||||
|
|||||||
@ -197,14 +197,22 @@ var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto) {
|
|||||||
}
|
}
|
||||||
var members = roster.state.members;
|
var members = roster.state.members;
|
||||||
|
|
||||||
var changed = false;
|
// validate first...
|
||||||
args.forEach(function (curve) {
|
args.forEach(function (curve) {
|
||||||
if (!isValidId(curve)) { throw new Error("INVALID_CURVE_KEY"); }
|
if (!isValidId(curve)) { throw new Error("INVALID_CURVE_KEY"); }
|
||||||
|
|
||||||
// don't try to remove something that isn't there
|
// even members can remove themselves
|
||||||
if (!members[curve]) { return; }
|
if (curve === author) { return; }
|
||||||
|
|
||||||
|
// but if it concerns anyone else, validate that the author has sufficient permissions
|
||||||
var role = members[curve].role;
|
var role = members[curve].role;
|
||||||
if (!canRemoveRole(author, role, members)) { throw new Error("INSUFFICIENT_PERMISSIONS"); }
|
if (!canRemoveRole(author, role, members)) { throw new Error("INSUFFICIENT_PERMISSIONS"); }
|
||||||
|
});
|
||||||
|
|
||||||
|
var changed = false;
|
||||||
|
args.forEach(function (curve) {
|
||||||
|
// don't try to remove something that isn't there
|
||||||
|
if (!members[curve]) { return; }
|
||||||
changed = true;
|
changed = true;
|
||||||
delete members[curve];
|
delete members[curve];
|
||||||
});
|
});
|
||||||
@ -352,6 +360,8 @@ var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto) {
|
|||||||
var keys = config.keys;
|
var keys = config.keys;
|
||||||
var me = keys.myCurvePublic;
|
var me = keys.myCurvePublic;
|
||||||
var channel = config.channel;
|
var channel = config.channel;
|
||||||
|
var lastKnownHash = config.lastKnownHash || -1;
|
||||||
|
|
||||||
var ref = {
|
var ref = {
|
||||||
state: {
|
state: {
|
||||||
members: { },
|
members: { },
|
||||||
@ -360,7 +370,7 @@ var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto) {
|
|||||||
internal: {
|
internal: {
|
||||||
initialized: false,
|
initialized: false,
|
||||||
sinceLastCheckpoint: 0,
|
sinceLastCheckpoint: 0,
|
||||||
lastCheckpointHash: -1
|
lastCheckpointHash: lastKnownHash,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
var roster = {};
|
var roster = {};
|
||||||
@ -462,7 +472,7 @@ var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto) {
|
|||||||
try {
|
try {
|
||||||
changed = handleCommand(parsed, author, ref);
|
changed = handleCommand(parsed, author, ref);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
error = err;
|
error = err.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
var id = getMessageId(hash);
|
var id = getMessageId(hash);
|
||||||
@ -517,7 +527,7 @@ var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto) {
|
|||||||
// simulate the command before you send it
|
// simulate the command before you send it
|
||||||
changed = simulate(msg, keys.myCurvePublic, ref);
|
changed = simulate(msg, keys.myCurvePublic, ref);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return void cb(err);
|
return void cb(err.message);
|
||||||
}
|
}
|
||||||
if (!changed) { return void cb("NO_CHANGE"); }
|
if (!changed) { return void cb("NO_CHANGE"); }
|
||||||
|
|
||||||
@ -533,7 +543,7 @@ var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto) {
|
|||||||
channel,
|
channel,
|
||||||
ciphertext
|
ciphertext
|
||||||
], function (err) {
|
], function (err) {
|
||||||
if (err) { return response.handle(id, [err]); }
|
if (err) { return response.handle(id, [err.message || err]); }
|
||||||
});
|
});
|
||||||
return id;
|
return id;
|
||||||
};
|
};
|
||||||
@ -644,7 +654,6 @@ var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto) {
|
|||||||
return void cb(err);
|
return void cb(err);
|
||||||
}
|
}
|
||||||
}).nThen(function () {
|
}).nThen(function () {
|
||||||
var lastKnownHash = config.lastKnownHash || -1;
|
|
||||||
if (typeof(lastKnownHash) === 'string') {
|
if (typeof(lastKnownHash) === 'string') {
|
||||||
console.log("Synchronizing from checkpoint");
|
console.log("Synchronizing from checkpoint");
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user