diff --git a/include/transport/transport.h b/include/transport/transport.h index b7bd92ef..c0babb17 100644 --- a/include/transport/transport.h +++ b/include/transport/transport.h @@ -107,8 +107,8 @@ namespace Transport { /// Connects the Jabber server. - /// In server mode this function does nothing. - void connect(); + void start(); + void stop(); /// Sets disco#info features which are sent as answer to disco#info IQ-get. diff --git a/spectrum/src/main.cpp b/spectrum/src/main.cpp index 679ac336..dc513959 100644 --- a/spectrum/src/main.cpp +++ b/spectrum/src/main.cpp @@ -74,6 +74,5 @@ int main(int argc, char **argv) NetworkPluginServer plugin(&transport, &config, &userManager); - transport.connect(); eventLoop.run(); } diff --git a/src/networkpluginserver.cpp b/src/networkpluginserver.cpp index ebbe874d..3ad86e73 100644 --- a/src/networkpluginserver.cpp +++ b/src/networkpluginserver.cpp @@ -155,6 +155,11 @@ void NetworkPluginServer::handleNewClientConnection(boost::shared_ptrpongReceived = true; client->connection = c; + if (m_clients.size() == 0) { + // first backend connected, start the server, we're ready. + m_component->start(); + } + m_clients.push_back(client); c->onDisconnected.connect(boost::bind(&NetworkPluginServer::handleSessionFinished, this, client)); diff --git a/src/transport.cpp b/src/transport.cpp index 3d79ae86..ff128ae0 100644 --- a/src/transport.cpp +++ b/src/transport.cpp @@ -67,7 +67,7 @@ Component::Component(Swift::EventLoop *loop, Config *config, Factory *factory) { m_factories = new BoostNetworkFactories(loop); m_reconnectTimer = m_factories->getTimerFactory()->createTimer(1000); - m_reconnectTimer->onTick.connect(bind(&Component::connect, this)); + m_reconnectTimer->onTick.connect(bind(&Component::start, this)); if (CONFIG_BOOL(m_config, "service.server_mode")) { m_userRegistry = new MyUserRegistry(this); @@ -76,7 +76,7 @@ Component::Component(Swift::EventLoop *loop, Config *config, Factory *factory) { TLSServerContextFactory *f = new OpenSSLServerContextFactory(); m_server->addTLSEncryption(f, PKCS12Certificate(CONFIG_STRING(m_config, "service.cert"), createSafeByteArray(CONFIG_STRING(m_config, "service.cert_password")))); } - m_server->start(); +// m_server->start(); m_stanzaChannel = m_server->getStanzaChannel(); m_iqRouter = m_server->getIQRouter(); @@ -152,12 +152,26 @@ void Component::setBuddyFeatures(std::list &features) { m_discoInfoResponder->setBuddyFeatures(features); } -void Component::connect() { - if (!m_component) - return; - m_reconnectCount++; - m_component->connect(CONFIG_STRING(m_config, "service.server"), CONFIG_INT(m_config, "service.port")); - m_reconnectTimer->stop(); +void Component::start() { + if (m_component) { + m_reconnectCount++; + m_component->connect(CONFIG_STRING(m_config, "service.server"), CONFIG_INT(m_config, "service.port")); + m_reconnectTimer->stop(); + } + else if (m_server) { + m_server->start(); + } +} + +void Component::stop() { + if (m_component) { + m_reconnectCount = 0; + m_component->disconnect(); + m_reconnectTimer->stop(); + } + else if (m_server) { + m_server->stop(); + } } void Component::handleConnected() {