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