def cachePacket(self, data): #add current packet to cache, check cache size, if too big remove a packet seq = dataPacketHandler.getPacketSeq(data) self.packetCache[seq] = data self.packetCacheList.append(seq) if len(self.packetCacheList)>self.cacheMaxSize: del self.packetCache[self.packetCacheList.pop(0)] # remove oldest entry from packetCache, which should be at index 0 or packetCacheList
def sendPackets(self): data = self.packetList.pop(0) seq = dataPacketHandler.getPacketSeq(data) # print "Writing:" #, data self.transport.write(data,(self.bcast,self.port)) self.cachePacket(data) # save if packet is needed in a ReTx # print "Getting old seq" seqNew = self.getSequence()+1 # as the packet list goes 1 -> 2 -> ... -> n ->1 but we can't do this we seq numbers so we need to update them to a new number everytime we paste the packet back into the list seqOld, pData = dataPacketHandler.decodePacket(data) newData = dataPacketHandler.encodePacket(seqNew, pData) self.packetList.append(newData) #adds spike to end of list # print "sleeping" self.reactor.callLater(self.sleep, self.sendPackets)