From 8ec3277ff20629588e7166ccdde9e75c7f0a2792 Mon Sep 17 00:00:00 2001 From: Dietrich Ayala Date: Wed, 4 Jun 2008 17:00:02 -0700 Subject: [PATCH] [mq]: xmpp-reconnect --- services/sync/modules/xmpp/readme.txt | 6 +++--- services/sync/modules/xmpp/transportLayer.js | 5 ++++- services/sync/modules/xmpp/xmppClient.js | 9 +++------ services/sync/tests/unit/test_xmpp.js | 14 +++++--------- services/sync/tests/unit/test_xmpp_simple.js | 5 ++--- 5 files changed, 17 insertions(+), 22 deletions(-) diff --git a/services/sync/modules/xmpp/readme.txt b/services/sync/modules/xmpp/readme.txt index 071e46a33ef5..29397a9dd13a 100644 --- a/services/sync/modules/xmpp/readme.txt +++ b/services/sync/modules/xmpp/readme.txt @@ -1,6 +1,8 @@ About the XMPP module -Here is sample code demonstrating how client code can use the XMPP module. It assumes that a Jabber server is running on localhost on port 5280. +Here is sample code demonstrating how client code can use the XMPP module. +It assumes that a Jabber server capable of HTTP-Polling is running on localhost +on port 5280. Components.utils.import( "resource://weave/xmpp/xmppClient.js" ); @@ -66,7 +68,6 @@ The ejabberd process is started simply by running: ejabberd/bin/ejabberdctl start - Outstanding Issues -- bugs and things to do. * The test above is failing with a timeout. How to debug this? Let's start @@ -122,4 +123,3 @@ Outstanding Issues -- bugs and things to do. (Everything seems to be working OK with useKeys turned off, but that's less secure.) - diff --git a/services/sync/modules/xmpp/transportLayer.js b/services/sync/modules/xmpp/transportLayer.js index de3d63f91f4e..0b08f9d8630d 100644 --- a/services/sync/modules/xmpp/transportLayer.js +++ b/services/sync/modules/xmpp/transportLayer.js @@ -314,7 +314,7 @@ HTTPPollingTransport.prototype = { }, setCallbackObject: function( callbackObject ) { - this._callbackObject = callbackObject; + this._callbackObject = callbackObject; }, notify: function( timer ) { @@ -332,6 +332,9 @@ HTTPPollingTransport.prototype = { }, connect: function() { + // In case this is a reconnect, make sure to re-initialize. + this._init(this._serverUrl, this._useKeys, this._interval); + /* Set up a timer to poll the server periodically. */ // TODO doPost isn't reentrant; don't try to doPost if there's diff --git a/services/sync/modules/xmpp/xmppClient.js b/services/sync/modules/xmpp/xmppClient.js index 52e326ffe969..77d9ec5ce136 100644 --- a/services/sync/modules/xmpp/xmppClient.js +++ b/services/sync/modules/xmpp/xmppClient.js @@ -7,6 +7,9 @@ const EXPORTED_SYMBOLS = ['XmppClient', 'HTTPPollingTransport', 'PlainAuthentica // http://developer.mozilla.org/en/docs/xpcshell // http://developer.mozilla.org/en/docs/Writing_xpcshell-based_unit_tests +// IM level protocol stuff: presence announcements, conversations, etc. +// ftp://ftp.isi.edu/in-notes/rfc3921.txt + var Cc = Components.classes; var Ci = Components.interfaces; var Cu = Components.utils; @@ -419,15 +422,9 @@ XmppClient.prototype = { }, waitForDisconnect: function() { - LOG("waitForDisconnect(): starting"); var thread = this._threadManager.currentThread; while ( this._connectionStatus == this.CONNECTED ) { thread.processNextEvent( true ); } } - }; - -// IM level protocol stuff: presence announcements, conversations, etc. -// ftp://ftp.isi.edu/in-notes/rfc3921.txt - diff --git a/services/sync/tests/unit/test_xmpp.js b/services/sync/tests/unit/test_xmpp.js index 04958495bfde..09f718d8f0d5 100644 --- a/services/sync/tests/unit/test_xmpp.js +++ b/services/sync/tests/unit/test_xmpp.js @@ -6,10 +6,8 @@ function LOG(aMsg) { dump("TEST_XMPP: " + aMsg + "\n"); } -var serverUrl = "http://127.0.0.1:5280/http-poll"; -var jabberDomain = Cc["@mozilla.org/network/dns-service;1"]. - getService(Ci.nsIDNSService).myHostName; -LOG("DOMAIN: " + jabberDomain); +var serverUrl = "http://localhost:5280/http-poll"; +var jabberDomain = "localhost"; var timer = Cc["@mozilla.org/timer;1"].createInstance( Ci.nsITimer ); var threadManager = Cc["@mozilla.org/thread-manager;1"].getService(); @@ -19,12 +17,10 @@ function run_test() { return; /* First, just see if we can connect: */ - var transport = new HTTPPollingTransport( serverUrl, - false, - 4000 ); + var transport = new HTTPPollingTransport(serverUrl, false, 4000); var auth = new PlainAuthenticator(); var alice = new XmppClient("alice", jabberDomain, "iamalice", - transport, auth); + transport, auth); // test connection LOG("connecting"); @@ -39,7 +35,6 @@ function run_test() { do_check_eq( alice._connectionStatus, alice.NOT_CONNECTED); LOG("disconnected"); - /* // test re-connection LOG("reconnecting"); alice.connect( jabberDomain ); @@ -48,6 +43,7 @@ function run_test() { do_check_eq( alice._connectionStatus, alice.CONNECTED); alice.disconnect(); + /* // test connection failure alice.connect( "bad domain" ); alice.waitForConnection(); diff --git a/services/sync/tests/unit/test_xmpp_simple.js b/services/sync/tests/unit/test_xmpp_simple.js index 50b01da295f8..b6b54eabd04b 100644 --- a/services/sync/tests/unit/test_xmpp_simple.js +++ b/services/sync/tests/unit/test_xmpp_simple.js @@ -4,9 +4,8 @@ function LOG(aMsg) { Components.utils.import( "resource://weave/xmpp/xmppClient.js" ); -var serverUrl = "http://127.0.0.1:5280/http-poll"; -var jabberDomain = Cc["@mozilla.org/network/dns-service;1"]. - getService(Ci.nsIDNSService).myHostName; +var serverUrl = "http://localhost:5280/http-poll"; +var jabberDomain = "localhost"; function run_test() { // FIXME: this test hangs when you don't have a server, disabling for now