adding threaded check

Problems compiling? Don't understand the source code? Don't know how to code your feature? Post here.

Moderator: Moderators

Locked
adrian_007
Posts: 32
Joined: 2006-03-06 10:54
Location: Poland

adding threaded check

Post by adrian_007 » 2006-11-15 11:29

hi all, i want to add threaded checker to dc, and i have some problem. i try to use hash map (?) from client manager, and it works, but it have bug that i cant find/repair.
1 hub - test clients /dont check filelists
2 hub - dont test clients/ check filelists
when i connect to those hubs, checker check clients AND filelists on both hubs.
can someone help? :)

riped from dcdm/zion:

Code: Select all

int Client::ThreadedCheck::run() {
	setThreadPriority(Thread::LOW);
	ClientManager* cm = ClientManager::getInstance();
	OnlineUser* ou = NULL;

[some code....]

for(ClientManager::OnlineIter i = cm->onlineUsers.begin(); i != cm->onlineUsers.end(); i++) {
ou = i->second;
	if(ou->getIdentity().getUnchecked()) {
		if(client->getCheckClients()) {
			iterBreak = true;
			try {
				QueueManager::getInstance()->addTestSUR(ou->getUser(), false);
				break;
			} catch(...) {
				dcdebug("Exception adding testsur: %s\n", i->second->getIdentity().getNick());
			}
		}
		if(client->getCheckFilelists()) {
			try {
				QueueManager::getInstance()->addList(ou->getUser(), QueueItem::FLAG_CHECK_FILE_LIST);
			} catch(...) {
				dcdebug("Exception adding filelist: %s\n", i->second->getIdentity().getNick());
			}
			break;
		}
	}
}
[...]
thx

GargoyleMT
DC++ Contributor
Posts: 3212
Joined: 2003-01-07 21:46
Location: .pa.us

Post by GargoyleMT » 2006-11-19 15:04

Is it intentional that you're using a mix of "ou" and "client"? That seems like bad organization, if the settings are per-hub. Also, have you looked at where you're initializing the variables, to make sure they're not set to true?

adrian_007
Posts: 32
Joined: 2006-03-06 10:54
Location: Poland

Post by adrian_007 » 2006-11-19 17:50

thanks for reply... so, i check something and i think bools are not mix, this is the problem with getting nick for check i think... but let take a look:
for update settings on connect: [client.cpp]

Code: Select all

void Client::reloadSettings(bool updateNick) { [...]
// CDM START
setUserProtected(hub->getUserProtected());
setCheckOnConnect(hub->getCheckOnConnect());
setCheckClients(hub->getCheckClients());
setCheckFilelists(hub->getCheckFilelists());
// CDM END
to start check and set client [Client* client defined in client.h, private]

Code: Select all

void Client::ThreadedCheck::startCheck(Client* c) {
	client = c;
	start();
}
void for start thread and update settings

Code: Select all

void startCheckOnConnect(bool checkC, bool checkF) {
		if(!checker.isChecking()) {
			checker.setCheckClients(checkC);
			checker.setCheckFilelists(checkF);
			checker.setCheckOnConnect(true);
			checker.startCheck(this);
		}
	}
for start check on connect [in nmdchub.cpp]

Code: Select all

if(ou.getUser() == getMyIdentity().getUser()) {
setMyIdentity(ou.getIdentity());
	if(getCheckOnConnect()) {
		startCheckOnConnect(getCheckClients(), getCheckFilelists());
	}
}
/*clean it up*/
}
to get nicks i use

Code: Select all

	typedef HASH_MULTIMAP_X(CID, OnlineUser*, CID::Hash, equal_to<CID>, less<CID>) OnlineMap;
	typedef OnlineMap::const_iterator OnlineIter;
	typedef pair<OnlineIter> OnlinePair;
	OnlineMap onlineUsers;
from client manager, and i think that make problem...?
also for check getting settings fro each hub i add

Code: Select all

if(client->getCheckClients()) {  [...]
LogManager::getInstance()->message(client->getHubName() + " " + i->second->getIdentity().getNick() + "(client)");
}
[...]
if(client->getCheckFilelists()) { [...]
LogManager::getInstance()->message(client->getHubName() + " " + i->second->getIdentity().getNick() + "(list)");
}
and it show normal settings for each hub, but users are not good :P for example:
i connect to x and y hub, on x i check client, on y i check filelist and on x hub i check a,b,c users and on y e,f,g users and i get msgs in log like:
x[first hub] e[user from second hub] (client)
y[second] a[user from first hub] (filelist)
i hope you will understand this mess :)

GargoyleMT
DC++ Contributor
Posts: 3212
Joined: 2003-01-07 21:46
Location: .pa.us

Post by GargoyleMT » 2006-12-06 19:15

adrian_007 wrote:i hope you will understand this mess :)
No, sorry!

adrian_007
Posts: 32
Joined: 2006-03-06 10:54
Location: Poland

Post by adrian_007 » 2006-12-07 15:13

so do it in other way... cos i think this is problem with getting users [checker gets all users from all hubs for each check settings] tell me how i can create own hash_map and use it? for ex. i put it in OnlineUser in User.h
example; in user.h

Code: Select all

	typedef HASH_MAP_X(string*, OnlineUser*, noCaseStringHash, noCaseStringEq, noCaseStringLess) NickMap;
	typedef NickMap::const_iterator NickIter;
and in client.h

Code: Select all

OnlineUser::NickMap users;
to use it, in client.cpp

Code: Select all

for(OnlineUser::NickIter i = client->users.begin(); i != client->users.end(); ++i) {
i try it, but it doesn't work :(

GargoyleMT
DC++ Contributor
Posts: 3212
Joined: 2003-01-07 21:46
Location: .pa.us

Post by GargoyleMT » 2006-12-11 19:04

Do you put the online users into the data structure at any point?

adrian_007
Posts: 32
Joined: 2006-03-06 10:54
Location: Poland

Post by adrian_007 » 2006-12-18 15:42

Do you put the online users into the data structure at any point?
i think not, could you give me an example code please?

Locked