Changeset - 28ca4ba95e42
[Not reviewed]
0 4 0
HanzZ - 14 years ago 2011-06-19 10:37:01
hanzz.k@gmail.com
Do not start XMPP server before first backend is connected
4 files changed with 29 insertions and 11 deletions:
0 comments (0 inline, 0 general)
include/transport/transport.h
Show inline comments
 
@@ -104,14 +104,14 @@ namespace Transport {
 
			/// \param barejid User's bare JID.
 
			/// \return User's password.
 
			const std::string &getUserRegistryPassword(const std::string &barejid);
 

	
 
			/// 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.
 
			
 
			/// This sets features of transport contact (For example "j2j.domain.tld").
 
			/// \param features list of features as sent in disco#info response
 
			void setTransportFeatures(std::list<std::string> &features);
spectrum/src/main.cpp
Show inline comments
 
@@ -71,9 +71,8 @@ int main(int argc, char **argv)
 
		logger.setUserRegistration(&userRegistration);
 
	}
 
	logger.setUserManager(&userManager);
 
 
	NetworkPluginServer plugin(&transport, &config, &userManager);
 
 
	transport.connect();
 
	eventLoop.run();
 
}
src/networkpluginserver.cpp
Show inline comments
 
@@ -152,12 +152,17 @@ NetworkPluginServer::~NetworkPluginServer() {
 

	
 
void NetworkPluginServer::handleNewClientConnection(boost::shared_ptr<Swift::Connection> c) {
 
	Client *client = new Client;
 
	client->pongReceived = 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));
 
	c->onDataRead.connect(boost::bind(&NetworkPluginServer::handleDataRead, this, client, _1));
 
	sendPing(client);
 
	m_pingTimer->start();
src/transport.cpp
Show inline comments
 
@@ -64,22 +64,22 @@ Component::Component(Swift::EventLoop *loop, Config *config, Factory *factory) {
 

	
 
	m_jid = Swift::JID(CONFIG_STRING(m_config, "service.jid"));
 

	
 
	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);
 
		m_server = new Swift::Server(loop, m_factories, m_userRegistry, m_jid, CONFIG_INT(m_config, "service.port"));
 
		if (!CONFIG_STRING(m_config, "service.cert").empty()) {
 
			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();
 

	
 
		m_server->addPayloadParserFactory(new GenericPayloadParserFactory<StorageParser>("private", "jabber:iq:private"));
 

	
 
		m_server->onDataRead.connect(bind(&Component::handleDataRead, this, _1));
 
@@ -149,18 +149,32 @@ void Component::setTransportFeatures(std::list<std::string> &features) {
 

	
 
void Component::setBuddyFeatures(std::list<std::string> &features) {
 
	// TODO: handle caps change
 
	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() {
 
	onConnected();
 
	m_reconnectCount = 0;
 
}
0 comments (0 inline, 0 general)