From: <Kha...@us...> - 2009-03-26 02:01:19
|
Revision: 3317 http://planeshift.svn.sourceforge.net/planeshift/?rev=3317&view=rev Author: KhakiLord Date: 2009-03-26 01:31:21 +0000 (Thu, 26 Mar 2009) Log Message: ----------- Improved performance when checking for duplicated packets. Fixed bug in npcclient where duplicates would not be detected since the input queue was longer than the packet history so when the input queue fills up, dups would not be detected. Modified Paths: -------------- trunk/src/common/net/netbase.cpp trunk/src/common/net/netbase.h trunk/src/npcclient/npcclient.cpp Modified: trunk/src/common/net/netbase.cpp =================================================================== --- trunk/src/common/net/netbase.cpp 2009-03-25 19:13:38 UTC (rev 3316) +++ trunk/src/common/net/netbase.cpp 2009-03-26 01:31:21 UTC (rev 3317) @@ -408,18 +408,25 @@ bool NetBase::CheckDoublePackets(Connection* connection, csRef<psNetPacketEntry> pkt) { - int i; + + csArray<uint32_t> offsets = connection->packethistoryhash.GetAll(pkt->packet->pktid); + if(!offsets.IsEmpty()) + { + for(size_t i = 0; i < offsets.GetSize(); i++) + if(offsets[i] == pkt->packet->offset) + return true; + } - for (i=0; i<MAXPACKETHISTORY; i++) - if (connection->packethistoryid[i] == pkt->packet->pktid - && connection->packethistoryoffset[i] == pkt->packet->offset) - break; + // No duplicate packet found + connection->packethistoryhash.Put(pkt->packet->pktid, pkt->packet->offset); + + // Push new packet onto history + connection->packethistoryhash.Delete(connection->packethistoryid[connection->historypos], connection->packethistoryoffset[connection->historypos]); + connection->packethistoryid[connection->historypos] = pkt->packet->pktid; + connection->packethistoryoffset[connection->historypos] = pkt->packet->offset; + connection->historypos = (connection->historypos + 1) % MAXPACKETHISTORY; - connection->packethistoryid[connection->historypos] = pkt->packet->pktid; - connection->packethistoryoffset[connection->historypos] = pkt->packet->offset; - connection->historypos = (connection->historypos + 1) % MAXPACKETHISTORY; - - return (i != MAXPACKETHISTORY); + return false; } void NetBase::CheckResendPkts() @@ -1285,7 +1292,7 @@ // -------------------------------------------------------------------------- -NetBase::Connection::Connection(uint32_t num): sequence(1) +NetBase::Connection::Connection(uint32_t num): sequence(1), packethistoryhash(MAXPACKETHISTORY) { pcknumin=0; pcknumout=0; Modified: trunk/src/common/net/netbase.h =================================================================== --- trunk/src/common/net/netbase.h 2009-03-25 19:13:38 UTC (rev 3316) +++ trunk/src/common/net/netbase.h 2009-03-26 01:31:21 UTC (rev 3317) @@ -36,7 +36,9 @@ #define NUM_BROADCAST 0xffffffff #define MAXQUEUESIZE 20000 #define MAXCLIENTQUEUESIZE 5000 -#define MAXPACKETHISTORY 400 +#define MAXPACKETHISTORY 503 // Should be a prime to improve performance of hash + // This must be set carefully and ideally should be at least the size + // of the input queue #define NETAVGCOUNT 400 #define RESENDAVGCOUNT 200 @@ -604,6 +606,7 @@ { uint32_t sequence; public: + csHash<uint32_t> packethistoryhash; /** buffer for split up packets, allocated when needed */ void *buf; /** The INet Adress of the client */ Modified: trunk/src/npcclient/npcclient.cpp =================================================================== --- trunk/src/npcclient/npcclient.cpp 2009-03-25 19:13:38 UTC (rev 3316) +++ trunk/src/npcclient/npcclient.cpp 2009-03-26 01:31:21 UTC (rev 3317) @@ -176,9 +176,8 @@ msghandler = eventmanager; psMessageCracker::msghandler = eventmanager; - // Start up network, need a large queue in order to handle all - // the persist messages received from server at startup. - if (!msghandler->Initialize(connection, 20000)) + // Start up network + if (!msghandler->Initialize(connection)) { return false; // Attach to incoming messages. } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |