← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 3193: Send passive search replies via the hub they were requested from

 

------------------------------------------------------------
revno: 3193
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Mon 2013-01-28 20:41:11 +0100
message:
  Send passive search replies via the hub they were requested from
modified:
  changelog.txt
  dcpp/AdcHub.cpp
  dcpp/ClientListener.h
  dcpp/ClientManager.cpp
  dcpp/ClientManager.h
  dcpp/HintedUser.h
  dcpp/SearchManager.cpp
  dcpp/SearchManager.h


--
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 'changelog.txt'
--- changelog.txt	2013-01-27 18:04:17 +0000
+++ changelog.txt	2013-01-28 19:41:11 +0000
@@ -25,6 +25,7 @@
 * [L#489704] Fix invalid share sizes after a directory merge (poy)
 * Satisfy some boost lockfree requirements, could fix bugs on heavy load
 * Clean up earlier after receiving zlib data (thanks irainman)
+* [ADC] Send passive search replies via the hub they were requested from (poy)
 
 Note: The hash registry will be upgraded when running this version for the
 first time. Make sure all your drives are connected to avoid re-hashing.

=== modified file 'dcpp/AdcHub.cpp'
--- dcpp/AdcHub.cpp	2013-01-18 21:28:38 +0000
+++ dcpp/AdcHub.cpp	2013-01-28 19:41:11 +0000
@@ -502,7 +502,7 @@
 		return;
 	}
 
-	fire(ClientListener::AdcSearch(), this, c, ou->getUser()->getCID());
+	fire(ClientListener::AdcSearch(), this, c, *ou);
 }
 
 void AdcHub::handle(AdcCommand::RES, AdcCommand& c) noexcept {

=== modified file 'dcpp/ClientListener.h'
--- dcpp/ClientListener.h	2013-01-18 21:28:38 +0000
+++ dcpp/ClientListener.h	2013-01-28 19:41:11 +0000
@@ -69,7 +69,7 @@
 	virtual void on(NickTaken, Client*) noexcept { }
 	virtual void on(SearchFlood, Client*, const string&) noexcept { }
 	virtual void on(NmdcSearch, Client*, const string&, int, int64_t, int, const string&) noexcept { }
-	virtual void on(AdcSearch, Client*, const AdcCommand&, const CID&) noexcept { }
+	virtual void on(AdcSearch, Client*, const AdcCommand&, const OnlineUser&) noexcept { }
 	virtual void on(ClientLine, Client*, const string& line, int type) noexcept { };
 };
 

=== modified file 'dcpp/ClientManager.cpp'
--- dcpp/ClientManager.cpp	2013-01-18 21:28:38 +0000
+++ dcpp/ClientManager.cpp	2013-01-28 19:41:11 +0000
@@ -428,21 +428,17 @@
 	ou->getClient().sendUserCmd(uc, params);
 }
 
-void ClientManager::send(AdcCommand& cmd, const CID& cid) {
-	Lock l(cs);
-	auto i = onlineUsers.find(cid);
-	if(i != onlineUsers.end()) {
-		OnlineUser& u = *i->second;
-		if(cmd.getType() == AdcCommand::TYPE_UDP && !u.getIdentity().isUdpActive()) {
-			cmd.setType(AdcCommand::TYPE_DIRECT);
-			cmd.setTo(u.getIdentity().getSID());
-			u.getClient().send(cmd);
-		} else {
-			try {
-				udp.writeTo(u.getIdentity().getIp(), u.getIdentity().getUdpPort(), cmd.toString(getMe()->getCID()));
-			} catch(const SocketException&) {
-				dcdebug("Socket exception sending ADC UDP command\n");
-			}
+void ClientManager::sendUDP(AdcCommand& cmd, const OnlineUser& user) {
+	dcassert(cmd.getType() == AdcCommand::TYPE_UDP);
+	if(!user.getIdentity().isUdpActive()) {
+		cmd.setType(AdcCommand::TYPE_DIRECT);
+		cmd.setTo(user.getIdentity().getSID());
+		const_cast<Client&>(user.getClient()).send(cmd);
+	} else {
+		try {
+			udp.writeTo(user.getIdentity().getIp(), user.getIdentity().getUdpPort(), cmd.toString(getMe()->getCID()));
+		} catch(const SocketException&) {
+			dcdebug("Socket exception sending ADC UDP command\n");
 		}
 	}
 }
@@ -504,19 +500,8 @@
 	}
 }
 
-void ClientManager::on(AdcSearch, Client*, const AdcCommand& adc, const CID& from) noexcept {
-	bool isUdpActive = false;
-	{
-		Lock l(cs);
-
-		auto i = onlineUsers.find(from);
-		if(i != onlineUsers.end()) {
-			OnlineUser& u = *i->second;
-			isUdpActive = u.getIdentity().isUdpActive();
-		}
-
-	}
-	SearchManager::getInstance()->respond(adc, from, isUdpActive);
+void ClientManager::on(AdcSearch, Client*, const AdcCommand& cmd, const OnlineUser& from) noexcept {
+	SearchManager::getInstance()->respond(cmd, from);
 }
 
 void ClientManager::search(int aSizeMode, int64_t aSize, int aFileType, const string& aString, const string& aToken) {

=== modified file 'dcpp/ClientManager.h'
--- dcpp/ClientManager.h	2013-01-18 21:28:38 +0000
+++ dcpp/ClientManager.h	2013-01-28 19:41:11 +0000
@@ -119,7 +119,7 @@
 
 	UserPtr& getMe();
 
-	void send(AdcCommand& c, const CID& to);
+	void sendUDP(AdcCommand& cmd, const OnlineUser& user);
 
 	void connect(const HintedUser& user, const string& token);
 	void privateMessage(const HintedUser& user, const string& msg, bool thirdPerson);
@@ -192,7 +192,7 @@
 	virtual void on(HubUserCommand, Client*, int, int, const string&, const string&) noexcept;
 	virtual void on(NmdcSearch, Client* aClient, const string& aSeeker, int aSearchType, int64_t aSize,
 		int aFileType, const string& aString) noexcept;
-	virtual void on(AdcSearch, Client* c, const AdcCommand& adc, const CID& from) noexcept;
+	virtual void on(AdcSearch, Client*, const AdcCommand& cmd, const OnlineUser& from) noexcept;
 	// TimerManagerListener
 	virtual void on(TimerManagerListener::Minute, uint64_t aTick) noexcept;
 };

=== modified file 'dcpp/HintedUser.h'
--- dcpp/HintedUser.h	2013-01-18 21:28:38 +0000
+++ dcpp/HintedUser.h	2013-01-28 19:41:11 +0000
@@ -22,6 +22,8 @@
 #include <string>
 
 #include "forward.h"
+#include "Client.h"
+#include "OnlineUser.h"
 #include "User.h"
 
 namespace dcpp {
@@ -33,7 +35,8 @@
 	UserPtr user;
 	string hint;
 
-	explicit HintedUser(const UserPtr& user_, const string& hint_) : user(user_), hint(hint_) { }
+	HintedUser(const UserPtr& user, const string& hint) : user(user), hint(hint) { }
+	HintedUser(const OnlineUser& ou) : HintedUser(ou.getUser(), ou.getClient().getHubUrl()) { }
 
 	bool operator==(const UserPtr& rhs) const {
 		return user == rhs;

=== modified file 'dcpp/SearchManager.cpp'
--- dcpp/SearchManager.cpp	2013-01-18 21:28:38 +0000
+++ dcpp/SearchManager.cpp	2013-01-28 19:41:11 +0000
@@ -328,30 +328,24 @@
 	}
 }
 
-void SearchManager::respond(const AdcCommand& adc, const CID& from,  bool isUdpActive) {
+void SearchManager::respond(const AdcCommand& cmd, const OnlineUser& user) {
 	// Filter own searches
-	if(from == ClientManager::getInstance()->getMe()->getCID())
-		return;
-
-	UserPtr p = ClientManager::getInstance()->findUser(from);
-	if(!p)
+	if(user.getUser() == ClientManager::getInstance()->getMe())
 		return;
 
 	SearchResultList results;
-	ShareManager::getInstance()->search(results, adc.getParameters(), isUdpActive ? 10 : 5);
-
-	string token;
-
-	adc.getParam("TO", 0, token);
-
+	ShareManager::getInstance()->search(results, cmd.getParameters(), user.getIdentity().isUdpActive() ? 10 : 5);
 	if(results.empty())
 		return;
 
+	string token;
+	cmd.getParam("TO", 0, token);
+
 	for(auto& i: results) {
-		AdcCommand cmd = i->toRES(AdcCommand::TYPE_UDP);
+		AdcCommand res = i->toRES(AdcCommand::TYPE_UDP);
 		if(!token.empty())
-			cmd.addParam("TO", token);
-		ClientManager::getInstance()->send(cmd, from);
+			res.addParam("TO", token);
+		ClientManager::getInstance()->sendUDP(res, user);
 	}
 }
 

=== modified file 'dcpp/SearchManager.h'
--- dcpp/SearchManager.h	2013-01-18 21:28:38 +0000
+++ dcpp/SearchManager.h	2013-01-28 19:41:11 +0000
@@ -69,7 +69,7 @@
 		search(who, aName, Util::toInt64(aSize), aTypeMode, aSizeMode, aToken, aExtList);
 	}
 
-	void respond(const AdcCommand& cmd, const CID& cid,  bool isUdpActive);
+	void respond(const AdcCommand& cmd, const OnlineUser& user);
 
 	const string& getPort() const { return port; }