[go: nahoru, domu]

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

feature: Implement --save option in 'ipfs swarm peering add/rm' #9425

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Requested changes.
  • Loading branch information
ajnavarro committed Dec 6, 2022
commit 35efa59ee656069a08f2aef466c922d3847410c0
29 changes: 19 additions & 10 deletions core/commands/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ var swarmPeeringAddCmd = &cmds.Command{
save, _ := req.Options[swarmSaveOptionName].(bool)
if save {
update := func(cfg *config.Config) {
cfg.Peering.Peers = node.Peering.ListPeers()
cfg.Peering.Peers = append(cfg.Peering.Peers, addInfos...)
}
err := updateAndPersistConfig(env, update)
if err != nil {
Expand Down Expand Up @@ -231,16 +231,25 @@ var swarmPeeringRmCmd = &cmds.Command{
if err = res.Emit(peeringResult{id, "success"}); err != nil {
return err
}
}

save, _ := req.Options[swarmSaveOptionName].(bool)
if save {
update := func(cfg *config.Config) {
cfg.Peering.Peers = node.Peering.ListPeers()
}
err := updateAndPersistConfig(env, update)
if err != nil {
return fmt.Errorf("unable to update and persist config change: %w", err)
save, _ := req.Options[swarmSaveOptionName].(bool)
if save {
update := func(cfg *config.Config) {
var cfgOut []peer.AddrInfo
for _, p := range cfg.Peering.Peers {
if p.ID == id {
continue
}
cfgOut = append(cfgOut, p)
}

cfg.Peering.Peers = cfgOut
}

err := updateAndPersistConfig(env, update)
if err != nil {
return fmt.Errorf("unable to update and persist config change: %w", err)
}
}
}

Expand Down