2012-02-06 12:45:20 +00:00
|
|
|
// SparkleShare, a collaboration and sharing tool.
|
2017-07-23 12:47:54 +00:00
|
|
|
// Copyright (C) 2010 Hylke Bons <hi@planetpeanut.uk>
|
2012-02-06 12:45:20 +00:00
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
2013-10-11 15:13:46 +00:00
|
|
|
// it under the terms of the GNU Lesser General Public License as
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
// License, or (at your option) any later version.
|
2012-02-06 12:45:20 +00:00
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
2016-03-31 08:35:26 +00:00
|
|
|
namespace Sparkles {
|
2012-02-06 12:45:20 +00:00
|
|
|
|
2016-03-30 23:36:31 +00:00
|
|
|
public static class ListenerFactory {
|
2012-02-06 12:45:20 +00:00
|
|
|
|
2016-03-31 18:30:58 +00:00
|
|
|
static readonly List<BaseListener> listeners = new List<BaseListener> ();
|
2012-02-06 12:45:20 +00:00
|
|
|
|
|
|
|
|
2016-03-30 23:36:31 +00:00
|
|
|
public static BaseListener CreateListener (string folder_name, string folder_identifier)
|
2012-02-06 12:45:20 +00:00
|
|
|
{
|
|
|
|
// Check if the user wants to use a global custom notification service
|
2016-04-08 15:57:11 +00:00
|
|
|
string uri = Configuration.DefaultConfiguration.GetConfigOption ("announcements_url");
|
2012-02-06 12:45:20 +00:00
|
|
|
|
|
|
|
// Check if the user wants a use a custom notification service for this folder
|
|
|
|
if (string.IsNullOrEmpty (uri))
|
2016-04-08 15:57:11 +00:00
|
|
|
uri = Configuration.DefaultConfiguration.GetFolderOptionalAttribute (folder_name, "announcements_url");
|
2012-07-18 21:12:51 +00:00
|
|
|
|
|
|
|
// This is SparkleShare's centralized notification service.
|
|
|
|
// It communicates "It's time to sync!" signals between clients.
|
|
|
|
//
|
|
|
|
// Please see the SparkleShare wiki if you wish to run
|
|
|
|
// your own service instead
|
|
|
|
if (string.IsNullOrEmpty (uri))
|
2016-03-31 18:30:58 +00:00
|
|
|
uri = "tcp://announcements.sparkleshare.org:443";
|
2012-02-06 12:45:20 +00:00
|
|
|
|
2016-03-31 18:30:58 +00:00
|
|
|
var announce_uri = new Uri (uri);
|
2012-02-06 12:45:20 +00:00
|
|
|
|
2012-07-27 09:55:11 +00:00
|
|
|
// Use only one listener per notification service to keep
|
2012-02-06 12:45:20 +00:00
|
|
|
// the number of connections as low as possible
|
2016-03-30 23:36:31 +00:00
|
|
|
foreach (BaseListener listener in listeners) {
|
2012-02-06 12:45:20 +00:00
|
|
|
if (listener.Server.Equals (announce_uri)) {
|
2016-03-30 23:36:31 +00:00
|
|
|
Logger.LogInfo ("ListenerFactory", "Refered to existing listener for " + announce_uri);
|
2012-02-06 12:45:20 +00:00
|
|
|
|
|
|
|
// We already seem to have a listener for this server,
|
|
|
|
// refer to the existing one instead
|
2012-02-11 19:23:38 +00:00
|
|
|
listener.AlsoListenTo (folder_identifier);
|
2016-03-31 18:30:58 +00:00
|
|
|
return listener;
|
2012-02-06 12:45:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-30 23:36:31 +00:00
|
|
|
listeners.Add (new TcpListener (announce_uri, folder_identifier));
|
|
|
|
Logger.LogInfo ("ListenerFactory", "Issued new listener for " + announce_uri);
|
2012-02-06 12:45:20 +00:00
|
|
|
|
2016-03-31 18:30:58 +00:00
|
|
|
return listeners [listeners.Count - 1];
|
2012-02-06 12:45:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|