@@ -7,17 +7,15 @@ import (
7
7
"github.com/tendermint/tendermint/types"
8
8
)
9
9
10
- // nolint: golint
11
- // TODO: Rename type.
12
- type MempoolIDs struct {
10
+ type IDs struct {
13
11
mtx tmsync.RWMutex
14
12
peerMap map [types.NodeID ]uint16
15
13
nextID uint16 // assumes that a node will never have over 65536 active peers
16
14
activeIDs map [uint16 ]struct {} // used to check if a given peerID key is used
17
15
}
18
16
19
- func NewMempoolIDs () * MempoolIDs {
20
- return & MempoolIDs {
17
+ func NewMempoolIDs () * IDs {
18
+ return & IDs {
21
19
peerMap : make (map [types.NodeID ]uint16 ),
22
20
23
21
// reserve UnknownPeerID for mempoolReactor.BroadcastTx
@@ -28,7 +26,7 @@ func NewMempoolIDs() *MempoolIDs {
28
26
29
27
// ReserveForPeer searches for the next unused ID and assigns it to the provided
30
28
// peer.
31
- func (ids * MempoolIDs ) ReserveForPeer (peerID types.NodeID ) {
29
+ func (ids * IDs ) ReserveForPeer (peerID types.NodeID ) {
32
30
ids .mtx .Lock ()
33
31
defer ids .mtx .Unlock ()
34
32
@@ -38,7 +36,7 @@ func (ids *MempoolIDs) ReserveForPeer(peerID types.NodeID) {
38
36
}
39
37
40
38
// Reclaim returns the ID reserved for the peer back to unused pool.
41
- func (ids * MempoolIDs ) Reclaim (peerID types.NodeID ) {
39
+ func (ids * IDs ) Reclaim (peerID types.NodeID ) {
42
40
ids .mtx .Lock ()
43
41
defer ids .mtx .Unlock ()
44
42
@@ -50,7 +48,7 @@ func (ids *MempoolIDs) Reclaim(peerID types.NodeID) {
50
48
}
51
49
52
50
// GetForPeer returns an ID reserved for the peer.
53
- func (ids * MempoolIDs ) GetForPeer (peerID types.NodeID ) uint16 {
51
+ func (ids * IDs ) GetForPeer (peerID types.NodeID ) uint16 {
54
52
ids .mtx .RLock ()
55
53
defer ids .mtx .RUnlock ()
56
54
@@ -59,7 +57,7 @@ func (ids *MempoolIDs) GetForPeer(peerID types.NodeID) uint16 {
59
57
60
58
// nextPeerID returns the next unused peer ID to use. We assume that the mutex
61
59
// is already held.
62
- func (ids * MempoolIDs ) nextPeerID () uint16 {
60
+ func (ids * IDs ) nextPeerID () uint16 {
63
61
if len (ids .activeIDs ) == MaxActiveIDs {
64
62
panic (fmt .Sprintf ("node has maximum %d active IDs and wanted to get one more" , MaxActiveIDs ))
65
63
}
0 commit comments