fix: verify if metadata exists before checking for shard mismatch (#1056)

This commit is contained in:
richΛrd 2024-03-15 20:48:10 -04:00 committed by GitHub
parent bdf44c0a23
commit 3074cdb11c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 15 deletions

View File

@ -121,24 +121,20 @@ func (pm *PeerManager) handlerPeerTopicEvent(peerEvt relay.EvtPeerTopic) {
wps := pm.host.Peerstore().(*wps.WakuPeerstoreImpl)
peerID := peerEvt.PeerID
if peerEvt.State == relay.PEER_JOINED {
if pm.metadata != nil {
rs, err := pm.metadata.RelayShard()
if err != nil {
pm.logger.Error("could not obtain the cluster and shards of wakunode", zap.Error(err))
return
} else if rs == nil {
pm.logger.Info("not using sharding")
return
}
if pm.metadata != nil && rs.ClusterID != 0 {
} else if rs != nil && rs.ClusterID != 0 {
ctx, cancel := context.WithTimeout(pm.ctx, 7*time.Second)
defer cancel()
if err := pm.metadata.DisconnectPeerOnShardMismatch(ctx, peerEvt.PeerID); err != nil {
return
}
}
}
err = wps.AddPubSubTopic(peerID, peerEvt.PubsubTopic)
err := wps.AddPubSubTopic(peerID, peerEvt.PubsubTopic)
if err != nil {
pm.logger.Error("failed to add pubSubTopic for peer",
logging.HostID("peerID", peerID), zap.String("topic", peerEvt.PubsubTopic), zap.Error(err))