mirror of
https://github.com/status-im/go-waku.git
synced 2025-01-27 05:56:07 +00:00
fix: use subscription peerIds instead of separate peer slice (#906)
This commit is contained in:
parent
f0fbe62b8d
commit
49593fd61d
@ -482,15 +482,18 @@ func (wf *WakuFilterLightNode) Unsubscribe(ctx context.Context, contentFilter pr
|
||||
result := &WakuFilterPushResult{}
|
||||
for pTopic, cTopics := range pubSubTopicMap {
|
||||
cFilter := protocol.NewContentFilter(pTopic, cTopics...)
|
||||
peers, subs := wf.subscriptions.GetSubscription(params.selectedPeer, cFilter)
|
||||
|
||||
peers := make(map[peer.ID]struct{})
|
||||
subs := wf.subscriptions.GetSubscription(params.selectedPeer, cFilter)
|
||||
for _, sub := range subs {
|
||||
sub.Remove(cTopics...)
|
||||
peers[sub.PeerID] = struct{}{}
|
||||
}
|
||||
if params.wg != nil {
|
||||
params.wg.Add(len(peers))
|
||||
}
|
||||
// send unsubscribe request to all the peers
|
||||
for _, peerID := range peers {
|
||||
for peerID := range peers {
|
||||
go func(peerID peer.ID) {
|
||||
defer func() {
|
||||
if params.wg != nil {
|
||||
@ -516,7 +519,7 @@ func (wf *WakuFilterLightNode) Unsubscribe(ctx context.Context, contentFilter pr
|
||||
}
|
||||
|
||||
func (wf *WakuFilterLightNode) Subscriptions() []*subscription.SubscriptionDetails {
|
||||
_, subs := wf.subscriptions.GetSubscription("", protocol.ContentFilter{})
|
||||
subs := wf.subscriptions.GetSubscription("", protocol.ContentFilter{})
|
||||
return subs
|
||||
}
|
||||
|
||||
@ -581,15 +584,17 @@ func (wf *WakuFilterLightNode) unsubscribeAll(ctx context.Context, opts ...Filte
|
||||
return nil, err
|
||||
}
|
||||
|
||||
peerIds, subs := wf.subscriptions.GetSubscription(params.selectedPeer, protocol.ContentFilter{})
|
||||
peers := make(map[peer.ID]struct{})
|
||||
subs := wf.subscriptions.GetSubscription(params.selectedPeer, protocol.ContentFilter{})
|
||||
for _, sub := range subs {
|
||||
sub.Close()
|
||||
peers[sub.PeerID] = struct{}{}
|
||||
}
|
||||
result := &WakuFilterPushResult{}
|
||||
if params.wg != nil {
|
||||
params.wg.Add(len(peerIds))
|
||||
params.wg.Add(len(peers))
|
||||
}
|
||||
for _, peerId := range peerIds {
|
||||
for peerId := range peers {
|
||||
go func(peerID peer.ID) {
|
||||
defer func() {
|
||||
if params.wg != nil {
|
||||
|
@ -193,16 +193,13 @@ func iterateSubscriptionSet(logger *zap.Logger, subscriptions SubscriptionSet, e
|
||||
}
|
||||
}
|
||||
|
||||
func (m *SubscriptionsMap) GetSubscription(peerID peer.ID, contentFilter protocol.ContentFilter) ([]peer.ID, []*SubscriptionDetails) {
|
||||
func (m *SubscriptionsMap) GetSubscription(peerID peer.ID, contentFilter protocol.ContentFilter) []*SubscriptionDetails {
|
||||
m.RLock()
|
||||
defer m.RUnlock()
|
||||
|
||||
var output []*SubscriptionDetails
|
||||
|
||||
var peerIDs []peer.ID
|
||||
for _, peerSubs := range m.items {
|
||||
if peerID == "" || peerSubs.PeerID == peerID {
|
||||
peerIDs = append(peerIDs, peerID)
|
||||
for _, subs := range peerSubs.SubsPerPubsubTopic {
|
||||
for _, subscriptionDetail := range subs {
|
||||
if subscriptionDetail.isPartOf(contentFilter) {
|
||||
@ -212,5 +209,5 @@ func (m *SubscriptionsMap) GetSubscription(peerID peer.ID, contentFilter protoco
|
||||
}
|
||||
}
|
||||
}
|
||||
return peerIDs, output
|
||||
return output
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user