-
-
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
Added /name/upload command definition #3547
Closed
Closed
Changes from all commits
Commits
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ os: | |
- osx | ||
|
||
language: go | ||
go_import_path: github.com/ipfs/go-ipfs | ||
|
||
go: | ||
- 1.7 | ||
|
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
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
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 |
---|---|---|
|
@@ -12,12 +12,91 @@ import ( | |
core "github.com/ipfs/go-ipfs/core" | ||
path "github.com/ipfs/go-ipfs/path" | ||
|
||
multibase "gx/ipfs/QmShp7G5GEsLVZ52imm6VP4nukpc5ipdHbscrxJMNasmSd/go-multibase" | ||
peer "gx/ipfs/QmfMmLGoKzCHDN7cGgk64PJr4iipzidDRME8HABSJqvmhC/go-libp2p-peer" | ||
crypto "gx/ipfs/QmfWDLQjGjVe4fr5CoztYW2DYYjRysMJrFe1RCsXLPTf46/go-libp2p-crypto" | ||
) | ||
|
||
var errNotOnline = errors.New("This command must be run in online mode. Try running 'ipfs daemon' first.") | ||
|
||
type UploadResult struct { | ||
Peer string | ||
OldSeq uint64 | ||
NewSeq uint64 | ||
NewPath path.Path | ||
} | ||
|
||
var UploadNameCmd = &cmds.Command{ | ||
Helptext: cmds.HelpText{ | ||
Tagline: "Upload a signed IPNS record to an IPFS node", | ||
}, | ||
|
||
Arguments: []cmds.Argument{ | ||
cmds.StringArg("ipns-rec", true, false, "binary IPNS record").EnableStdin(), | ||
}, | ||
Options: []cmds.Option{ | ||
cmds.StringOption("key", "Public key of the author who signed the IPNS record"), | ||
}, | ||
|
||
Run: func(req cmds.Request, res cmds.Response) { | ||
log.Debug("begin name upload") | ||
n, err := getNodeWithNamesys(req, res) | ||
if err != nil { | ||
res.SetError(err, cmds.ErrNormal) | ||
return | ||
} | ||
|
||
if len(req.Arguments()) != 1 { | ||
res.SetError(errors.New("Must provide the IPNS record as the single argument"), cmds.ErrNormal) | ||
return | ||
} | ||
|
||
_, record, err := multibase.Decode(req.Arguments()[0]) | ||
if err != nil { | ||
res.SetError(err, cmds.ErrNormal) | ||
return | ||
} | ||
|
||
ctx := req.Context() | ||
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. move this closer to where its used |
||
pubkeyString, found, err := req.Option("key").String() | ||
if err != nil { | ||
res.SetError(err, cmds.ErrNormal) | ||
return | ||
} | ||
if !found { | ||
res.SetError(errors.New("Must provide a public key as the --key option"), cmds.ErrNormal) | ||
return | ||
} | ||
|
||
_, pubkeyBytes, err := multibase.Decode(pubkeyString) | ||
if err != nil { | ||
res.SetError(err, cmds.ErrNormal) | ||
return | ||
} | ||
|
||
pubkey, err := crypto.UnmarshalPublicKey(pubkeyBytes) | ||
crypto.MarshalPublicKey(pubkey) | ||
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. this line is unnecessary |
||
if err != nil { | ||
res.SetError(err, cmds.ErrNormal) | ||
return | ||
} | ||
|
||
id, oldSeq, newSeq, newPath, err := n.Namesys.Upload(ctx, pubkey, record) | ||
res.SetOutput(&UploadResult{Peer: id.Pretty(), OldSeq: oldSeq, NewSeq: newSeq, NewPath: newPath}) | ||
if err != nil { | ||
res.SetError(err, cmds.ErrNormal) | ||
return | ||
} | ||
}, | ||
Marshalers: cmds.MarshalerMap{ | ||
cmds.Text: func(res cmds.Response) (io.Reader, error) { | ||
o := res.Output().(*UploadResult) | ||
return strings.NewReader(fmt.Sprintf("/ipns/%s was set to %s (old seq=%d, new seq=%d)\n", o.Peer, o.NewPath, o.OldSeq, o.NewSeq)), nil | ||
}, | ||
}, | ||
Type: UploadResult{}, | ||
} | ||
|
||
var PublishCmd = &cmds.Command{ | ||
Helptext: cmds.HelpText{ | ||
Tagline: "Publish an object to IPNS.", | ||
|
@@ -38,11 +117,6 @@ Publish an <ipfs-path> to your identity name: | |
> ipfs name publish /ipfs/QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy | ||
Published to QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n: /ipfs/QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy | ||
|
||
Publish an <ipfs-path> to another public key (not implemented): | ||
|
||
> ipfs name publish /ipfs/QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n | ||
Published to QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n: /ipfs/QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy | ||
|
||
`, | ||
}, | ||
|
||
|
@@ -60,32 +134,13 @@ Publish an <ipfs-path> to another public key (not implemented): | |
}, | ||
Run: func(req cmds.Request, res cmds.Response) { | ||
log.Debug("begin publish") | ||
n, err := req.InvocContext().GetNode() | ||
n, err := getNodeWithNamesys(req, res) | ||
if err != nil { | ||
res.SetError(err, cmds.ErrNormal) | ||
return | ||
} | ||
|
||
if !n.OnlineMode() { | ||
err := n.SetupOfflineRouting() | ||
if err != nil { | ||
res.SetError(err, cmds.ErrNormal) | ||
return | ||
} | ||
} | ||
|
||
if n.Mounts.Ipns != nil && n.Mounts.Ipns.IsActive() { | ||
res.SetError(errors.New("You cannot manually publish while IPNS is mounted."), cmds.ErrNormal) | ||
return | ||
} | ||
|
||
pstr := req.Arguments()[0] | ||
|
||
if n.Identity == "" { | ||
res.SetError(errors.New("Identity not loaded!"), cmds.ErrNormal) | ||
return | ||
} | ||
|
||
popts := new(publishOpts) | ||
|
||
popts.verifyExists, _, _ = req.Option("resolve").Bool() | ||
|
@@ -134,6 +189,35 @@ Publish an <ipfs-path> to another public key (not implemented): | |
Type: IpnsEntry{}, | ||
} | ||
|
||
func getNodeWithNamesys(req cmds.Request, res cmds.Response) (n *core.IpfsNode, err error) { | ||
n, err = req.InvocContext().GetNode() | ||
if err != nil { | ||
res.SetError(err, cmds.ErrNormal) | ||
return | ||
} | ||
|
||
if !n.OnlineMode() { | ||
err = n.SetupOfflineRouting() | ||
if err != nil { | ||
res.SetError(err, cmds.ErrNormal) | ||
return | ||
} | ||
} | ||
|
||
if n.Mounts.Ipns != nil && n.Mounts.Ipns.IsActive() { | ||
err = errors.New("You cannot manually publish while IPNS is mounted.") | ||
res.SetError(err, cmds.ErrNormal) | ||
return | ||
} | ||
|
||
if n.Identity == "" { | ||
err = errors.New("Identity not loaded!") | ||
res.SetError(err, cmds.ErrNormal) | ||
} | ||
|
||
return | ||
} | ||
|
||
type publishOpts struct { | ||
verifyExists bool | ||
pubValidTime time.Duration | ||
|
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
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
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
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
Oops, something went wrong.
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.
upload probably isnt the best name for this feature... maybe something like
publish-record
could be used, since its not intented as a common thing?cc @Kubuxu @diasdavid @lgierth
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.
Given that record stores will be simple stores with get/put interfaces, something like
/record/put
sounds like a good name to me