[notifications] Reconnect to the IRC server after a disconnect
This commit is contained in:
parent
60ffb7450d
commit
bb5229d4d3
|
@ -40,28 +40,26 @@ namespace SparkleLib {
|
||||||
public SparkleListener (string server, string folder_name, string user_email)
|
public SparkleListener (string server, string folder_name, string user_email)
|
||||||
{
|
{
|
||||||
|
|
||||||
Server = server;
|
// This is SparkleShare's centralized notification service.
|
||||||
//Channel = GetSHA1 (server + folder_name);
|
// Don't worry, we only use this server as a backup if you
|
||||||
Channel = folder_name;
|
// don't have your own. All data needed to connect is hashed and
|
||||||
|
// we don't store any personal information ever.
|
||||||
|
// Server = "204.62.14.135";
|
||||||
|
|
||||||
if (!user_email.Equals ("") && user_email != null)
|
if (!user_email.Equals ("") && user_email != null)
|
||||||
Nick = GetSHA1 (user_email + "sparkles");
|
Nick = GetSHA1 (folder_name + user_email + "sparkles");
|
||||||
else
|
else
|
||||||
Nick = GetSHA1 (DateTime.Now.ToString () + "sparkles");
|
Nick = GetSHA1 (DateTime.Now.ToString () + "sparkles");
|
||||||
|
|
||||||
Nick = "s" + Nick.Substring (0, 7);
|
Nick = "s" + Nick.Substring (0, 7);
|
||||||
|
// Channel = "#" + GetSHA1 (server + folder_name);
|
||||||
|
|
||||||
// TODO: remove
|
|
||||||
Channel = "#sparkletest";
|
|
||||||
Server = "irc.gnome.org";
|
Server = "irc.gnome.org";
|
||||||
|
Channel = "#sparkletest";
|
||||||
|
|
||||||
Client = new IrcClient () {
|
Client = new IrcClient () {
|
||||||
PingTimeout = 120,
|
PingTimeout = 180,
|
||||||
SocketSendTimeout = 120,
|
PingInterval = 90
|
||||||
SocketReceiveTimeout = 120,
|
|
||||||
AutoRetry = true,
|
|
||||||
AutoReconnect = true,
|
|
||||||
AutoRejoin = true
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -308,32 +308,37 @@ namespace SparkleLib {
|
||||||
// Listen to the irc channel on the server...
|
// Listen to the irc channel on the server...
|
||||||
Listener = new SparkleListener (Domain, "#" + RemoteName, UserEmail);
|
Listener = new SparkleListener (Domain, "#" + RemoteName, UserEmail);
|
||||||
|
|
||||||
// ...fetch remote changes every 90 seconds if that fails
|
// ...fetch remote changes every 60 seconds if that fails
|
||||||
RemoteTimer = new Timer () {
|
RemoteTimer = new Timer () {
|
||||||
Interval = 90000
|
Interval = 60000
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
RemoteTimer.Elapsed += delegate {
|
RemoteTimer.Elapsed += delegate {
|
||||||
|
|
||||||
if (_IsPolling)
|
if (_IsPolling) {
|
||||||
CheckForRemoteChanges ();
|
|
||||||
|
|
||||||
if (_HasUnsyncedChanges)
|
CheckForRemoteChanges ();
|
||||||
Push ();
|
|
||||||
|
|
||||||
if (!Listener.Client.IsConnected) {
|
if (!Listener.Client.IsConnected) {
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Irc", "[" + Name + "] Trying to reconnect...");
|
SparkleHelpers.DebugInfo ("Irc", "[" + Name + "] Trying to reconnect...");
|
||||||
Listener.Client.Reconnect (true, true);
|
Listener.Listen ();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_HasUnsyncedChanges)
|
||||||
|
Push ();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Stop polling when the connection to the irc channel is succesful
|
// Stop polling when the connection to the irc channel is succesful
|
||||||
Listener.Client.OnConnected += delegate {
|
Listener.Client.OnConnected += delegate {
|
||||||
|
|
||||||
|
_IsPolling = false;
|
||||||
|
|
||||||
// Check for changes manually one more time
|
// Check for changes manually one more time
|
||||||
CheckForRemoteChanges ();
|
CheckForRemoteChanges ();
|
||||||
|
|
||||||
|
@ -341,9 +346,15 @@ namespace SparkleLib {
|
||||||
if (_HasUnsyncedChanges)
|
if (_HasUnsyncedChanges)
|
||||||
Push ();
|
Push ();
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Irc", "[" + Name + "] Connected. Now listening...");
|
SparkleHelpers.DebugInfo ("Irc", "[" + Name + "] Connected. Now listening... (" + Listener.Server + ")");
|
||||||
|
|
||||||
_IsPolling = false;
|
};
|
||||||
|
|
||||||
|
// Start polling when the connection to the irc channel is lost
|
||||||
|
Listener.Client.OnConnectionError += delegate {
|
||||||
|
|
||||||
|
SparkleHelpers.DebugInfo ("Irc", "[" + Name + "] Lost connection. Falling back to polling...");
|
||||||
|
_IsPolling = true;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -351,9 +362,7 @@ namespace SparkleLib {
|
||||||
Listener.Client.OnDisconnected += delegate {
|
Listener.Client.OnDisconnected += delegate {
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Irc", "[" + Name + "] Lost connection. Falling back to polling...");
|
SparkleHelpers.DebugInfo ("Irc", "[" + Name + "] Lost connection. Falling back to polling...");
|
||||||
|
|
||||||
_IsPolling = true;
|
_IsPolling = true;
|
||||||
CheckForRemoteChanges ();
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -361,8 +370,9 @@ namespace SparkleLib {
|
||||||
Listener.Client.OnChannelMessage += delegate (object o, IrcEventArgs args) {
|
Listener.Client.OnChannelMessage += delegate (object o, IrcEventArgs args) {
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Irc", "[" + Name + "] Was notified of a remote change.");
|
SparkleHelpers.DebugInfo ("Irc", "[" + Name + "] Was notified of a remote change.");
|
||||||
|
string message = args.Data.Message.Trim ();
|
||||||
|
|
||||||
if (!args.Data.Message.Equals (_CurrentHash)) {
|
if (!message.Equals (_CurrentHash) && message.Length == 40) {
|
||||||
|
|
||||||
FetchRequests++;
|
FetchRequests++;
|
||||||
|
|
||||||
|
@ -406,9 +416,7 @@ namespace SparkleLib {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
if (_IsPolling)
|
|
||||||
RemoteTimer.Start ();
|
RemoteTimer.Start ();
|
||||||
|
|
||||||
LocalTimer.Start ();
|
LocalTimer.Start ();
|
||||||
|
|
||||||
// Add everything that changed
|
// Add everything that changed
|
||||||
|
@ -555,9 +563,7 @@ namespace SparkleLib {
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
|
||||||
if (_IsPolling)
|
|
||||||
RemoteTimer.Start ();
|
RemoteTimer.Start ();
|
||||||
|
|
||||||
LocalTimer.Start ();
|
LocalTimer.Start ();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -678,8 +684,6 @@ namespace SparkleLib {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (_IsPolling)
|
|
||||||
RemoteTimer.Start ();
|
RemoteTimer.Start ();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -989,8 +993,8 @@ namespace SparkleLib {
|
||||||
|
|
||||||
if (entry_line.StartsWith (":")) {
|
if (entry_line.StartsWith (":")) {
|
||||||
|
|
||||||
string change_type = entry_line.Substring (37, 1);
|
string change_type = entry_line [37].ToString ();
|
||||||
string file_path = entry_line.Substring (39, entry_line.Length - 39);
|
string file_path = entry_line.Substring (39);
|
||||||
|
|
||||||
if (change_type.Equals ("A")) {
|
if (change_type.Equals ("A")) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue