OSDN Git Service

IM0034
[peercast-im/PeerCastIM.git] / PeerCast.root / PeerCast / core / common / pcp.cpp
index a7b47fb..1b0b66a 100644 (file)
@@ -25,6 +25,7 @@
 #define DEBUG_NEW new(__FILE__, __LINE__)
 #define new DEBUG_NEW
 #endif
+#include <ctime>
 
 // ------------------------------------------
 void PCPStream::init(GnuID &rid)
@@ -802,6 +803,22 @@ int PCPStream::readBroadcastAtoms(AtomStream &atom,int numc,BroadcastState &bcs)
        char tmp[64];
        bcs.chanID.toStr(tmp);
 
+       // Broadcast flood
+       if (servMgr->lastPCPFromID.isSame(fromID)
+               && time(NULL) - servMgr->lastPCPBcstTime < 3)
+       {
+               memcpy(servMgr->lastPCPFromID.id, fromID.id, 16);
+               servMgr->lastPCPBcstTime = time(NULL);
+               LOG_DEBUG("PCP bcst reject: group=%d, hops=%d, ver=%d(%c%c%04d), from=%s, dest=%s ttl=%d",
+                       bcs.group,bcs.numHops,ver,ver_ex_prefix[0],ver_ex_prefix[1],ver_ex_number,fromStr,destStr,bcs.ttl);
+
+               return r;
+       }
+       memcpy(servMgr->lastPCPFromID.id, fromID.id, 16);
+       servMgr->lastPCPBcstTime = time(NULL);
+
+       servMgr->lastPCPFromID.toStr(destStr);
+
 //     LOG_DEBUG(tmp);
 
        if (ver_ex_number){