-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
WIP: add PeerID lookup #3882
Merged
Merged
WIP: add PeerID lookup #3882
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 |
---|---|---|
|
@@ -48,6 +48,11 @@ Publish an <ipfs-path> with another name, added by an 'ipfs key' command: | |
> ipfs name publish --key=mykey /ipfs/QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy | ||
Published to QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n: /ipfs/QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy | ||
|
||
Alternatively, publish an <ipfs-path> using a valid PeerID(as listed by 'ipfs key list -l'): | ||
|
||
> ipfs name publish --key=QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n /ipfs/QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy | ||
Published to QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n: /ipfs/QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy | ||
|
||
`, | ||
}, | ||
|
||
|
@@ -61,7 +66,7 @@ Publish an <ipfs-path> with another name, added by an 'ipfs key' command: | |
This accepts durations such as "300s", "1.5h" or "2h45m". Valid time units are | ||
"ns", "us" (or "µs"), "ms", "s", "m", "h".`).Default("24h"), | ||
cmds.StringOption("ttl", "Time duration this record should be cached for (caution: experimental)."), | ||
cmds.StringOption("key", "k", "Name of the key to be used, as listed by 'ipfs key list'. Default: <<default>>.").Default("self"), | ||
cmds.StringOption("key", "k", "Name of the key to be used or a valid PeerID, as listed by 'ipfs key list -l'. Default: <<default>>.").Default("self"), | ||
}, | ||
Run: func(req cmds.Request, res cmds.Response) { | ||
log.Debug("begin publish") | ||
|
@@ -116,7 +121,7 @@ Publish an <ipfs-path> with another name, added by an 'ipfs key' command: | |
} | ||
|
||
kname, _, _ := req.Option("key").String() | ||
k, err := n.GetKey(kname) | ||
k, err := keylookup(kname, n) | ||
if err != nil { | ||
res.SetError(err, cmds.ErrNormal) | ||
return | ||
|
@@ -176,3 +181,36 @@ func publish(ctx context.Context, n *core.IpfsNode, k crypto.PrivKey, ref path.P | |
Value: ref.String(), | ||
}, nil | ||
} | ||
|
||
func keylookup(k string, n *core.IpfsNode) (crypto.PrivKey, error) { | ||
|
||
res, err := n.GetKey(k) | ||
if res != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would check here if error is different than |
||
return res, nil | ||
} | ||
|
||
keys, err := n.Repo.Keystore().List() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, key := range keys { | ||
privKey, err := n.Repo.Keystore().Get(key) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
pubKey := privKey.GetPublic() | ||
|
||
pid, err := peer.IDFromPublicKey(pubKey) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if pid.Pretty() == k { | ||
return privKey, nil | ||
} | ||
} | ||
|
||
return nil, fmt.Errorf("no key by the given name or PeerID was found") | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make the Node first argument.