/**
 * returns entry in hashtable for the given connection
 * if it was not found, a new entry is created and returned
 */
TRWPortscanDetector::TRWEntry* TRWPortscanDetector::getEntry(Connection* conn)
{
	time_t curtime = time(0);
	uint32_t hash = crc32(0, 2, &reinterpret_cast<char*>(&conn->srcIP)[2]) & (hashSize-1);

	// regularly cleanup expired entries in hashtable
	if (lastCleanup+timeCleanupInterval < (uint32_t)curtime) {
		cleanupEntries();
		lastCleanup = curtime;
	}

	list<TRWEntry*>::iterator iter = trwEntries[hash].begin();
	while (iter != trwEntries[hash].end()) {
		if ((*iter)->srcIP == conn->srcIP) {
			// found the entry
			return *iter;
		}
		iter++;
	}

	// no entry found, create a new one
	TRWEntry* trw = createEntry(conn);
	trwEntries[hash].push_back(trw);

	return trw;
}
Пример #2
0
/**
 * returns entry in hashtable for the given connection
 * if it was not found, a new entry is created and returned
 */
RBSWormDetector::RBSEntry* RBSWormDetector::getEntry(Connection* conn)
{
	time_t curtime = time(0);
	uint32_t hash = crc32(0, 4, reinterpret_cast<char*>(&conn->srcIP)) & (hashSize-1);

	//regularly adapt new values
	if (lastAdaption+timeAdaptInterval < (uint32_t) curtime) 
	{
		lastAdaption = curtime;
		adaptFrequencies();
		
	}

	// regularly cleanup expired entries in hashtable
	if (lastCleanup+timeCleanupInterval < (uint32_t)curtime) {
		lastCleanup = curtime;
		cleanupEntries();		
	}

	list<RBSEntry*>::iterator iter = rbsEntries[hash].begin();
	while (iter != rbsEntries[hash].end()) {
		if ((*iter)->srcIP == conn->srcIP) {
			// found the entry
			return *iter;
		}
		iter++;
	}

	// no entry found, create a new one
	RBSEntry* rbs = createEntry(conn);
	rbsEntries[hash].push_back(rbs);

	return rbs;
}