Skip to content

Commit

Permalink
Fix deleting pubsub topics; only allow adding unique topics
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy Vlasov committed Sep 22, 2023
1 parent a84701a commit 201e1b1
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions waku/v2/peerstore/waku_peer_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ func (ps *WakuPeerstoreImpl) AddPubSubTopic(p peer.ID, topic string) error {
if err != nil {
return err
}
for _, t := range existingTopics {
if t == topic {
return errors.New("Pubsub topic already exists")
}
}
existingTopics = append(existingTopics, topic)
return ps.peerStore.Put(p, peerPubSubTopics, existingTopics)
}
Expand All @@ -170,8 +175,11 @@ func (ps *WakuPeerstoreImpl) RemovePubSubTopic(p peer.ID, topic string) error {
return nil
}

for i := range existingTopics {
existingTopics = append(existingTopics[:i], existingTopics[i+1:]...)
for i, t := range existingTopics {
if t == topic {
existingTopics = append(existingTopics[:i], existingTopics[i+1:]...)
break
}
}
err = ps.SetPubSubTopics(p, existingTopics)
if err != nil {
Expand Down

0 comments on commit 201e1b1

Please sign in to comment.