Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make sure list of authorized peers is unique #159

Merged
merged 1 commit into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions cmd/blox/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,27 @@ func updateConfig(p []peer.ID) error {
return err
}

// Create a map to hold unique peer IDs
uniquePeers := make(map[string]bool)

// Add existing AuthorizedPeers to the map
for _, pidStr := range app.config.AuthorizedPeers {
uniquePeers[pidStr] = true
}

// Convert the slice of peer.ID to a slice of strings
app.config.AuthorizedPeers = make([]string, len(p))
for i, pid := range p {
app.config.AuthorizedPeers[i] = pid.String()
for _, pid := range p {
// Convert the peer.ID to string
pidStr := pid.String()
// Check if the peer.ID is already in the map
if !uniquePeers[pidStr] {
// If it's not in the map, add it to the map and the slice
uniquePeers[pidStr] = true
app.config.AuthorizedPeers = append(app.config.AuthorizedPeers, pidStr)
}
}

logger.Infof("Authorized peers: %v", app.config.AuthorizedPeers)
// Write back the updated config to the file
configData, err = yaml.Marshal(app.config)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions exchange/fx_exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ func (e *FxExchange) handleAuthorization(from peer.ID, w http.ResponseWriter, r
} else {
delete(e.authorizedPeers, a.Subject)
}
log.Infow("Authorizing peers for ", "a.Subject", a.Subject, "from", from)
e.authorizedPeersLock.Unlock()
if err := e.updateAuthorizePeers(ctx); err != nil {
log.Errorw("failed to update authorized peers", "err", err)
Expand Down