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' #9192

Closed
wants to merge 4 commits into from

Conversation

samuelbacaner
Copy link

Resolves #7880 where @Stebalien proposes several new CLI commands. #8147 implements most of the actual functionality.

This PR adds the --save option to both ipfs swarm peering add and ipfs swarm peering rm. With this boolean option set, the mutated peering set will be written to the configuration on disk.

@welcome
Copy link

welcome bot commented Aug 14, 2022

Thank you for submitting this PR!
A maintainer will be here shortly to review it.
We are super grateful, but we are also overloaded! Help us by making sure that:

  • The context for this PR is clear, with relevant discussion, decisions
    and stakeholders linked/mentioned.

  • Your contribution itself is clear (code comments, self-review for the
    rest) and in its best form. Follow the code contribution
    guidelines

    if they apply.

Getting other community members to do a review would be great help too on complex PRs (you can ask in the chats/forums). If you are unsure about something, just leave us a comment.
Next steps:

  • A maintainer will triage and assign priority to this PR, commenting on
    any missing things and potentially assigning a reviewer for high
    priority items.

  • The PR gets reviews, discussed and approvals as needed.

  • The PR is merged by maintainers when it has been approved and comments addressed.

We currently aim to provide initial feedback/triaging within two business days. Please keep an eye on any labelling actions, as these will indicate priorities and status of your contribution.
We are very grateful for your contribution!

@samuelbacaner samuelbacaner marked this pull request as draft August 14, 2022 15:16
@samuelbacaner
Copy link
Author

All tests pass for me locally except for generated completions defines '_ipfs'. It fails with this error output:

completions.bash: line 5527: complete: nosort: invalid option name
not ok 2 - generated completions defines '_ipfs'

I suspect, based on this thread on the Homebrew mailing list, that this is because I have Bash 3 installed on my Mac.

$ bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin21)
Copyright (C) 2007 Free Software Foundation, Inc.

I'll be interested to see if the test passes in CI when someone comes around who is authorized to run them. Marking this as open for review now in hopes that this is just a me issue.

core/commands/swarm.go Show resolved Hide resolved
if save {
r, err := fsrepo.Open(env.(*commands.Context).ConfigRoot)
if err != nil {
return err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you wrap this with a descriptive error?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in this commit.

defer r.Close()
cfg, err := r.Config()
if err != nil {
return err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you wrap this with a descriptive error?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in this commit.

core/commands/swarm.go Show resolved Hide resolved
defer r.Close()
cfg, err := r.Config()
if err != nil {
return err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you wrap this with a descriptive error?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in this commit.

if save {
r, err := fsrepo.Open(env.(*commands.Context).ConfigRoot)
if err != nil {
return err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you wrap this with a descriptive error?

Comment on lines 236 to 246
save, _ := req.Options[swarmSaveOptionName].(bool)
if save {
r, err := fsrepo.Open(env.(*commands.Context).ConfigRoot)
if err != nil {
return err
}
defer r.Close()
cfg, err := r.Config()
if err != nil {
return err
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can avoid repeating all this code and separate it into a function.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Factored out into new method updateAndPersistConfig in this commit.

return err
}

addrInfos, err := mergeAddrInfo(addInfos, cfg.Peering.Peers)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if I'm wrong, but we can do the same as we are doing in line 248 to set the peers, avoiding even more duplicated lines.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Simplified in this commit.

@samuelbacaner samuelbacaner requested review from ajnavarro and Jorropo and removed request for ajnavarro and Jorropo August 25, 2022 13:39
}
update(cfg)
if err := r.SetConfig(cfg); err != nil {
return fmt.Errorf("error removing peers from repo config: %w", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this method is generic for any config param, we should update this error message.

@BigLep BigLep added this to the Best Effort Track milestone Sep 1, 2022
@BigLep BigLep added the need/author-input Needs input from the original author label Sep 1, 2022
@ajnavarro ajnavarro assigned ajnavarro and unassigned ajnavarro Oct 4, 2022
@ajnavarro
Copy link
Member

Superseded by #9425

@ajnavarro ajnavarro closed this Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need/author-input Needs input from the original author
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[Enhancement] Dynamic Peerlist adding / removing
4 participants