Skip to content

Commit

Permalink
add the peerID of announcer to a list and no longer accepts the pubsub
Browse files Browse the repository at this point in the history
Also added lock on the bl.members
  • Loading branch information
ehsan6sha committed Nov 7, 2023
1 parent 5c4d12f commit 98a7cb8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions blockchain/bl_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,10 @@ func (bl *FxBlockchain) HandlePoolJoinRequest(ctx context.Context, from peer.ID,

// Handle the response as needed
log.Infow("Vote cast successfully", "response", voteResponse)
// Update member status to unknown
bl.membersLock.Lock() // Lock before accessing the map
bl.members[from] = common.Unknown
bl.membersLock.Unlock() // Unlock after accessing the map

} else {
return fmt.Errorf("peerID does not exists in the list of pool requests: %s with status %d", from, status)
Expand Down
7 changes: 6 additions & 1 deletion blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ type (
p *ping.FxPing
a *announcements.FxAnnouncements

members map[peer.ID]common.MemberStatus
members map[peer.ID]common.MemberStatus
membersLock sync.RWMutex
}
authorizationRequest struct {
Subject peer.ID `json:"id"`
Expand Down Expand Up @@ -551,6 +552,7 @@ func (bl *FxBlockchain) FetchUsersAndPopulateSets(ctx context.Context, topicStri
}

// Now iterate through the users and populate the member map
bl.membersLock.Lock()
for _, user := range response.Users {
pid, err := peer.Decode(user.PeerID)
if err != nil {
Expand Down Expand Up @@ -597,15 +599,18 @@ func (bl *FxBlockchain) FetchUsersAndPopulateSets(ctx context.Context, topicStri
bl.members[pid] = status
}
}
bl.membersLock.Unlock()

return nil
}

func (bl *FxBlockchain) GetMemberStatus(id peer.ID) (common.MemberStatus, bool) {
bl.membersLock.RLock()
status, exists := bl.members[id]
if !exists {
// If the peer.ID doesn't exist in the members map, we treat it as an error case.
return common.MemberStatus(0), false
}
bl.membersLock.RUnlock()
return status, true
}

0 comments on commit 98a7cb8

Please sign in to comment.