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
p2p
go-p2p-discovery
Commits
74aa1c8c
Unverified
Commit
74aa1c8c
authored
May 17, 2019
by
vyzo
Committed by
GitHub
May 17, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #25 from libp2p/feat/options
More consistent use of options
parents
4cb4193d
98c8684d
Pipeline
#557
failed with stages
in 0 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
9 deletions
+20
-9
routing.go
routing.go
+14
-3
routing_test.go
routing_test.go
+1
-1
util.go
util.go
+5
-5
No files found.
routing.go
View file @
74aa1c8c
...
...
@@ -21,6 +21,19 @@ func NewRoutingDiscovery(router routing.ContentRouting) *RoutingDiscovery {
}
func
(
d
*
RoutingDiscovery
)
Advertise
(
ctx
context
.
Context
,
ns
string
,
opts
...
Option
)
(
time
.
Duration
,
error
)
{
var
options
Options
err
:=
options
.
Apply
(
opts
...
)
if
err
!=
nil
{
return
0
,
err
}
ttl
:=
options
.
Ttl
if
ttl
==
0
||
ttl
>
3
*
time
.
Hour
{
// the DHT provider record validity is 24hrs, but it is recommnded to republish at least every 6hrs
// we go one step further and republish every 3hrs
ttl
=
3
*
time
.
Hour
}
cid
,
err
:=
nsToCid
(
ns
)
if
err
!=
nil
{
return
0
,
err
...
...
@@ -37,9 +50,7 @@ func (d *RoutingDiscovery) Advertise(ctx context.Context, ns string, opts ...Opt
return
0
,
err
}
// the DHT provider record validity is 24hrs, but it is recommnded to republish at least every 6hrs
// we go one step further and republish every 3hrs
return
3
*
time
.
Hour
,
nil
return
ttl
,
nil
}
func
(
d
*
RoutingDiscovery
)
FindPeers
(
ctx
context
.
Context
,
ns
string
,
opts
...
Option
)
(
<-
chan
pstore
.
PeerInfo
,
error
)
{
...
...
routing_test.go
View file @
74aa1c8c
...
...
@@ -89,7 +89,7 @@ func TestRoutingDiscovery(t *testing.T) {
t
.
Fatal
(
err
)
}
pis
,
err
:=
FindPeers
(
ctx
,
d2
,
"/test"
,
20
)
pis
,
err
:=
FindPeers
(
ctx
,
d2
,
"/test"
,
Limit
(
20
)
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
util.go
View file @
74aa1c8c
...
...
@@ -11,10 +11,10 @@ import (
var
log
=
logging
.
Logger
(
"discovery"
)
// FindPeers is a utility function that synchonously collects peers from a Discoverer
func
FindPeers
(
ctx
context
.
Context
,
d
Discoverer
,
ns
string
,
limit
int
)
([]
pstore
.
PeerInfo
,
error
)
{
res
:=
make
(
[]
pstore
.
PeerInfo
,
0
,
limit
)
func
FindPeers
(
ctx
context
.
Context
,
d
Discoverer
,
ns
string
,
opts
...
Option
)
([]
pstore
.
PeerInfo
,
error
)
{
var
res
[]
pstore
.
PeerInfo
ch
,
err
:=
d
.
FindPeers
(
ctx
,
ns
,
Limit
(
limit
)
)
ch
,
err
:=
d
.
FindPeers
(
ctx
,
ns
,
opts
...
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -27,10 +27,10 @@ func FindPeers(ctx context.Context, d Discoverer, ns string, limit int) ([]pstor
}
// Advertise is a utility function that persistently advertises a service through an Advertiser
func
Advertise
(
ctx
context
.
Context
,
a
Advertiser
,
ns
string
)
{
func
Advertise
(
ctx
context
.
Context
,
a
Advertiser
,
ns
string
,
opts
...
Option
)
{
go
func
()
{
for
{
ttl
,
err
:=
a
.
Advertise
(
ctx
,
ns
)
ttl
,
err
:=
a
.
Advertise
(
ctx
,
ns
,
opts
...
)
if
err
!=
nil
{
log
.
Debugf
(
"Error advertising %s: %s"
,
ns
,
err
.
Error
())
if
ctx
.
Err
()
!=
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