@@ -12,12 +12,17 @@ import (
12
12
13
13
// Wantlist is a raw list of wanted blocks and their priorities
14
14
type Wantlist struct {
15
- set map [cid.Cid ]Entry
15
+ set map [cid.Cid ]entry
16
16
17
17
// Re-computing this can get expensive so we memoize it.
18
18
cached []Entry
19
19
}
20
20
21
+ type entry struct {
22
+ Priority int32
23
+ WantType pb.Message_Wantlist_WantType
24
+ }
25
+
21
26
// Entry is an entry in a want list, consisting of a cid and its priority
22
27
type Entry struct {
23
28
Cid cid.Cid
@@ -37,7 +42,7 @@ func NewRefEntry(c cid.Cid, p int32) Entry {
37
42
// New generates a new raw Wantlist
38
43
func New () * Wantlist {
39
44
return & Wantlist {
40
- set : make (map [cid.Cid ]Entry ),
45
+ set : make (map [cid.Cid ]entry ),
41
46
}
42
47
}
43
48
@@ -55,8 +60,7 @@ func (w *Wantlist) Add(c cid.Cid, priority int32, wantType pb.Message_Wantlist_W
55
60
return false
56
61
}
57
62
58
- w .put (c , Entry {
59
- Cid : c ,
63
+ w .put (c , entry {
60
64
Priority : priority ,
61
65
WantType : wantType ,
62
66
})
@@ -91,7 +95,7 @@ func (w *Wantlist) delete(c cid.Cid) {
91
95
w .cached = nil
92
96
}
93
97
94
- func (w * Wantlist ) put (c cid.Cid , e Entry ) {
98
+ func (w * Wantlist ) put (c cid.Cid , e entry ) {
95
99
w .cached = nil
96
100
w .set [c ] = e
97
101
}
@@ -105,7 +109,11 @@ func (w *Wantlist) Has(c cid.Cid) bool {
105
109
// present.
106
110
func (w * Wantlist ) Get (c cid.Cid ) (Entry , bool ) {
107
111
e , ok := w .set [c ]
108
- return e , ok
112
+ return Entry {
113
+ Cid : c ,
114
+ Priority : e .Priority ,
115
+ WantType : e .WantType ,
116
+ }, ok
109
117
}
110
118
111
119
// Entries returns all wantlist entries for a want list, sorted by priority.
@@ -116,8 +124,12 @@ func (w *Wantlist) Entries() []Entry {
116
124
return w .cached
117
125
}
118
126
es := make ([]Entry , 0 , len (w .set ))
119
- for _ , e := range w .set {
120
- es = append (es , e )
127
+ for c , e := range w .set {
128
+ es = append (es , Entry {
129
+ Cid : c ,
130
+ Priority : e .Priority ,
131
+ WantType : e .WantType ,
132
+ })
121
133
}
122
134
slices .SortFunc (es , func (a , b Entry ) int {
123
135
return cmp .Compare (b .Priority , a .Priority )
0 commit comments