From a481538836754525afc19da97ef3a44c7216915e Mon Sep 17 00:00:00 2001 From: HanzZ Date: Thu, 8 Sep 2011 16:15:41 +0200 Subject: [PATCH] Config file tweaks --- spectrum/src/sample2.cfg | 91 +++++++++++++++++++++++++++++++------ src/config.cpp | 2 +- src/networkpluginserver.cpp | 38 ++++++++-------- 3 files changed, 98 insertions(+), 33 deletions(-) diff --git a/spectrum/src/sample2.cfg b/spectrum/src/sample2.cfg index 0dedd646..d4e5b417 100644 --- a/spectrum/src/sample2.cfg +++ b/spectrum/src/sample2.cfg @@ -1,25 +1,88 @@ [service] -jid = localhost -password = secret -server = 127.0.0.1 -port = 5222 +# 1 if Spectrum should run in server mode. server_mode = 1 -backend_host=localhost # < this option doesn't work yet + +# JID of Spectrum instance. +jid = localhost + +# Password used to connect the XMPP server in gateway mode. +# In server mode, this option is ignored. +password = secret + +# XMPP server to which Spectrum connects in gateway mode. +# In server mode, this option is ignored. +server = 127.0.0.1 + +# XMPP server port. +port = 5222 + +# Interface on which Spectrum listens for backends. +backend_host = localhost + +# Port on which Spectrum listens for backends. backend_port=10001 -#cert= #patch to PKCS#12 certificate -#cert_password= #password to that certificate if any -users_per_backend=1 -backend=spectrum_libpurple_backend -#backend=spectrum_libircclient-qt_backend + +# Full path to PKCS#12 cetficiate used for TLS in server mode. +#cert= + +# Certificate password if any. +#cert_password= + +# Number of users per one legacy network backend. +users_per_backend=10 + +# Full path to backend binary. +backend=/usr/bin/spectrum_libpurple_backend +#backend=/usr/bin/spectrum_libircclient-qt_backend + +# Libpurple protocol-id for spectrum_libpurple_backend protocol=prpl-jabber #protocol=prpl-msn #protocol=prpl-icq +# prpl-any means that user sets his protocol in his JID which has to be +# in following format: protocol.username@domain.tld +# So for example: prpl-jabber.hanzz.k%gmail.com@domain.tld +#protocol=prpl-any + +[identity] +# Name of Spectrum instance in service discovery +name=Spectrum Jabber Transport + +# Type of transport ("msn", "icq", "xmpp"). +# Check http://xmpp.org/registrar/disco-categories.html#gateway +type=xmpp + +# Category of transport, default is "gateway +#category=gateway + [logging] -#config=logging.cfg # log4cxx/log4j logging configuration file +# log4cxx/log4j logging configuration file in ini format used for main spectrum2 instance. +#config = logging.cfg + +# log4cxx/log4j logging configuration file in ini format used for backends. #backend_config=backend_logging.cfg # log4cxx/log4j logging configuration file for backends [database] -type = none # "sqlite3" or "none" without database backend -database = test.sql -#prefix=icq +# Database backend type +# "sqlite3", "mysql" or "none" without database backend +type = none + +# For SQLite3: Full path to database +# For MySQL: name of database +database = jabber_transport + +# Server. +server = localhost + +# Port. +port = 0 + +# User. +user = spectrum + +# Paasword. +password = secret + +# Prefix used for tables +prefix = jabber_ diff --git a/src/config.cpp b/src/config.cpp index 5999af3e..82f3aa47 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -62,7 +62,7 @@ bool Config::load(std::istream &ifs, boost::program_options::options_description ("service.admin_username", value()->default_value(""), "Administrator username.") ("service.admin_password", value()->default_value(""), "Administrator password.") ("service.reuse_old_backends", value()->default_value(true), "True if Spectrum should use old backends which were full in the past.") - ("service.idle_reconnect_time", value()->default_value(4*3600), "Time in seconds after which idle users are reconnected to let their backend die.") + ("service.idle_reconnect_time", value()->default_value(0), "Time in seconds after which idle users are reconnected to let their backend die.") ("service.more_resources", value()->default_value(false), "Allow more resources to be connected in server mode at the same time.") ("identity.name", value()->default_value("Spectrum 2 Transport"), "Name showed in service discovery.") ("identity.category", value()->default_value("gateway"), "Disco#info identity category. 'gateway' by default.") diff --git a/src/networkpluginserver.cpp b/src/networkpluginserver.cpp index cfc25c8f..47f31ba3 100644 --- a/src/networkpluginserver.cpp +++ b/src/networkpluginserver.cpp @@ -669,30 +669,32 @@ void NetworkPluginServer::pingTimeout() { // Some users are connected for weeks and they are blocking backend to be destroyed and its memory // to be freed. We are finding users who are inactive for more than "idle_reconnect_time" seconds and // reconnect them to long-running backend, where they can idle hapilly till the end of ages. - time_t now = time(NULL); - std::vector usersToMove; unsigned long diff = CONFIG_INT(m_config, "service.idle_reconnect_time"); - for (std::list::const_iterator it = m_clients.begin(); it != m_clients.end(); it++) { - // Users from long-running backends can't be moved - if ((*it)->longRun) { - continue; - } + if (diff != 0) { + time_t now = time(NULL); + std::vector usersToMove; + + for (std::list::const_iterator it = m_clients.begin(); it != m_clients.end(); it++) { + // Users from long-running backends can't be moved + if ((*it)->longRun) { + continue; + } - // Find users which are inactive for more than 'diff' - BOOST_FOREACH(User *u, (*it)->users) { - if (now - u->getLastActivity() > diff) { - usersToMove.push_back(u); + // Find users which are inactive for more than 'diff' + BOOST_FOREACH(User *u, (*it)->users) { + if (now - u->getLastActivity() > diff) { + usersToMove.push_back(u); + } } } - } - // Move inactive users to long-running backend. - BOOST_FOREACH(User *u, usersToMove) { - LOG4CXX_INFO(logger, "Moving user " << u->getJID().toString() << " to long-running backend"); - if (!moveToLongRunBackend(u)) - break; + // Move inactive users to long-running backend. + BOOST_FOREACH(User *u, usersToMove) { + LOG4CXX_INFO(logger, "Moving user " << u->getJID().toString() << " to long-running backend"); + if (!moveToLongRunBackend(u)) + break; + } } - // check ping responses