You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: bitswap/network/httpnet/error_tracker.go
+10-27Lines changed: 10 additions & 27 deletions
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,6 @@ package httpnet
3
3
import (
4
4
"errors"
5
5
"sync"
6
-
"sync/atomic"
7
6
8
7
"github.com/libp2p/go-libp2p/core/peer"
9
8
)
@@ -14,50 +13,34 @@ type errorTracker struct {
14
13
ht*Network
15
14
16
15
mux sync.RWMutex
17
-
errorsmap[peer.ID]*atomic.Uint64
16
+
errorsmap[peer.ID]int
18
17
}
19
18
20
19
funcnewErrorTracker(ht*Network) *errorTracker {
21
20
return&errorTracker{
22
21
ht: ht,
23
-
errors: make(map[peer.ID]*atomic.Uint64),
24
-
}
25
-
}
26
-
27
-
func (et*errorTracker) startTracking(p peer.ID) {
28
-
et.mux.Lock()
29
-
deferet.mux.Unlock()
30
-
31
-
// Initialize the error count for the peer if it doesn't exist
32
-
if_, exists:=et.errors[p]; !exists {
33
-
et.errors[p] =&atomic.Uint64{}
22
+
errors: make(map[peer.ID]int),
34
23
}
35
24
}
36
25
37
26
func (et*errorTracker) stopTracking(p peer.ID) {
38
27
et.mux.Lock()
39
-
deferet.mux.Unlock()
40
28
delete(et.errors, p)
29
+
et.mux.Unlock()
41
30
}
42
31
43
32
// logErrors adds n to the current error count for p. If the total count is above the threshold, then an error is returned. If n is 0, the the total count is reset to 0.
0 commit comments