fix: unsubscribe from all peers unless specified and check err code when full node has no subscription

This commit is contained in:
Richard Ramos 2023-07-03 13:17:20 -04:00 committed by richΛrd
parent 0822fdb280
commit 7dd02067f8

View File

@ -256,10 +256,6 @@ func (wf *WakuFilterLightnode) getUnsubscribeParameters(opts ...FilterUnsubscrib
opt(params)
}
if !params.unsubscribeAll && params.selectedPeer == "" {
return nil, ErrNoPeersAvailable
}
return params, nil
}
@ -350,7 +346,7 @@ func (wf *WakuFilterLightnode) Unsubscribe(ctx context.Context, contentFilter Co
resultChan := make(chan WakuFilterPushResult, len(wf.subscriptions.items))
for peerID := range wf.subscriptions.items {
if !params.unsubscribeAll && peerID != params.selectedPeer {
if params.selectedPeer != "" && peerID != params.selectedPeer {
continue
}
@ -363,8 +359,13 @@ func (wf *WakuFilterLightnode) Unsubscribe(ctx context.Context, contentFilter Co
pb.FilterSubscribeRequest_UNSUBSCRIBE,
contentFilter)
if err != nil {
wf.log.Error("could not unsubscribe from peer", logging.HostID("peerID", peerID), zap.Error(err))
return
ferr, ok := err.(*FilterError)
if ok && ferr.Code == http.StatusNotFound {
wf.log.Warn("peer does not have a subscription", logging.HostID("peerID", peerID), zap.Error(err))
} else {
wf.log.Error("could not unsubscribe from peer", logging.HostID("peerID", peerID), zap.Error(err))
return
}
}
wf.cleanupSubscriptions(peerID, contentFilter)
@ -408,7 +409,7 @@ func (wf *WakuFilterLightnode) UnsubscribeAll(ctx context.Context, opts ...Filte
resultChan := make(chan WakuFilterPushResult, len(wf.subscriptions.items))
for peerID := range wf.subscriptions.items {
if !params.unsubscribeAll && peerID != params.selectedPeer {
if params.selectedPeer != "" && peerID != params.selectedPeer {
continue
}
localWg.Add(1)