sping icon indicating copy to clipboard operation
sping copied to clipboard

A loss of 32 can never be determined

Open marek22k opened this issue 8 months ago • 0 comments

Hello,

I am currently looking at the code for the program. It is about the following: The function "getLoss" determines how many packages have been lost. To do this, the For loop is run through for the last 32 IDs. If an ID is missing, i.e. the packet has not been received, a loss has occurred. However, I have now noticed that the loop is only run 31 times. This means that a loss of 32 is not possible at all. To verify my findings, I have changed the code slightly:

func getLoss(rx pingStruct, ses *session) (RXLoss int, TXLoss int, TotalSent int) {

	TipID := uint8(time.Now().Unix()%255) + 1

	// Don't send loss stats when we don't have enough info to operate with
	if dumbLastAckSearchForID(0, ses.LastAcks) {
		return 0, 0, 0
	}

	// Okay so we have enough data, let's search backwards (avoiding 0)
	Starting := TipID - 32
	i := Starting
	counter := 0
	for {
		i++
		if i == 0 {
			i++
		}
		if i == TipID {
			break
		}
		if !dumbLastAckSearchForID(i, rx.LastAcks) {
			TXLoss++
		}
		if !dumbLastAckSearchForID(i, ses.LastAcks) {
			RXLoss++
		}
		log.Printf("i: %d", i)
		counter += 1
	}
	log.Printf("Counter: %d", counter)

	return RXLoss, TXLoss, 32
}

I received the following output:

2023/11/05 23:34:24 i: 24
2023/11/05 23:34:24 i: 25
2023/11/05 23:34:24 i: 26
2023/11/05 23:34:24 i: 27
2023/11/05 23:34:24 i: 28
2023/11/05 23:34:24 i: 29
2023/11/05 23:34:24 i: 30
2023/11/05 23:34:24 i: 31
2023/11/05 23:34:24 i: 32
2023/11/05 23:34:24 i: 33
2023/11/05 23:34:24 i: 34
2023/11/05 23:34:24 i: 35
2023/11/05 23:34:24 i: 36
2023/11/05 23:34:24 i: 37
2023/11/05 23:34:24 i: 38
2023/11/05 23:34:24 i: 39
2023/11/05 23:34:24 i: 40
2023/11/05 23:34:24 i: 41
2023/11/05 23:34:24 i: 42
2023/11/05 23:34:24 i: 43
2023/11/05 23:34:24 i: 44
2023/11/05 23:34:24 i: 45
2023/11/05 23:34:24 i: 46
2023/11/05 23:34:24 i: 47
2023/11/05 23:34:24 i: 48
2023/11/05 23:34:24 i: 49
2023/11/05 23:34:24 i: 50
2023/11/05 23:34:24 i: 51
2023/11/05 23:34:24 i: 52
2023/11/05 23:34:24 i: 53
2023/11/05 23:34:24 i: 54
2023/11/05 23:34:24 Counter: 31

Both the output with "i" and the counter are only output 31 times. This means that not 32, but 31 IDs are run through.

marek22k avatar Nov 05 '23 22:11 marek22k