MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / Ack

Method Ack

internal/utils/ratelimit/bandwidth.go:26–61  ·  view source on GitHub ↗

Ack acquire next chance to send data

(ctx context.Context, newBytes int)

Source from the content-addressed store, hash-verified

24
25// Ack acquire next chance to send data
26func (this *Bandwidth) Ack(ctx context.Context, newBytes int) {
27 if newBytes <= 0 {
28 return
29 }
30 if this.totalBytes <= 0 {
31 return
32 }
33
34 var timestamp = fasttime.Now().Unix()
35 if this.currentTimestamp != 0 && this.currentTimestamp != timestamp {
36 this.currentTimestamp = timestamp
37 this.currentBytes = int64(newBytes)
38
39 // 第一次发送直接放行,不需要判断
40 return
41 }
42
43 if this.currentTimestamp == 0 {
44 this.currentTimestamp = timestamp
45 }
46 if atomic.AddInt64(&this.currentBytes, int64(newBytes)) <= this.totalBytes {
47 return
48 }
49
50 var timeout = time.NewTimer(1 * time.Second)
51 if ctx != nil {
52 select {
53 case <-timeout.C:
54 case <-ctx.Done():
55 }
56 } else {
57 select {
58 case <-timeout.C:
59 }
60 }
61}

Callers

nothing calls this directly

Calls 3

NowFunction · 0.92
UnixMethod · 0.80
DoneMethod · 0.80

Tested by

no test coverage detected