]> jfr.im git - irc/UndernetIRC/gnuworld.git/commitdiff
dronescan: now considering the 10 1st joining clients in the join/part
authorHidden <redacted>
Sun, 5 Mar 2023 23:07:18 +0000 (18:07 -0500)
committerHidden <redacted>
Sun, 5 Mar 2023 23:07:18 +0000 (18:07 -0500)
flood detection

mod.dronescan/dronescan.cc
mod.dronescan/dronescan.h
mod.dronescan/jfChannel.h

index e4f992ca54dd0b7b4ad5de936173e20c8741561d..c56710a145cc4404ec6ef3c7812e75532e578e48 100644 (file)
@@ -1263,7 +1263,7 @@ else
        assert(channel != NULL);
        jcChanMap[channelName] = channel;
        }
-unsigned int joinCount = channel->advanceChannelJoin();
+unsigned int joinCount = channel->advanceChannelJoin(theClient);
 
 if(joinCount == jcCutoff)
        {
@@ -1275,68 +1275,90 @@ if(joinCount == jcCutoff)
        }
 if(channel->getJoinFlooded())
        {
-       channel->addJoin(theClient);
-       if (joinCount >= jcCutoff) {
-               string IP = xIP(theClient->getIP()).GetNumericIP();
-               jcFloodClients* jcFC;
-               if ((::time(0) - lastBurstTime) >= jcGracePeriodBurstOrSplit && jcGlineEnable) {
-                       clientsIPFloodMapType::const_iterator Itr = clientsIPFloodMap.find(IP);
-                       if (Itr != clientsIPFloodMap.end()) {
-                               jcFC = Itr->second;
-                               if ((unsigned int) (::time(0) - jcFC->ctime) > jcJoinsPerIPTime) {
-                                       jcFC->ctime = ::time(0);
-                                       jcFC->count = 0;
-                                       jcFC->chans.clear();
-                                       jcFC->nicks.clear();
-                                       jcFC->log.clear();
-                               }
+       if (joinCount == jcCutoff)
+               {
+               for (jfChannel::jClientsVectorIterator jItr = channel->jClientsBegin(); jItr != channel->jClientsEnd(); jItr++)
+                       {
+                       iClient *tmpClient = Network->findClient(*jItr);
+                       if (tmpClient == 0)
+                               continue;
+                       addJoin(channel, tmpClient, joinCount);
                        }
-                       else {
-                               jcFC = new (std::nothrow) jcFloodClients;
-                               assert(jcFC != NULL);
-                               jcFC->count = 0;
+               }
+       else
+               addJoin(channel, theClient, joinCount);
+       }
+}
+
+time_t dronescan::getRoundedUnixTime(time_t ts, unsigned int power)
+{
+ts >> power;
+ts << power;
+return ts;
+}
+
+void dronescan::addJoin(jfChannel* channel, iClient *theClient, unsigned int joinCount)
+{
+std::string channelName = channel->getName();
+channel->addJoin(theClient);
+if (joinCount >= jcCutoff) {
+       string IP = xIP(theClient->getIP()).GetNumericIP();
+       jcFloodClients* jcFC;
+       if ((::time(0) - lastBurstTime) >= jcGracePeriodBurstOrSplit && jcGlineEnable) {
+               clientsIPFloodMapType::const_iterator Itr = clientsIPFloodMap.find(IP);
+               if (Itr != clientsIPFloodMap.end()) {
+                       jcFC = Itr->second;
+                       if ((unsigned int) (::time(0) - jcFC->ctime) > jcJoinsPerIPTime) {
                                jcFC->ctime = ::time(0);
-                               clientsIPFloodMap[IP] = jcFC;
+                               jcFC->count = 0;
+                               jcFC->chans.clear();
+                               jcFC->nicks.clear();
+                               jcFC->log.clear();
                        }
-                       jcFC->count++;
-                       std::list< string >::iterator sItr;
-                       bool isMatchFound = false;
-                       for (sItr = jcFC->chans.begin(); sItr != jcFC->chans.end(); sItr++) {
-                               if (*sItr == channelName) {
-                                       isMatchFound = true;
-                                       break;
-                               }
+               }
+               else {
+                       jcFC = new (std::nothrow) jcFloodClients;
+                       assert(jcFC != NULL);
+                       jcFC->count = 0;
+                       jcFC->ctime = ::time(0);
+                       clientsIPFloodMap[IP] = jcFC;
+               }
+               jcFC->count++;
+               std::list< string >::iterator sItr;
+               bool isMatchFound = false;
+               for (sItr = jcFC->chans.begin(); sItr != jcFC->chans.end(); sItr++) {
+                       if (*sItr == channelName) {
+                               isMatchFound = true;
+                               break;
                        }
-                       if (!isMatchFound)
-                               jcFC->chans.push_back(channelName);
-                       isMatchFound = false;
-                       for (sItr = jcFC->nicks.begin(); sItr != jcFC->nicks.end(); sItr++) {
-                               if (*sItr == theClient->getNickName()) {
-                                       isMatchFound = true;
-                                       break;
-                               }
+               }
+               if (!isMatchFound)
+                       jcFC->chans.push_back(channelName);
+               isMatchFound = false;
+               for (sItr = jcFC->nicks.begin(); sItr != jcFC->nicks.end(); sItr++) {
+                       if (*sItr == theClient->getNickName()) {
+                               isMatchFound = true;
+                               break;
                        }
-                       if (!isMatchFound)
-                               jcFC->nicks.push_back(theClient->getNickName());
+               }
+               if (!isMatchFound)
+                       jcFC->nicks.push_back(theClient->getNickName());
 
-                       std::stringstream s;
-                       s << theClient->getNickName()
-                               << "!" << theClient->getUserName()
-                               << "@" << xIP(theClient->getIP()).GetNumericIP()
-                               << " " << theClient->getDescription()
-                               << " " << channelName <<  " " << ::time(0);
-                       jcFC->log.push_back(s.str());
+               std::stringstream s;
+               s << theClient->getNickName()
+                       << "!" << theClient->getUserName()
+                       << "@" << xIP(theClient->getIP()).GetNumericIP()
+                       << " " << theClient->getDescription()
+                       << " " << channelName <<  " " << ::time(0);
+               jcFC->log.push_back(s.str());
 
 
-                       if ((unsigned int) jcFC->count >= jcMinJoinsPerIPToGline) {
-                               IPJQueue.push_back(IP);
-                       }
+               if ((unsigned int) jcFC->count >= jcMinJoinsPerIPToGline) {
+                       IPJQueue.push_back(IP);
                }
        }
-
-       }
 }
-
+}
 
 void dronescan::handleChannelPart(Channel* theChan,iClient* theClient)
 {
index 207287a1125277fb9373e5ecdc41bed716919bf5..50e2ab5ab93a5e9673c18a6555f35d4e1ea721d4 100644 (file)
@@ -155,7 +155,13 @@ public:
 
        /** handles a channel part */
        void handleChannelPart( Channel*, iClient* );
-       
+
+       /** get rounded unix time */
+       time_t getRoundedUnixTime(time_t, unsigned int);
+
+       /** addJoin() method */
+       void addJoin(jfChannel*, iClient*, unsigned int);
+
        /** This function handles new clients as they connect. */
        void handleNewClient( iClient* ) ;
 
index 6cbe1ef57722d6f2b7390e19a5dbecc37cf7beb4..a8e822c8207a95d56e932d405ded531cfe302436 100644 (file)
@@ -35,6 +35,8 @@ public:
        
        typedef std::map<std::string,jfClientData> joinPartMapType;
        typedef joinPartMapType::const_iterator joinPartMapIterator;
+       typedef std::vector<std::string> jClientsVectorType;
+       typedef jClientsVectorType::const_iterator jClientsVectorIterator;
                
        /**
         * Constructor to set up initial state.
@@ -71,13 +73,22 @@ public:
        
        inline const joinPartMapIterator joinPartEnd() const
                { return joinPartMap.end(); }
-               
+
+       inline const jClientsVectorIterator jClientsBegin() const
+               { return jClients.begin(); }
+
+       inline const jClientsVectorIterator jClientsEnd() const
+               { return jClients.end(); }
+
        /*********************
         ** M U T A T O R S **
         *********************/
        
-       inline unsigned int advanceChannelJoin() 
-               { return ++numOfJoins; }
+       inline unsigned int advanceChannelJoin(iClient* tmpClient)
+               {
+               jClients.push_back(std::string(tmpClient->getCharYYXXX()));
+               return ++numOfJoins;
+               }
        
        inline void resetJoinCount()
                { numOfJoins = 0; }
@@ -112,6 +123,7 @@ protected:
        bool            partFlooded;
        joinPartMapType joinPartMap;
        time_t lastJoinFlood;
+       jClientsVectorType jClients;
 
 }; // class jfChannel