-
Notifications
You must be signed in to change notification settings - Fork 525
cmd: Add goal node subcommand to generate peer private key #6078
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
Merged
algorandskiy
merged 6 commits into
algorand:master
from
algorandskiy:pavel/p2p-peerkey-gen
Aug 1, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9b23a43
cmd: Add a simple cli util to generate peer private key and print out…
algorandskiy 6e94067
update help string
algorandskiy eccb057
Merge remote-tracking branch 'upstream/master' into pavel/p2p-peerkey…
algorandskiy dc8b3e0
move to `goal node generate-p2pid` subcommand
algorandskiy 6f3b9ba
properly support multuple data dirs
algorandskiy 375efad
use anyError
algorandskiy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| // Copyright (C) 2019-2024 Algorand, Inc. | ||
| // This file is part of go-algorand | ||
| // | ||
| // go-algorand is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Affero General Public License as | ||
| // published by the Free Software Foundation, either version 3 of the | ||
| // License, or (at your option) any later version. | ||
| // | ||
| // go-algorand is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Affero General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Affero General Public License | ||
| // along with go-algorand. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| // generate a new p2p private key and print out peerID to stdout | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "path" | ||
|
|
||
| "github.com/algorand/go-algorand/cmd/util/datadir" | ||
| "github.com/algorand/go-algorand/config" | ||
| "github.com/algorand/go-algorand/network/p2p" | ||
| "github.com/algorand/go-algorand/util" | ||
| "github.com/libp2p/go-libp2p/core/peer" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| var p2pID = &cobra.Command{ | ||
| Use: "generate-p2pid", | ||
| Short: "Generate a new p2p private key", | ||
| Long: "Generate a new p2p private key (saved to " + p2p.DefaultPrivKeyPath + ") and print out peerID to stdout", | ||
| Args: validateNoPosArgsFn, | ||
| Run: func(cmd *cobra.Command, args []string) { | ||
| anyError := false | ||
| datadir.OnDataDirs(func(dataDir string) { | ||
| exist := false | ||
| privKeyPath := path.Join(dataDir, p2p.DefaultPrivKeyPath) | ||
| if util.FileExists(privKeyPath) { | ||
| exist = true | ||
| } | ||
|
|
||
| peerKey, err := p2p.GetPrivKey(config.Local{P2PPersistPeerID: true}, dataDir) | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error obtaining private key: %v\n", err) | ||
| anyError = true | ||
| return | ||
| } | ||
| peerID, err := peer.IDFromPublicKey(peerKey.GetPublic()) | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error obtaining peerID from a key: %v\n", err) | ||
| anyError = true | ||
| return | ||
|
jasonpaulos marked this conversation as resolved.
|
||
| } | ||
|
|
||
| fmt.Printf("PeerID: %s\n", peerID.String()) | ||
| if !exist { | ||
| fmt.Printf("Private key saved to %s\n", privKeyPath) | ||
| } else { | ||
| fmt.Printf("Used existing key %s\n", privKeyPath) | ||
| } | ||
| }) | ||
| if anyError { | ||
| os.Exit(1) | ||
| } | ||
| }, | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.