Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
c1bc202f
Unverified
提交
c1bc202f
authored
4月 23, 2019
作者:
Steven Allen
提交者:
GitHub
4月 23, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6248 from ipfs/feat/reprovider-noctx
reprovider: Use goprocess
上级
fc4dbb63
d36b6dbd
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
51 行增加
和
42 行删除
+51
-42
core.go
core/core.go
+4
-4
core.go
core/node/core.go
+0
-1
provider.go
core/node/provider.go
+14
-14
providers.go
reprovide/providers.go
+0
-0
reprovide.go
reprovide/reprovide.go
+29
-17
reprovide_test.go
reprovide/reprovide_test.go
+4
-6
没有找到文件。
core/core.go
浏览文件 @
c1bc202f
...
...
@@ -19,7 +19,6 @@ import (
"github.com/ipfs/go-ipfs/core/bootstrap"
"github.com/ipfs/go-ipfs/core/node"
"github.com/ipfs/go-ipfs/core/node/libp2p"
rp
"github.com/ipfs/go-ipfs/exchange/reprovide"
"github.com/ipfs/go-ipfs/filestore"
"github.com/ipfs/go-ipfs/fuse/mount"
"github.com/ipfs/go-ipfs/namesys"
...
...
@@ -28,6 +27,7 @@ import (
"github.com/ipfs/go-ipfs/pin"
"github.com/ipfs/go-ipfs/provider"
"github.com/ipfs/go-ipfs/repo"
rp
"github.com/ipfs/go-ipfs/reprovide"
bserv
"github.com/ipfs/go-blockservice"
bstore
"github.com/ipfs/go-ipfs-blockstore"
...
...
@@ -69,9 +69,9 @@ type IpfsNode struct {
Repo
repo
.
Repo
// Local node
Pinning
pin
.
Pinner
// the pinning manager
Mounts
Mounts
`optional:"true"`
// current mount state, if any.
PrivateKey
ic
.
PrivKey
// the local node's private Key
Pinning
pin
.
Pinner
// the pinning manager
Mounts
Mounts
`optional:"true"`
// current mount state, if any.
PrivateKey
ic
.
PrivKey
// the local node's private Key
PNetFingerprint
libp2p
.
PNetFingerprint
`optional:"true"`
// fingerprint of private network
// Services
...
...
core/node/core.go
浏览文件 @
c1bc202f
...
...
@@ -119,4 +119,3 @@ func Files(mctx helpers.MetricsCtx, lc fx.Lifecycle, repo repo.Repo, dag format.
return
root
,
err
}
core/node/provider.go
浏览文件 @
c1bc202f
...
...
@@ -11,10 +11,10 @@ import (
"go.uber.org/fx"
"github.com/ipfs/go-ipfs/core/node/helpers"
"github.com/ipfs/go-ipfs/exchange/reprovide"
"github.com/ipfs/go-ipfs/pin"
"github.com/ipfs/go-ipfs/provider"
"github.com/ipfs/go-ipfs/repo"
"github.com/ipfs/go-ipfs/reprovide"
)
const
kReprovideFrequency
=
time
.
Hour
*
12
...
...
@@ -45,6 +45,16 @@ func ProviderCtor(mctx helpers.MetricsCtx, lc fx.Lifecycle, queue *provider.Queu
func
ReproviderCtor
(
mctx
helpers
.
MetricsCtx
,
lc
fx
.
Lifecycle
,
cfg
*
config
.
Config
,
bs
BaseBlocks
,
ds
format
.
DAGService
,
pinning
pin
.
Pinner
,
rt
routing
.
IpfsRouting
)
(
*
reprovide
.
Reprovider
,
error
)
{
var
keyProvider
reprovide
.
KeyChanFunc
reproviderInterval
:=
kReprovideFrequency
if
cfg
.
Reprovider
.
Interval
!=
""
{
dur
,
err
:=
time
.
ParseDuration
(
cfg
.
Reprovider
.
Interval
)
if
err
!=
nil
{
return
nil
,
err
}
reproviderInterval
=
dur
}
switch
cfg
.
Reprovider
.
Strategy
{
case
"all"
:
fallthrough
...
...
@@ -57,21 +67,11 @@ func ReproviderCtor(mctx helpers.MetricsCtx, lc fx.Lifecycle, cfg *config.Config
default
:
return
nil
,
fmt
.
Errorf
(
"unknown reprovider strategy '%s'"
,
cfg
.
Reprovider
.
Strategy
)
}
return
reprovide
.
NewReprovider
(
helpers
.
LifecycleCtx
(
mctx
,
lc
),
rt
,
keyProvider
),
nil
return
reprovide
.
NewReprovider
(
helpers
.
LifecycleCtx
(
mctx
,
lc
),
r
eproviderInterval
,
r
t
,
keyProvider
),
nil
}
// Reprovider runs the reprovider service
func
Reprovider
(
cfg
*
config
.
Config
,
reprovider
*
reprovide
.
Reprovider
)
error
{
reproviderInterval
:=
kReprovideFrequency
if
cfg
.
Reprovider
.
Interval
!=
""
{
dur
,
err
:=
time
.
ParseDuration
(
cfg
.
Reprovider
.
Interval
)
if
err
!=
nil
{
return
err
}
reproviderInterval
=
dur
}
go
reprovider
.
Run
(
reproviderInterval
)
// TODO: refactor reprovider to have Start/Stop, use lifecycle
func
Reprovider
(
lp
lcProcess
,
reprovider
*
reprovide
.
Reprovider
)
error
{
lp
.
Append
(
reprovider
.
Run
)
return
nil
}
exchange/
reprovide/providers.go
→
reprovide/providers.go
浏览文件 @
c1bc202f
File moved
exchange/
reprovide/reprovide.go
→
reprovide/reprovide.go
浏览文件 @
c1bc202f
...
...
@@ -2,67 +2,77 @@ package reprovide
import
(
"context"
"errors"
"fmt"
"time"
backoff
"github.com/cenkalti/backoff"
cid
"github.com/ipfs/go-cid"
"github.com/cenkalti/backoff"
"github.com/ipfs/go-cid"
logging
"github.com/ipfs/go-log"
"github.com/ipfs/go-verifcid"
"github.com/jbenet/goprocess"
goprocessctx
"github.com/jbenet/goprocess/context"
routing
"github.com/libp2p/go-libp2p-routing"
)
var
log
=
logging
.
Logger
(
"reprovider"
)
//KeyChanFunc is function streaming CIDs to pass to content routing
//
KeyChanFunc is function streaming CIDs to pass to content routing
type
KeyChanFunc
func
(
context
.
Context
)
(
<-
chan
cid
.
Cid
,
error
)
type
doneFunc
func
(
error
)
type
Reprovider
struct
{
ctx
context
.
Context
trigger
chan
doneFunc
closing
chan
struct
{}
// The routing system to provide values through
rsys
routing
.
ContentRouting
keyProvider
KeyChanFunc
tick
time
.
Duration
}
// NewReprovider creates new Reprovider instance.
func
NewReprovider
(
ctx
context
.
Context
,
rsys
routing
.
ContentRouting
,
keyProvider
KeyChanFunc
)
*
Reprovider
{
func
NewReprovider
(
ctx
context
.
Context
,
tick
time
.
Duration
,
rsys
routing
.
ContentRouting
,
keyProvider
KeyChanFunc
)
*
Reprovider
{
return
&
Reprovider
{
ctx
:
ctx
,
trigger
:
make
(
chan
doneFunc
),
closing
:
make
(
chan
struct
{}),
rsys
:
rsys
,
keyProvider
:
keyProvider
,
tick
:
tick
,
}
}
// Run re-provides keys with 'tick' interval or when triggered
func
(
rp
*
Reprovider
)
Run
(
tick
time
.
Duration
)
{
func
(
rp
*
Reprovider
)
Run
(
proc
goprocess
.
Process
)
{
ctx
:=
goprocessctx
.
WithProcessClosing
(
rp
.
ctx
,
proc
)
defer
close
(
rp
.
closing
)
// 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
{
if
rp
.
tick
==
0
{
after
=
make
(
chan
time
.
Time
)
}
select
{
case
<-
rp
.
ctx
.
Done
()
:
case
<-
ctx
.
Done
()
:
return
case
done
=
<-
rp
.
trigger
:
case
<-
after
:
}
//'mute' the trigger channel so when `ipfs bitswap reprovide` is called
//a 'reprovider is already running' error is returned
//
'mute' the trigger channel so when `ipfs bitswap reprovide` is called
//
a 'reprovider is already running' error is returned
unmute
:=
rp
.
muteTrigger
()
err
:=
rp
.
Reprovide
(
)
err
:=
rp
.
reprovide
(
ctx
)
if
err
!=
nil
{
log
.
Debug
(
err
)
}
...
...
@@ -73,13 +83,13 @@ func (rp *Reprovider) Run(tick time.Duration) {
unmute
()
after
=
time
.
After
(
tick
)
after
=
time
.
After
(
rp
.
tick
)
}
}
//
R
eprovide registers all keys given by rp.keyProvider to libp2p content routing
func
(
rp
*
Reprovider
)
Reprovide
(
)
error
{
keychan
,
err
:=
rp
.
keyProvider
(
rp
.
ctx
)
//
r
eprovide registers all keys given by rp.keyProvider to libp2p content routing
func
(
rp
*
Reprovider
)
reprovide
(
ctx
context
.
Context
)
error
{
keychan
,
err
:=
rp
.
keyProvider
(
ctx
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to get key chan: %s"
,
err
)
}
...
...
@@ -90,7 +100,7 @@ func (rp *Reprovider) Reprovide() error {
continue
}
op
:=
func
()
error
{
err
:=
rp
.
rsys
.
Provide
(
rp
.
ctx
,
c
,
true
)
err
:=
rp
.
rsys
.
Provide
(
ctx
,
c
,
true
)
if
err
!=
nil
{
log
.
Debugf
(
"Failed to provide key: %s"
,
err
)
}
...
...
@@ -119,10 +129,12 @@ func (rp *Reprovider) Trigger(ctx context.Context) error {
}
select
{
case
<-
rp
.
closing
:
return
errors
.
New
(
"reprovider is closed"
)
case
<-
rp
.
ctx
.
Done
()
:
return
context
.
Canceled
return
rp
.
ctx
.
Err
()
case
<-
ctx
.
Done
()
:
return
c
ontext
.
Canceled
return
c
tx
.
Err
()
case
rp
.
trigger
<-
df
:
<-
progressCtx
.
Done
()
return
err
...
...
exchange/
reprovide/reprovide_test.go
→
reprovide/reprovide_test.go
浏览文件 @
c1bc202f
package
reprovide
_test
package
reprovide
import
(
"context"
...
...
@@ -10,9 +10,7 @@ import (
blockstore
"github.com/ipfs/go-ipfs-blockstore"
mock
"github.com/ipfs/go-ipfs-routing/mock"
pstore
"github.com/libp2p/go-libp2p-peerstore"
testutil
"github.com/libp2p/go-testutil"
.
"github.com/ipfs/go-ipfs/exchange/reprovide"
"github.com/libp2p/go-testutil"
)
func
TestReprovide
(
t
*
testing
.
T
)
{
...
...
@@ -36,8 +34,8 @@ func TestReprovide(t *testing.T) {
}
keyProvider
:=
NewBlockstoreProvider
(
bstore
)
reprov
:=
NewReprovider
(
ctx
,
clA
,
keyProvider
)
err
=
reprov
.
Reprovide
(
)
reprov
:=
NewReprovider
(
ctx
,
0
,
clA
,
keyProvider
)
err
=
reprov
.
reprovide
(
ctx
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论