Conversation
|
@magik6k since these are going to be user facing APIs, lets go ahead and make this all godoc compliant |
9aae19d to
a56eade
Compare
| api, | ||
| nil, | ||
| } | ||
| } |
There was a problem hiding this comment.
Is this multiline format what gofmt emitted?
a56eade to
f6d74af
Compare
core/coreapi/interface/interface.go
Outdated
| type IpnsEntry struct { | ||
| Name string | ||
| Value Path | ||
| } |
There was a problem hiding this comment.
I wonder if we should make IpnsEntry an interface, in the spirit of future extensibility. Opinions on that?
There was a problem hiding this comment.
On the topic of future extensibility, we should also consider adding TTL/expiry to the returned values.
core/coreapi/interface/interface.go
Outdated
| // WithKey is an option for Publish which specifies the key to use for | ||
| // publishing. Default value is "self" which is the node's own PeerID. | ||
| // | ||
| // You can use .Key API to list and generate more names and their respective keys. |
f6d74af to
1d0e236
Compare
ghost
left a comment
There was a problem hiding this comment.
This looks pretty good overall :) 🤖 Left a few comments and questions
core/coreapi/interface/interface.go
Outdated
|
|
||
| // WithNoCache is an option for Resolve which specifies when set to true | ||
| // disables the use of local name cache. Default value is false | ||
| WithNoCache(nocache bool) options.NameResolveOption |
There was a problem hiding this comment.
I have a hunch we shouldn't make this a negative, even if it's already a negative in the CLI/API -- opinions?
core/coreapi/interface/interface.go
Outdated
| // Supported algorithms: | ||
| // * rsa | ||
| // * ed25519 | ||
| WithAlgorithm(algorithm string) options.KeyGenerateOption |
There was a problem hiding this comment.
Let's call this WithType(), following ipfs key generate --type=
We can have consts for the key types:
const (
RSAKey = "rsa"
Ed25519Key = "ed25519"
)
keyapi.Generate(ctx, "my-key", keyapi.WithType(coreopts.Ed25519Key))
core/coreapi/interface/interface.go
Outdated
| WithForce(force bool) options.KeyRenameOption | ||
|
|
||
| // List lists keys stored in keystore | ||
| List(ctx context.Context) (map[string]string, error) //TODO: better key type? |
There was a problem hiding this comment.
//TODO: better key type?
Let's make it a Key interface (for easier future extensibility)
type Key interface {
Name() string
Type() string // is the type exposed through the keystore?
Path() Path // => /ipns/QmPeerID
}There was a problem hiding this comment.
Also, any opinion on returning a map[string]Key or a []Key here?
core/coreapi/interface/interface.go
Outdated
| type KeyAPI interface { | ||
| // Generate generates new key, stores it in the keystore under the specified | ||
| // name and returns a base58 encoded multihash of it's public key | ||
| Generate(ctx context.Context, name string, opts ...options.KeyGenerateOption) (string, error) |
There was a problem hiding this comment.
Should we return Paths instead of PeerID strings?
|
|
||
| func NamePublishOptions(opts ...NamePublishOption) (*NamePublishSettings, error) { | ||
| options := &NamePublishSettings{ | ||
| ValidTime: 24 * time.Hour, |
There was a problem hiding this comment.
Should have DefaultValidTime = 24 * time.Hour for this
core/coreapi/key.go
Outdated
|
|
||
| func (api *KeyAPI) Rename(ctx context.Context, oldName string, newName string, opts ...caopts.KeyRenameOption) (string, bool, error) { | ||
| options, err := caopts.KeyRenameOptions(opts...) | ||
| if newName == "self" { |
There was a problem hiding this comment.
This looks like it should be err != nil, typo?
core/coreapi/name.go
Outdated
|
|
||
| if n.Identity == "" { | ||
| return nil, errors.New("identity not loaded") | ||
| } |
There was a problem hiding this comment.
We don't use n.Identity, I think this check can be removed
| settings.Key = key | ||
| return nil | ||
| } | ||
| } |
There was a problem hiding this comment.
I noticed key can be both a key name and peerID (see keylookup()) -- cool! Let's make sure to document that :)
e280cd4 to
b80a76e
Compare
|
Waiting for #4471 to be merged for test utils |
b80a76e to
1123587
Compare
|
@magik6k merged the other PR, let me know when to look at this one again |
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
1123587 to
8df2d1a
Compare
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
067ae52 to
396c34b
Compare
| } | ||
|
|
||
| func TestBasicPublishResolveTimeout(t *testing.T) { | ||
| t.Skip("ValidTime doesn't appear to work at this time resolution") |
There was a problem hiding this comment.
@whyrusleeping, I noticed that ValidTime doesn't seem to work at this time scale. Is this by design (should I drop this test), or is there a better way to do this (or is it a bug)?
There was a problem hiding this comment.
hrm... thats tricky. It should be okay at 100ms... I'm not sure this isnt a bug. How does it fail?
|
Added tests, fixed some bugs they caught, other than that one question and after test are reviewed this PR is RTM. |
|
|
||
| // WithSize is an option for Generate which specifies the size of the key to | ||
| // generated. Default is 0 | ||
| WithSize(size int) options.KeyGenerateOption |
There was a problem hiding this comment.
It feels a bit weird having these options be part of the interface... cc @lgierth
There was a problem hiding this comment.
The thinking was that in the future some of these option funcs might depend on state of the KeyAPI object. But actually in these cases we can just pass it in as an argument, e.g. keyapi.Generate(ctx, "mykey", coreopts.WithType(coreopts.Ed25519Key))
Drawback: the likelyhood of name collisions increases: there's more "type" options than just the one in key/generate. We can prefix these funcs, e.g. coreopts.WithKeyType, or we can make a conversion similar to the api.KeyAPI() conversions: opts := api.Options(); keyopts := opts.KeyOptions()
There was a problem hiding this comment.
Oh, so all the options are in the same package?
There was a problem hiding this comment.
They are in one package, though are scoped per API, see https://github.com/ipfs/go-ipfs/pull/4477/files#diff-764a71d2f522b4136e7909befd573776R53 (or the tests).
For key API, type will always mean 'key type'. In the case where we create another function for which it would make sense to pass this option, it's possible to reuse that (with some more go types magic)
| return nil, err | ||
| } | ||
|
|
||
| if pid.Pretty() == k { |
There was a problem hiding this comment.
when could this ever not be the case?
There was a problem hiding this comment.
We're iterating over all keys in the keystore and this is our return condition -- it's not a sanity assertion :)
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
7f4f086 to
2109cbc
Compare
TODO:
Note that most of the implementation code comes form respective commands, if this get's merged, I'll rewrite them to use this API.