improve async generator logging; don't call done() on StopIteration when we already have a timer set (it means the generator just 'bottomed out' after calling done()); make XHRs be synchronous (blocking) - temporarily; fix up sharing code (adding to the keyring)

This commit is contained in:
Dan Mills 2008-03-26 00:59:34 -07:00
Родитель 4bbd3af126
Коммит a7291a69bd
4 изменённых файлов: 42 добавлений и 23 удалений

Просмотреть файл

@ -141,14 +141,17 @@ Generator.prototype = {
_handleException: function AsyncGen__handleException(e) {
if (e instanceof StopIteration) {
if (!this._timer)
this._log.trace("[" + this.name + "] Generator stopped unexpectedly");
if (this.errorOnStop) {
this._log.error("Generator stopped unexpectedly");
this._log.error("[" + this.name + "] Generator stopped unexpectedly");
this._log.trace("Stack trace:\n" + this.trace);
this._exception = "Generator stopped unexpectedly"; // don't propagate StopIteration
}
} else if (this.onComplete.parentGenerator instanceof Generator) {
//this._log.trace("Saving exception and stack trace");
this._log.trace("[" + this.name + "] Saving exception and stack trace");
this._log.trace(Async.exceptionStr(this, e));
if (e instanceof AsyncException)
e.trace = this.trace + e.trace? "\n" + e.trace : "";
@ -167,7 +170,10 @@ Generator.prototype = {
// in the case of StopIteration we could return an error right
// away, but instead it's easiest/best to let the caller handle
// the error after a yield / in a callback.
this.done();
if (!this._timer) {
this._log.trace("[" + this.name + "] running done() from _handleException()");
this.done();
}
},
run: function AsyncGen_run() {
@ -218,10 +224,11 @@ Generator.prototype = {
this._timer = null;
if (this._exception) {
this._log.trace("Propagating exception to parent generator");
this._log.trace("[" + this.name + "] Propagating exception to parent generator");
this.onComplete.parentGenerator.throw(this._exception);
} else {
try {
this._log.trace("[" + this.name + "] Running onComplete()");
this.onComplete(retval);
} catch (e) {
this._log.error("Exception caught from onComplete handler of " +

Просмотреть файл

@ -108,10 +108,11 @@ DAVCollection.prototype = {
let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance();
request = request.QueryInterface(Ci.nsIDOMEventTarget);
request.addEventListener("load", new Utils.EventListener(self.cb, "load"), false);
request.addEventListener("error", new Utils.EventListener(self.cb, "error"), false);
// request.addEventListener("load", new Utils.EventListener(self.cb, "load"), false);
// request.addEventListener("error", new Utils.EventListener(self.cb, "error"), false);
request = request.QueryInterface(Ci.nsIXMLHttpRequest);
request.open(op, this._baseURL + path, true);
// request.open(op, this._baseURL + path, true);
request.open(op, this._baseURL + path, false); // FIXME: blocking
// Force cache validation
@ -134,8 +135,9 @@ DAVCollection.prototype = {
request.channel.notificationCallbacks = this._authProvider;
request.send(data);
let event = yield;
ret = event.target;
ret = request;
// let event = yield;
// ret = event.target;
if (this._authProvider._authFailed)
this._log.warn("_makeRequest: authentication failed");

Просмотреть файл

@ -678,23 +678,28 @@ Engine.prototype = {
_share: function Engine__share(username) {
let self = yield;
this._getSymKey.async(this, self.cb);
yield;
let base = this._dav.baseURL;
this._log.debug("Sharing bookmarks with " + username);
try {
this._getSymKey.async(this, self.cb);
yield;
// copied from getSymKey
this._log.debug("Getting keyring from server");
this._dav.GET(this.keysFile, self.cb);
let ret = yield;
Utils.ensureStatus(ret.status,
"Could not get keys file.", [[200,300]]);
let keys = this._json.decode(keysResp.responseText);
Utils.ensureStatus(ret.status, "Could not get keys file.");
let keys = this._json.decode(ret.responseText);
// get the other user's pubkey
this._log.debug("Constructing other user's URL");
let hash = Utils.sha1(username);
let serverURL = Utils.prefs.getCharPref("serverURL");
this._dav.baseURL = serverURL + "user/" + hash + "/"; //FIXME: very ugly!
this._log.debug("Getting other user's public key");
this._dav.GET("public/pubkey", self.cb);
ret = yield;
Utils.ensureStatus(ret.status,
@ -705,16 +710,20 @@ Engine.prototype = {
this._dav.baseURL = base;
// now encrypt the symkey with their pubkey and upload the new keyring
this._log.debug("Encrypting symmetric key with other user's public key");
Crypto.RSAencrypt.async(Crypto, self.cb, this._engineId.password, id);
let enckey = yield;
if (!enckey)
throw "Could not encrypt symmetric encryption key";
this._log.debug("Uploading new keyring");
keys.ring[hash] = enckey;
this._dav.PUT(this.keysFile, this._json.encode(keys), self.cb);
ret = yield;
Utils.ensureStatus(ret.status, "Could not upload keyring file.");
this._log.debug("All done sharing!");
} catch (e) {
throw e;

Просмотреть файл

@ -610,19 +610,20 @@ WeaveSvc.prototype = {
let self = yield;
try {
//this._lock.async(this, self.cb);
//let locked = yield;
//if (!locked)
// return;
this._lock.async(this, self.cb);
let locked = yield;
if (!locked)
return;
this._bmkEngine.share(self.cb, username);
yield;
} catch (e) {
throw e;
} finally {
//this._unlock.async(this, self.cb);
//yield;
this._unlock.async(this, self.cb);
yield;
}
self.done();
@ -666,6 +667,6 @@ WeaveSvc.prototype = {
resetServer: function WeaveSync_resetServer() { this._resetServer.async(this); },
resetClient: function WeaveSync_resetClient() { this._resetClient.async(this); },
shareBookmarks: function WeaveSync_shareBookmarks(username) {
this._shareBookmarks.async(this, null, username);
this._shareBookmarks.async(this, function() {}, username);
}
};