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
go-dms3
Commits
9c0f9362
Commit
9c0f9362
authored
Aug 25, 2017
by
Jeromy Johnson
Committed by
GitHub
Aug 25, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4155 from ipfs/fix/reprovider-trigger
reprovide: fix ipfs bitswap reprovide when interval set to 0
parents
8c2166fa
ffc9abb8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
15 deletions
+43
-15
core/core.go
core/core.go
+8
-10
exchange/reprovide/reprovide.go
exchange/reprovide/reprovide.go
+7
-3
test/sharness/t0175-reprovider.sh
test/sharness/t0175-reprovider.sh
+28
-2
No files found.
core/core.go
View file @
9c0f9362
...
...
@@ -283,20 +283,18 @@ func (n *IpfsNode) startLateOnlineServices(ctx context.Context) error {
}
n
.
Reprovider
=
rp
.
NewReprovider
(
ctx
,
n
.
Routing
,
keyProvider
)
if
cfg
.
Reprovider
.
Interval
!=
"0"
{
interval
:=
kReprovideFrequency
if
cfg
.
Reprovider
.
Interval
!=
""
{
dur
,
err
:=
time
.
ParseDuration
(
cfg
.
Reprovider
.
Interval
)
if
err
!=
nil
{
return
err
}
interval
=
dur
reproviderInterval
:=
kReprovideFrequency
if
cfg
.
Reprovider
.
Interval
!=
""
{
dur
,
err
:=
time
.
ParseDuration
(
cfg
.
Reprovider
.
Interval
)
if
err
!=
nil
{
return
err
}
go
n
.
Reprovider
.
ProvideEvery
(
i
nterval
)
reproviderI
nterval
=
dur
}
go
n
.
Reprovider
.
Run
(
reproviderInterval
)
return
nil
}
...
...
exchange/reprovide/reprovide.go
View file @
9c0f9362
...
...
@@ -38,14 +38,18 @@ func NewReprovider(ctx context.Context, rsys routing.ContentRouting, keyProvider
}
}
//
ProvideEvery
re-provides keys with 'tick' interval
func
(
rp
*
Reprovider
)
ProvideEvery
(
tick
time
.
Duration
)
{
//
Run
re-provides keys with 'tick' interval
or when triggered
func
(
rp
*
Reprovider
)
Run
(
tick
time
.
Duration
)
{
// dont reprovide immediately.
// may have just started the daemon and shutting it down immediately.
// probability( up another minute | uptime ) increases with uptime.
after
:=
time
.
After
(
time
.
Minute
)
var
done
doneFunc
for
{
if
tick
==
0
{
after
=
make
(
chan
time
.
Time
)
}
select
{
case
<-
rp
.
ctx
.
Done
()
:
return
...
...
@@ -98,7 +102,7 @@ func (rp *Reprovider) Reprovide() error {
return
nil
}
// Trigger starts reprovision process in rp.
ProvideEvery
and waits for it
// Trigger starts reprovision process in rp.
Run
and waits for it
func
(
rp
*
Reprovider
)
Trigger
(
ctx
context
.
Context
)
error
{
progressCtx
,
done
:=
context
.
WithCancel
(
ctx
)
...
...
test/sharness/t0175-reprovider.sh
View file @
9c0f9362
...
...
@@ -4,8 +4,9 @@ test_description="Test reprovider"
.
lib/test-lib.sh
NUM_NODES
=
6
init_strategy
()
{
NUM_NODES
=
6
test_expect_success
'init iptb'
'
iptb init -f -n $NUM_NODES --bootstrap=none --port=0
'
...
...
@@ -19,7 +20,7 @@ init_strategy() {
ipfsi 0 config Reprovider.Strategy '
$1
'
'
startup_cluster
6
--debug
startup_cluster
${
NUM_NODES
}
}
findprovs_empty
()
{
...
...
@@ -124,4 +125,29 @@ test_expect_success 'stop peer 1' '
iptb stop 1
'
# Test reprovider working with ticking disabled
test_expect_success
'init iptb'
'
iptb init -f -n $NUM_NODES --bootstrap=none --port=0
'
test_expect_success
'peer ids'
'
PEERID_0=$(iptb get id 0) &&
PEERID_1=$(iptb get id 1)
'
test_expect_success
'Disable reprovider ticking'
'
ipfsi 0 config Reprovider.Interval 0
'
startup_cluster
${
NUM_NODES
}
test_expect_success
'add test object'
'
HASH_0=$(echo "foo" | ipfsi 0 add -q --local)
'
findprovs_empty
'$HASH_0'
reprovide
findprovs_expect
'$HASH_0'
'$PEERID_0'
test_done
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