github.com/geph-official/geph2@v0.22.6-0.20210211030601-f527cb59b0df/libs/kcp-go/kcp_vgs.go (about)

     1  package kcp
     2  
     3  import "log"
     4  
     5  const multiplier = 16
     6  
     7  func (kcp *KCP) vgs_onack(acks int32) {
     8  	factor := float64(kcp.mss) / (float64(kcp.DRE.minRtt) / 1000)
     9  	expected := kcp.cwnd * factor
    10  	actual := kcp.DRE.maxAckRate
    11  	alpha := factor * 128
    12  	beta := factor * 256
    13  	diff := expected - actual
    14  
    15  	if doLogging {
    16  		log.Printf("cwnd = %v, expected = %.2fK; actual = %.2fK; loss= %.2f%%", int(kcp.cwnd), expected/1000, actual/1000,
    17  			100*float64(kcp.retrans)/float64(kcp.trans))
    18  	}
    19  	if diff < alpha {
    20  		kcp.cwnd += (multiplier * float64(acks) * kcp.DRE.minRtt / 4 / kcp.cwnd)
    21  	} else if diff > beta {
    22  		kcp.cwnd -= float64(acks) * kcp.DRE.minRtt / 4 / kcp.cwnd
    23  	}
    24  	if kcp.cwnd < 4 {
    25  		kcp.cwnd = 4
    26  	}
    27  }