static short BWLimiterProcess(PacketNode *head, PacketNode *tail) { int dropped = 0; DWORD currentTime = timeGetTime(); PacketNode *pac = tail->prev; // pick up all packets and fill in the current time while (pac != head) { if (checkDirection(pac->addr.Direction, BWLimiterInbound, BWLimiterOutbound)) { if ( bufSizeByte >= ((DWORD)BWQueueSizeValue*1024)) { LOG("droped with chance, direction %s", BOUND_TEXT(pac->addr.Direction)); freeNode(popNode(pac)); ++dropped; } else { insertAfter(popNode(pac), bufHead)->timestamp = timeGetTime(); ++bufSize; bufSizeByte += pac->packetLen; pac = tail->prev; } } else { pac = pac->prev; } } while (!isBufEmpty() && canSendPacket(currentTime)) { PacketNode *pac = bufTail->prev; bufSizeByte -= pac->packetLen; recordSentPacket(currentTime, pac->packetLen); insertAfter(popNode(bufTail->prev), head); --bufSize; } if (bufSize > 0) { LOG("Queued buffers : %d", bufSize); } return (bufSize>0) || (dropped>0); }
static short dropProcess(PacketNode *head, PacketNode* tail) { int dropped = 0; while (head->next != tail) { PacketNode *pac = head->next; // chance in range of [0, 1000] if (checkDirection(pac->addr.Direction, dropInbound, dropOutbound) && calcChance(chance)) { LOG("dropped with chance %.1f%%, direction %s", chance/10.0, BOUND_TEXT(pac->addr.Direction)); freeNode(popNode(pac)); ++dropped; } else { head = head->next; } } return dropped > 0; }