Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
interface-go-dms3-core
Commits
8f7e0241
Commit
8f7e0241
authored
Dec 17, 2017
by
Łukasz Magiera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
coreapi: name/key review suggestions
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
parent
74695ab9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
25 deletions
+41
-25
interface.go
interface.go
+26
-19
options/key.go
options/key.go
+6
-1
options/name.go
options/name.go
+9
-5
No files found.
interface.go
View file @
8f7e0241
...
@@ -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
// With
No
Cache is an option for Resolve which specifies
w
he
n
s
et to true
// WithCache is an option for Resolve which specifies
if cac
he s
hould be used.
//
disables the use of local name cache.
Default value is
fals
e
// Default value is
tru
e
With
No
Cache
(
no
cache
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
// *
e
d25519
// *
options.E
d25519
Key
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 {
...
...
options/key.go
View file @
8f7e0241
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
,
}
}
...
...
options/name.go
View file @
8f7e0241
...
@@ -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
Noc
ache
bool
C
ache
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
,
Noc
ache
:
fals
e
,
C
ache
:
tru
e
,
}
}
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
)
With
No
Cache
(
no
cache
bool
)
NameResolveOption
{
func
(
api
*
NameOptions
)
WithCache
(
cache
bool
)
NameResolveOption
{
return
func
(
settings
*
NameResolveSettings
)
error
{
return
func
(
settings
*
NameResolveSettings
)
error
{
settings
.
Noc
ache
=
no
cache
settings
.
C
ache
=
cache
return
nil
return
nil
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment