← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 3195: use a regular counter to identify hubs in search tokens rather than a pointer

 

------------------------------------------------------------
revno: 3195
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Tue 2013-01-29 16:38:58 +0100
message:
  use a regular counter to identify hubs in search tokens rather than a pointer
modified:
  dcpp/AdcHub.cpp
  dcpp/Client.cpp
  dcpp/Client.h
  dcpp/SearchManager.cpp


--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'dcpp/AdcHub.cpp'
--- dcpp/AdcHub.cpp	2013-01-28 21:32:53 +0000
+++ dcpp/AdcHub.cpp	2013-01-29 15:38:58 +0000
@@ -811,10 +811,10 @@
 
 	AdcCommand c(AdcCommand::CMD_SCH, AdcCommand::TYPE_BROADCAST);
 
-	/* token format: [pointer to this class] "/" [actual token]
+	/* token format: [per-hub unique id] "/" [per-search actual token]
 	this allows easily knowing which hub a search was sent on when parsing a search result,
 	whithout having to bother maintaining a list of sent tokens. */
-	c.addParam("TO", Util::toString(reinterpret_cast<uintptr_t>(this)) + "/" + aToken);
+	c.addParam("TO", Util::toString(getUniqueId()) + "/" + aToken);
 
 	if(aFileType == SearchManager::TYPE_TTH) {
 		c.addParam("TR", aString);

=== modified file 'dcpp/Client.cpp'
--- dcpp/Client.cpp	2013-01-18 21:28:38 +0000
+++ dcpp/Client.cpp	2013-01-29 15:38:58 +0000
@@ -33,8 +33,10 @@
 
 atomic<long> Client::counts[COUNT_UNCOUNTED];
 
+uint32_t idCounter = 0;
+
 Client::Client(const string& hubURL, char separator_, bool secure_) :
-	myIdentity(ClientManager::getInstance()->getMe(), 0),
+	myIdentity(ClientManager::getInstance()->getMe(), 0), uniqueId(++idCounter),
 	reconnDelay(120), lastActivity(GET_TICK()), registered(false), autoReconnect(false),
 	encoding(Text::systemCharset), state(STATE_DISCONNECTED), sock(0),
 	hubUrl(hubURL),separator(separator_),

=== modified file 'dcpp/Client.h'
--- dcpp/Client.h	2013-01-18 21:28:38 +0000
+++ dcpp/Client.h	2013-01-29 15:38:58 +0000
@@ -100,6 +100,7 @@
 	GETSET(Identity, myIdentity, MyIdentity);
 	GETSET(Identity, hubIdentity, HubIdentity);
 
+	GETSET(uint32_t, uniqueId, UniqueId);
 	GETSET(string, defpassword, Password);
 	GETSET(uint32_t, reconnDelay, ReconnDelay);
 	GETSET(uint64_t, lastActivity, LastActivity);

=== modified file 'dcpp/SearchManager.cpp'
--- dcpp/SearchManager.cpp	2013-01-28 21:32:53 +0000
+++ dcpp/SearchManager.cpp	2013-01-29 15:38:58 +0000
@@ -19,6 +19,7 @@
 #include "stdinc.h"
 #include "SearchManager.h"
 
+#include <boost/range/algorithm/find_if.hpp>
 #include <boost/scoped_array.hpp>
 
 #include "ClientManager.h"
@@ -316,13 +317,14 @@
 
 	string hubUrl;
 
-	// token format: [pointer to the client class] "/" [actual token] (see AdcHub::search)
+	// token format: [per-hub unique id] "/" [per-search actual token] (see AdcHub::search)
 	auto slash = token.find('/');
 	if(slash == string::npos) { return; }
 	{
+		auto uniqueId = Util::toUInt32(token.substr(0, slash));
 		auto lock = ClientManager::getInstance()->lock();
 		auto& clients = ClientManager::getInstance()->getClients();
-		auto i = clients.find(reinterpret_cast<Client*>(Util::toInt64(token.substr(0, slash))));
+		auto i = boost::find_if(clients, [uniqueId](const Client* client) { return client->getUniqueId() == uniqueId; });
 		if(i == clients.end()) { return; }
 		hubUrl = (*i)->getHubUrl();
 	}