Commit 8f7e0241 authored by Łukasz Magiera's avatar Łukasz Magiera

coreapi: name/key review suggestions

License: MIT
Signed-off-by: default avatarŁukasz Magiera <magik6k@gmail.com>
parent 74695ab9
...@@ -28,16 +28,21 @@ type Path interface { ...@@ -28,16 +28,21 @@ type Path interface {
type Node ipld.Node type Node ipld.Node
type Link ipld.Link type Link ipld.Link
type IpnsEntry struct {
Name string
Value Path
}
type Reader interface { type Reader interface {
io.ReadSeeker io.ReadSeeker
io.Closer io.Closer
} }
type IpnsEntry interface {
Name() string
Value() Path
}
type Key interface {
Name() string
Path() Path
}
// CoreAPI defines an unified interface to IPFS for Go programs. // CoreAPI defines an unified interface to IPFS for Go programs.
type CoreAPI interface { type CoreAPI interface {
// Unixfs returns an implementation of Unixfs API // Unixfs returns an implementation of Unixfs API
...@@ -108,7 +113,7 @@ type DagAPI interface { ...@@ -108,7 +113,7 @@ type DagAPI interface {
// You can use .Key API to list and generate more names and their respective keys. // You can use .Key API to list and generate more names and their respective keys.
type NameAPI interface { type NameAPI interface {
// Publish announces new IPNS name // Publish announces new IPNS name
Publish(ctx context.Context, path Path, opts ...options.NamePublishOption) (*IpnsEntry, error) Publish(ctx context.Context, path Path, opts ...options.NamePublishOption) (IpnsEntry, error)
// WithValidTime is an option for Publish which specifies for how long the // WithValidTime is an option for Publish which specifies for how long the
// entry will remain valid. Default value is 24h // entry will remain valid. Default value is 24h
...@@ -116,8 +121,9 @@ type NameAPI interface { ...@@ -116,8 +121,9 @@ type NameAPI interface {
// WithKey is an option for Publish which specifies the key to use for // 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. // publishing. Default value is "self" which is the node's own PeerID.
// The key parameter must be either PeerID or keystore key alias.
// //
// You can use .Key API to list and generate more names and their respective keys. // You can use KeyAPI to list and generate more names and their respective keys.
WithKey(key string) options.NamePublishOption WithKey(key string) options.NamePublishOption
// Resolve attempts to resolve the newest version of the specified name // Resolve attempts to resolve the newest version of the specified name
...@@ -131,41 +137,42 @@ type NameAPI interface { ...@@ -131,41 +137,42 @@ type NameAPI interface {
// offline. Default value is false // offline. Default value is false
WithLocal(local bool) options.NameResolveOption WithLocal(local bool) options.NameResolveOption
// WithNoCache is an option for Resolve which specifies when set to true // WithCache is an option for Resolve which specifies if cache should be used.
// disables the use of local name cache. Default value is false // Default value is true
WithNoCache(nocache bool) options.NameResolveOption WithCache(cache bool) options.NameResolveOption
} }
// KeyAPI specifies the interface to Keystore // KeyAPI specifies the interface to Keystore
type KeyAPI interface { type KeyAPI interface {
// Generate generates new key, stores it in the keystore under the specified // Generate generates new key, stores it in the keystore under the specified
// name and returns a base58 encoded multihash of it's public key // name and returns a base58 encoded multihash of it's public key
Generate(ctx context.Context, name string, opts ...options.KeyGenerateOption) (string, error) Generate(ctx context.Context, name string, opts ...options.KeyGenerateOption) (Key, error)
// WithAlgorithm is an option for Generate which specifies which algorithm // WithAlgorithm is an option for Generate which specifies which algorithm
// should be used for the key. Default is "rsa" // should be used for the key. Default is options.RSAKey
// //
// Supported algorithms: // Supported algorithms:
// * rsa // * options.RSAKey
// * ed25519 // * options.Ed25519Key
WithAlgorithm(algorithm string) options.KeyGenerateOption WithAlgorithm(algorithm string) options.KeyGenerateOption
// WithSize is an option for Generate which specifies the size of the key to // WithSize is an option for Generate which specifies the size of the key to
// generated. Default is 0 // generated. Default is 0
WithSize(size int) options.KeyGenerateOption WithSize(size int) options.KeyGenerateOption
// Rename renames oldName key to newName. // Rename renames oldName key to newName. Returns the key and whether another
Rename(ctx context.Context, oldName string, newName string, opts ...options.KeyRenameOption) (string, bool, error) // key was overwritten, or an error
Rename(ctx context.Context, oldName string, newName string, opts ...options.KeyRenameOption) (Key, bool, error)
// WithForce is an option for Rename which specifies whether to allow to // WithForce is an option for Rename which specifies whether to allow to
// replace existing keys. // replace existing keys.
WithForce(force bool) options.KeyRenameOption WithForce(force bool) options.KeyRenameOption
// List lists keys stored in keystore // List lists keys stored in keystore
List(ctx context.Context) (map[string]string, error) //TODO: better key type? List(ctx context.Context) ([]Key, error)
// Remove removes keys from keystore // Remove removes keys from keystore. Returns ipns path of the removed key
Remove(ctx context.Context, name string) (string, error) Remove(ctx context.Context, name string) (Path, error)
} }
// type ObjectAPI interface { // type ObjectAPI interface {
......
package options package options
const (
RSAKey = "rsa"
Ed25519Key = "ed25519"
)
type KeyGenerateSettings struct { type KeyGenerateSettings struct {
Algorithm string Algorithm string
Size int Size int
...@@ -14,7 +19,7 @@ type KeyRenameOption func(*KeyRenameSettings) error ...@@ -14,7 +19,7 @@ type KeyRenameOption func(*KeyRenameSettings) error
func KeyGenerateOptions(opts ...KeyGenerateOption) (*KeyGenerateSettings, error) { func KeyGenerateOptions(opts ...KeyGenerateOption) (*KeyGenerateSettings, error) {
options := &KeyGenerateSettings{ options := &KeyGenerateSettings{
Algorithm: "rsa", Algorithm: RSAKey,
Size: 0, Size: 0,
} }
......
...@@ -4,6 +4,10 @@ import ( ...@@ -4,6 +4,10 @@ import (
"time" "time"
) )
const (
DefaultNameValidTime = 24 * time.Hour
)
type NamePublishSettings struct { type NamePublishSettings struct {
ValidTime time.Duration ValidTime time.Duration
Key string Key string
...@@ -12,7 +16,7 @@ type NamePublishSettings struct { ...@@ -12,7 +16,7 @@ type NamePublishSettings struct {
type NameResolveSettings struct { type NameResolveSettings struct {
Recursive bool Recursive bool
Local bool Local bool
Nocache bool Cache bool
} }
type NamePublishOption func(*NamePublishSettings) error type NamePublishOption func(*NamePublishSettings) error
...@@ -20,7 +24,7 @@ type NameResolveOption func(*NameResolveSettings) error ...@@ -20,7 +24,7 @@ type NameResolveOption func(*NameResolveSettings) error
func NamePublishOptions(opts ...NamePublishOption) (*NamePublishSettings, error) { func NamePublishOptions(opts ...NamePublishOption) (*NamePublishSettings, error) {
options := &NamePublishSettings{ options := &NamePublishSettings{
ValidTime: 24 * time.Hour, ValidTime: DefaultNameValidTime,
Key: "self", Key: "self",
} }
...@@ -38,7 +42,7 @@ func NameResolveOptions(opts ...NameResolveOption) (*NameResolveSettings, error) ...@@ -38,7 +42,7 @@ func NameResolveOptions(opts ...NameResolveOption) (*NameResolveSettings, error)
options := &NameResolveSettings{ options := &NameResolveSettings{
Recursive: false, Recursive: false,
Local: false, Local: false,
Nocache: false, Cache: true,
} }
for _, opt := range opts { for _, opt := range opts {
...@@ -81,9 +85,9 @@ func (api *NameOptions) WithLocal(local bool) NameResolveOption { ...@@ -81,9 +85,9 @@ func (api *NameOptions) WithLocal(local bool) NameResolveOption {
} }
} }
func (api *NameOptions) WithNoCache(nocache bool) NameResolveOption { func (api *NameOptions) WithCache(cache bool) NameResolveOption {
return func(settings *NameResolveSettings) error { return func(settings *NameResolveSettings) error {
settings.Nocache = nocache settings.Cache = cache
return nil return nil
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment