@@ -53,7 +53,7 @@ func (sim *SessionInterestManager) RemoveSession(ses uint64) []cid.Cid {
53
53
defer sim .lk .Unlock ()
54
54
55
55
// The keys that no session is interested in
56
- deletedKs := make ( []cid.Cid , 0 )
56
+ var deletedKs []cid.Cid
57
57
58
58
// For each known key
59
59
for c := range sim .wants {
@@ -119,18 +119,19 @@ func (sim *SessionInterestManager) RemoveSessionInterested(ses uint64, ks []cid.
119
119
// The session calls FilterSessionInterested() to filter the sets of keys for
120
120
// those that the session is interested in
121
121
func (sim * SessionInterestManager ) FilterSessionInterested (ses uint64 , ksets ... []cid.Cid ) [][]cid.Cid {
122
+ kres := make ([][]cid.Cid , len (ksets ))
123
+
122
124
sim .lk .RLock ()
123
125
defer sim .lk .RUnlock ()
124
126
125
127
// For each set of keys
126
- kres := make ([][]cid.Cid , len (ksets ))
127
128
for i , ks := range ksets {
128
129
// The set of keys that at least one session is interested in
129
- has := make ( []cid.Cid , 0 , len ( ks ))
130
+ var has []cid.Cid
130
131
131
132
// For each key in the list
132
133
for _ , c := range ks {
133
- // If there is a session that's interested, add the key to the set
134
+ // If the session is interested, add the key to the set
134
135
if _ , ok := sim.wants [c ][ses ]; ok {
135
136
has = append (has , c )
136
137
}
@@ -144,7 +145,6 @@ func (sim *SessionInterestManager) FilterSessionInterested(ses uint64, ksets ...
144
145
// unwanted blocks
145
146
func (sim * SessionInterestManager ) SplitWantedUnwanted (blks []blocks.Block ) ([]blocks.Block , []blocks.Block ) {
146
147
sim .lk .RLock ()
147
- defer sim .lk .RUnlock ()
148
148
149
149
// Get the wanted block keys as a set
150
150
wantedKs := cid .NewSet ()
@@ -160,6 +160,8 @@ func (sim *SessionInterestManager) SplitWantedUnwanted(blks []blocks.Block) ([]b
160
160
}
161
161
}
162
162
163
+ sim .lk .RUnlock ()
164
+
163
165
// Separate the blocks into wanted and unwanted
164
166
wantedBlks := make ([]blocks.Block , 0 , len (blks ))
165
167
notWantedBlks := make ([]blocks.Block , 0 )
@@ -175,23 +177,22 @@ func (sim *SessionInterestManager) SplitWantedUnwanted(blks []blocks.Block) ([]b
175
177
176
178
// When the SessionManager receives a message it calls InterestedSessions() to
177
179
// find out which sessions are interested in the message.
178
- func (sim * SessionInterestManager ) InterestedSessions (blks []cid.Cid , haves []cid.Cid , dontHaves []cid.Cid ) []uint64 {
179
- sim .lk .RLock ()
180
- defer sim .lk .RUnlock ()
180
+ func (sim * SessionInterestManager ) InterestedSessions (keySets ... []cid.Cid ) []uint64 {
181
+ sesSet := make (map [uint64 ]struct {})
181
182
182
- ks := make ([]cid.Cid , 0 , len (blks )+ len (haves )+ len (dontHaves ))
183
- ks = append (ks , blks ... )
184
- ks = append (ks , haves ... )
185
- ks = append (ks , dontHaves ... )
183
+ sim .lk .RLock ()
186
184
187
185
// Create a set of sessions that are interested in the keys
188
- sesSet := make (map [uint64 ]struct {})
189
- for _ , c := range ks {
190
- for s := range sim .wants [c ] {
191
- sesSet [s ] = struct {}{}
186
+ for _ , keySet := range keySets {
187
+ for _ , c := range keySet {
188
+ for s := range sim .wants [c ] {
189
+ sesSet [s ] = struct {}{}
190
+ }
192
191
}
193
192
}
194
193
194
+ sim .lk .RUnlock ()
195
+
195
196
// Convert the set into a list
196
197
ses := make ([]uint64 , 0 , len (sesSet ))
197
198
for s := range sesSet {
0 commit comments