mirror of https://github.com/status-im/go-waku.git
chore: method to disconnect all peers and not notify (#1168)
This commit is contained in:
parent
58d9721026
commit
a9be17fd48
|
@ -799,6 +799,17 @@ func (w *WakuNode) ClosePeerByAddress(address string) error {
|
|||
return w.ClosePeerById(info.ID)
|
||||
}
|
||||
|
||||
func (w *WakuNode) DisconnectAllPeers() {
|
||||
w.host.Network().StopNotify(w.connectionNotif)
|
||||
for _, peerID := range w.host.Network().Peers() {
|
||||
err := w.ClosePeerById(peerID)
|
||||
if err != nil {
|
||||
w.log.Info("failed to close peer", zap.Stringer("peer", peerID), zap.Error(err))
|
||||
}
|
||||
}
|
||||
w.host.Network().Notify(w.connectionNotif)
|
||||
}
|
||||
|
||||
// ClosePeerById is used to close a connection to a peer
|
||||
func (w *WakuNode) ClosePeerById(id peer.ID) error {
|
||||
err := w.host.Network().ClosePeer(id)
|
||||
|
|
|
@ -147,17 +147,6 @@ func (wf *WakuFilterLightNode) Stop() {
|
|||
})
|
||||
}
|
||||
|
||||
func (wf *WakuFilterLightNode) unsubscribeWithoutSubscription(cf protocol.ContentFilter, peerID peer.ID) {
|
||||
err := wf.request(
|
||||
wf.Context(),
|
||||
protocol.GenerateRequestID(),
|
||||
pb.FilterSubscribeRequest_UNSUBSCRIBE_ALL,
|
||||
cf, peerID)
|
||||
if err != nil {
|
||||
wf.log.Warn("could not unsubscribe from peer", logging.HostID("peerID", peerID), zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
||||
func (wf *WakuFilterLightNode) onRequest(ctx context.Context) func(network.Stream) {
|
||||
return func(stream network.Stream) {
|
||||
peerID := stream.Conn().RemotePeer()
|
||||
|
@ -168,8 +157,6 @@ func (wf *WakuFilterLightNode) onRequest(ctx context.Context) func(network.Strea
|
|||
logger.Warn("received message push from unknown peer", logging.HostID("peerID", peerID))
|
||||
wf.metrics.RecordError(unknownPeerMessagePush)
|
||||
//Send a wildcard unsubscribe to this peer so that further requests are not forwarded to us
|
||||
//This could be happening due to https://github.com/waku-org/go-waku/issues/1124
|
||||
go wf.unsubscribeWithoutSubscription(protocol.ContentFilter{}, peerID)
|
||||
if err := stream.Reset(); err != nil {
|
||||
wf.log.Error("resetting connection", zap.Error(err))
|
||||
}
|
||||
|
@ -216,8 +203,6 @@ func (wf *WakuFilterLightNode) onRequest(ctx context.Context) func(network.Strea
|
|||
cf := protocol.NewContentFilter(pubSubTopic, messagePush.WakuMessage.ContentTopic)
|
||||
if !wf.subscriptions.Has(peerID, cf) {
|
||||
logger.Warn("received messagepush with invalid subscription parameters")
|
||||
//Unsubscribe from that peer for the contentTopic, possibly due to https://github.com/waku-org/go-waku/issues/1124
|
||||
go wf.unsubscribeWithoutSubscription(cf, peerID)
|
||||
wf.metrics.RecordError(invalidSubscriptionMessage)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue