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
db9865b9
Commit
db9865b9
authored
Mar 10, 2018
by
Łukasz Magiera
Committed by
Steven Allen
Sep 10, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
coreapi: implement dht api
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
parent
bbd736fd
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
1 deletion
+34
-1
coreapi.go
coreapi.go
+3
-0
dht.go
dht.go
+5
-1
options/dht.go
options/dht.go
+26
-0
No files found.
coreapi.go
View file @
db9865b9
...
...
@@ -31,6 +31,9 @@ type CoreAPI interface {
// ObjectAPI returns an implementation of Object API
Object
()
ObjectAPI
// Dht returns an implementation of Dht API
Dht
()
DhtAPI
// ResolvePath resolves the path using Unixfs resolver
ResolvePath
(
context
.
Context
,
Path
)
(
ResolvedPath
,
error
)
...
...
dht.go
View file @
db9865b9
...
...
@@ -17,7 +17,11 @@ type DhtAPI interface {
// FindProviders finds peers in the DHT who can provide a specific value
// given a key.
FindProviders
(
context
.
Context
,
Path
)
(
<-
chan
peer
.
ID
,
error
)
//TODO: is path the right choice here?
FindProviders
(
context
.
Context
,
Path
,
...
options
.
DhtFindProvidersOption
)
(
<-
chan
peer
.
ID
,
error
)
//TODO: is path the right choice here?
// WithNumProviders is an option for FindProviders which specifies the
// number of peers to look for. Default is 20
WithNumProviders
(
numProviders
int
)
options
.
DhtFindProvidersOption
// Provide announces to the network that you are providing given values
Provide
(
context
.
Context
,
Path
,
...
options
.
DhtProvideOption
)
error
...
...
options/dht.go
View file @
db9865b9
...
...
@@ -4,7 +4,12 @@ type DhtProvideSettings struct {
Recursive
bool
}
type
DhtFindProvidersSettings
struct
{
NumProviders
int
}
type
DhtProvideOption
func
(
*
DhtProvideSettings
)
error
type
DhtFindProvidersOption
func
(
*
DhtFindProvidersSettings
)
error
func
DhtProvideOptions
(
opts
...
DhtProvideOption
)
(
*
DhtProvideSettings
,
error
)
{
options
:=
&
DhtProvideSettings
{
...
...
@@ -20,6 +25,20 @@ func DhtProvideOptions(opts ...DhtProvideOption) (*DhtProvideSettings, error) {
return
options
,
nil
}
func
DhtFindProvidersOptions
(
opts
...
DhtFindProvidersOption
)
(
*
DhtFindProvidersSettings
,
error
)
{
options
:=
&
DhtFindProvidersSettings
{
NumProviders
:
20
,
}
for
_
,
opt
:=
range
opts
{
err
:=
opt
(
options
)
if
err
!=
nil
{
return
nil
,
err
}
}
return
options
,
nil
}
type
DhtOptions
struct
{}
func
(
api
*
DhtOptions
)
WithRecursive
(
recursive
bool
)
DhtProvideOption
{
...
...
@@ -28,3 +47,10 @@ func (api *DhtOptions) WithRecursive(recursive bool) DhtProvideOption {
return
nil
}
}
func
(
api
*
DhtOptions
)
WithNumProviders
(
numProviders
int
)
DhtFindProvidersOption
{
return
func
(
settings
*
DhtFindProvidersSettings
)
error
{
settings
.
NumProviders
=
numProviders
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