[polari/wip/kunaljain/multiple-server] debug: multiple server support
- From: Kunal Jain <kunaljain src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari/wip/kunaljain/multiple-server] debug: multiple server support
- Date: Thu, 31 Mar 2016 20:12:35 +0000 (UTC)
commit a8572bfd895b5682c537395a2d55cd6460beffbc
Author: Kunaal Jain <kunaalus gmail com>
Date: Fri Apr 1 01:40:32 2016 +0530
debug: multiple server support
src/application.js | 45 ++++++++++++++++++++++++++++++++++++++++++---
src/networksManager.js | 7 +++++++
2 files changed, 49 insertions(+), 3 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index b6fa847..47b328a 100644
--- a/src/application.js
+++ b/src/application.js
@@ -347,10 +347,23 @@ const Application = new Lang.Class({
account.update_parameters_vardict_async(asv, [], callback);
},
+ _updateAccountServer: function(account, serverad, callback) {
+ print(serverad.address);
+ let sv = { server: GLib.Variant.new('s', serverad.address),
+ port: GLib.Variant.new('u', serverad.port) };
+ let asv = GLib.Variant.new('a{sv}', sv);
+ account.update_parameters_vardict_async(asv, [], callback);
+ },
+
_requestChannel: function(accountPath, targetType, targetId, time, callback) {
// have this in AccountMonitor?
let factory = Tp.AccountManager.dup().get_factory();
let account = factory.ensure_account(accountPath, []);
+ let servers = [];
+ if (this._networksManager.getAccountIsPredefined(account)) {
+ servers = this._networksManager.getNetworkServers(account.service);
+ print(servers.length);
+ }
if (!account.enabled) {
// if we are requesting a channel for a disabled account, we
@@ -375,7 +388,10 @@ const Application = new Lang.Class({
time: time,
retry: 0,
originalNick: account.nickname,
- callback: callback };
+ callback: callback,
+ servers: servers,
+ retryServer: 0
+ };
this._pendingRequests[roomId] = requestData;
@@ -407,6 +423,19 @@ const Application = new Lang.Class({
}));
},
+ _retryServerRequest: function(requestData) {
+ print("retrying");
+ print(requestData.retryServer);
+ let account = requestData.account;
+
+ // Try again with a different nick
+ let server = requestData.servers[requestData.retryServer];
+ this._updateAccountServer(account, server, Lang.bind(this,
+ function() {
+ this._ensureChannel(requestData);
+ }));
+ },
+
_onEnsureChannel: function(req, res, requestData) {
let account = req.account;
let channel = null;
@@ -414,22 +443,32 @@ const Application = new Lang.Class({
try {
channel = req.ensure_and_observe_channel_finish(res);
} catch (e if e.matches(Tp.Error, Tp.Error.DISCONNECTED)) {
+ print("Some error");
let error = account.connection_error;
// If we receive a disconnect error and the network is unavailable,
// then the error is not specific to polari and polari will
// just be in offline state.
- if (!this._networkMonitor.network_available)
+ if (!this._networkMonitor.network_available){
+ print("no network");
return;
+ }
if (error == ConnectionError.ALREADY_CONNECTED &&
requestData.retry++ < MAX_RETRIES) {
+ print("trying nick");
this._retryRequest(requestData);
return;
}
- if (error && error != ConnectionError.CANCELLED)
+ if (error && error != ConnectionError.CANCELLED) {
+ if (++requestData.retryServer < requestData.servers.length) {
+ this._retryServerRequest(requestData);
+ return;
+ }
+ print("gave up");
Utils.debug('Account %s disconnected with error %s'.format(
account.get_path_suffix(),
error.replace(Tp.ERROR_PREFIX + '.', '')));
+ }
} catch (e if e.matches(Tp.Error, Tp.Error.CANCELLED)) {
// interrupted by user request, don't log
} catch (e) {
diff --git a/src/networksManager.js b/src/networksManager.js
index 6b04261..2cd9313 100644
--- a/src/networksManager.js
+++ b/src/networksManager.js
@@ -84,6 +84,13 @@ const NetworksManager = new Lang.Class({
};
},
+ getNetworkServers: function(id) {
+ let network = this._lookupNetwork(id);
+ let sslServers = network.servers.filter(s => s.ssl);
+ return sslServers.length > 0 ? sslServers
+ : network.servers;
+ },
+
getNetworkMatchTerms: function(id) {
let network = this._lookupNetwork(id);
let servers = network.servers.map(function(s) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]