Changeset - 97a6609c8731
[Not reviewed]
0 4 0
HanzZ - 14 years ago 2011-12-07 18:20:28
hanzz.k@gmail.com
maybe working auto-reconnect
4 files changed with 22 insertions and 3 deletions:
0 comments (0 inline, 0 general)
include/Swiften/Elements/SpectrumErrorPayload.h
Show inline comments
 
@@ -31,7 +31,7 @@ namespace Swift {
 
				CONNECTION_ERROR_CERT_FINGERPRINT_MISMATCH = 13,
 
				CONNECTION_ERROR_CERT_SELF_SIGNED = 14,
 
				CONNECTION_ERROR_CERT_OTHER_ERROR = 15,
 
				CONNECTION_ERROR_OTHER_ERROR = 16,
 
				CONNECTION_ERROR_OTHER_ERROR = 16
 
			};
 

	
 
			SpectrumErrorPayload(Error error = CONNECTION_ERROR_OTHER_ERROR);
include/transport/networkpluginserver.h
Show inline comments
 
@@ -55,6 +55,7 @@ class NetworkPluginServer {
 
			unsigned long shared;
 
			bool acceptUsers;
 
			bool longRun;
 
			bool willDie;
 
		};
 

	
 
		NetworkPluginServer(Component *component, Config *config, UserManager *userManager, FileTransferManager *ftManager);
src/networkpluginserver.cpp
Show inline comments
 
@@ -288,6 +288,7 @@ void NetworkPluginServer::handleNewClientConnection(boost::shared_ptr<Swift::Con
 
	client->res = 0;
 
	client->init_res = 0;
 
	client->shared = 0;
 
	client->willDie = 0;
 
	// Backend does not accept new clients automatically if it's long-running
 
	client->acceptUsers = !m_isNextLongRun;
 
	client->longRun = m_isNextLongRun;
 
@@ -336,6 +337,9 @@ void NetworkPluginServer::handleNewClientConnection(boost::shared_ptr<Swift::Con
 
void NetworkPluginServer::handleSessionFinished(Backend *c) {
 
	LOG4CXX_INFO(logger, "Backend " << c << " disconnected. Current backend count=" << (m_clients.size() - 1));
 

	
 
	// This backend will do, so we can't reconnect users to it in User::handleDisconnected call
 
	c->willDie = true;
 

	
 
	// If there are users associated with this backend, it must have crashed, so print error output
 
	// and disconnect users
 
	for (std::list<User *>::const_iterator it = c->users.begin(); it != c->users.end(); it++) {
 
@@ -935,7 +939,7 @@ void NetworkPluginServer::handleUserCreated(User *user) {
 
	user->setData(c);
 
	c->users.push_back(user);
 

	
 
// 	UserInfo userInfo = user->getUserInfo();
 
	// Don't forget to disconnect these in handleUserDestroyed!!!
 
	user->onReadyToConnect.connect(boost::bind(&NetworkPluginServer::handleUserReadyToConnect, this, user));
 
	user->onPresenceChanged.connect(boost::bind(&NetworkPluginServer::handleUserPresenceChanged, this, user, _1));
 
	user->onRoomJoined.connect(boost::bind(&NetworkPluginServer::handleRoomJoined, this, user, _1, _2, _3, _4));
 
@@ -1054,6 +1058,11 @@ void NetworkPluginServer::handleUserDestroyed(User *user) {
 
	m_waitingUsers.remove(user);
 
	UserInfo userInfo = user->getUserInfo();
 

	
 
	user->onReadyToConnect.disconnect(boost::bind(&NetworkPluginServer::handleUserReadyToConnect, this, user));
 
	user->onPresenceChanged.disconnect(boost::bind(&NetworkPluginServer::handleUserPresenceChanged, this, user, _1));
 
	user->onRoomJoined.disconnect(boost::bind(&NetworkPluginServer::handleRoomJoined, this, user, _1, _2, _3, _4));
 
	user->onRoomLeft.disconnect(boost::bind(&NetworkPluginServer::handleRoomLeft, this, user, _1));
 

	
 
	pbnetwork::Logout logout;
 
	logout.set_user(user->getJID().toBare());
 
	logout.set_legacyname(userInfo.uin);
 
@@ -1352,7 +1361,7 @@ NetworkPluginServer::Backend *NetworkPluginServer::getFreeClient(bool acceptUser
 

	
 
	// Check all backends and find free one
 
	for (std::list<Backend *>::const_iterator it = m_clients.begin(); it != m_clients.end(); it++) {
 
		if ((*it)->acceptUsers == acceptUsers && (*it)->users.size() < CONFIG_INT(m_config, "service.users_per_backend") && (*it)->connection && (*it)->longRun == longRun) {
 
		if ((*it)->willDie == false && (*it)->acceptUsers == acceptUsers && (*it)->users.size() < CONFIG_INT(m_config, "service.users_per_backend") && (*it)->connection && (*it)->longRun == longRun) {
 
			c = *it;
 
			// if we're not reusing all backends and backend is full, stop accepting new users on this backend
 
			if (!CONFIG_BOOL(m_config, "service.reuse_old_backends")) {
src/user.cpp
Show inline comments
 
@@ -322,6 +322,15 @@ void User::handleDisconnected(const std::string &error, Swift::SpectrumErrorPayl
 
		return;
 
	}
 

	
 
	if (e == Swift::SpectrumErrorPayload::CONNECTION_ERROR_OTHER_ERROR || e == Swift::SpectrumErrorPayload::CONNECTION_ERROR_NETWORK_ERROR) {
 
		LOG4CXX_INFO(logger, m_jid.toString() << ": Disconnecting from legacy network, trying to reconnect automatically.");
 
		// Simulate destruction/resurrection :)
 
		// TODO: If this stops working, create onReconnect signal
 
		m_userManager->onUserDestroyed(this);
 
		m_userManager->onUserCreated(this);
 
		return;
 
	}
 

	
 
	if (error.empty()) {
 
		LOG4CXX_INFO(logger, m_jid.toString() << ": Disconnected from legacy network");
 
	}
0 comments (0 inline, 0 general)