Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
286941d4
提交
286941d4
authored
4月 08, 2019
作者:
Raúl Kripalani
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support experimental datastore-backed peerstore.
License: MIT Signed-off-by:
Raúl Kripalani
<
raul@protocol.ai
>
上级
495f12c0
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
59 行增加
和
10 行删除
+59
-10
builder.go
core/builder.go
+59
-10
没有找到文件。
core/builder.go
浏览文件 @
286941d4
...
...
@@ -5,7 +5,8 @@ import (
"crypto/rand"
"encoding/base64"
"errors"
"github.com/ipfs/go-ipfs/provider"
"fmt"
"os"
"syscall"
"time"
...
...
@@ -15,7 +16,7 @@ import (
pin
"github.com/ipfs/go-ipfs/pin"
repo
"github.com/ipfs/go-ipfs/repo"
cidv0v1
"github.com/ipfs/go-ipfs/thirdparty/cidv0v1"
"github.com/ipfs/go-ipfs/thirdparty/verifbs"
verifbs
"github.com/ipfs/go-ipfs/thirdparty/verifbs"
bserv
"github.com/ipfs/go-blockservice"
ds
"github.com/ipfs/go-datastore"
...
...
@@ -25,6 +26,7 @@ import (
cfg
"github.com/ipfs/go-ipfs-config"
offline
"github.com/ipfs/go-ipfs-exchange-offline"
offroute
"github.com/ipfs/go-ipfs-routing/offline"
provider
"github.com/ipfs/go-ipfs/provider"
ipns
"github.com/ipfs/go-ipns"
dag
"github.com/ipfs/go-merkledag"
metrics
"github.com/ipfs/go-metrics-interface"
...
...
@@ -36,6 +38,7 @@ import (
p2phost
"github.com/libp2p/go-libp2p-host"
peer
"github.com/libp2p/go-libp2p-peer"
pstore
"github.com/libp2p/go-libp2p-peerstore"
pstoreds
"github.com/libp2p/go-libp2p-peerstore/pstoreds"
pstoremem
"github.com/libp2p/go-libp2p-peerstore/pstoremem"
record
"github.com/libp2p/go-libp2p-record"
)
...
...
@@ -130,23 +133,33 @@ func defaultRepo(dstore repo.Datastore) (repo.Repo, error) {
}
// NewNode constructs and returns an IpfsNode using the given cfg.
func
NewNode
(
ctx
context
.
Context
,
cfg
*
BuildCfg
)
(
*
IpfsNode
,
error
)
{
if
cfg
==
nil
{
cfg
=
new
(
BuildCfg
)
func
NewNode
(
ctx
context
.
Context
,
b
cfg
*
BuildCfg
)
(
*
IpfsNode
,
error
)
{
if
b
cfg
==
nil
{
b
cfg
=
new
(
BuildCfg
)
}
err
:=
cfg
.
fillDefaults
()
err
:=
b
cfg
.
fillDefaults
()
if
err
!=
nil
{
return
nil
,
err
}
ctx
=
metrics
.
CtxScope
(
ctx
,
"ipfs"
)
config
,
err
:=
bcfg
.
Repo
.
Config
()
if
err
!=
nil
{
return
nil
,
err
}
ps
,
err
:=
setupPeerstore
(
ctx
,
bcfg
.
Repo
.
Datastore
(),
&
config
.
Experimental
.
Peerstore
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed while creating peerstore: %s"
,
err
)
}
n
:=
&
IpfsNode
{
IsOnline
:
cfg
.
Online
,
Repo
:
cfg
.
Repo
,
IsOnline
:
b
cfg
.
Online
,
Repo
:
b
cfg
.
Repo
,
ctx
:
ctx
,
Peerstore
:
ps
toremem
.
NewPeerstore
()
,
Peerstore
:
ps
,
}
n
.
RecordValidator
=
record
.
NamespacedValidator
{
...
...
@@ -157,7 +170,7 @@ func NewNode(ctx context.Context, cfg *BuildCfg) (*IpfsNode, error) {
// TODO: this is a weird circular-ish dependency, rework it
n
.
proc
=
goprocessctx
.
WithContextAndTeardown
(
ctx
,
n
.
teardown
)
if
err
:=
setupNode
(
ctx
,
n
,
cfg
);
err
!=
nil
{
if
err
:=
setupNode
(
ctx
,
n
,
b
cfg
);
err
!=
nil
{
n
.
Close
()
return
nil
,
err
}
...
...
@@ -291,3 +304,39 @@ func setupNode(ctx context.Context, n *IpfsNode, cfg *BuildCfg) error {
return
n
.
loadFilesRoot
()
}
func
setupPeerstore
(
ctx
context
.
Context
,
dstore
repo
.
Datastore
,
pcfg
*
cfg
.
Peerstore
)
(
pstore
.
Peerstore
,
error
)
{
switch
pcfg
.
Type
{
case
""
,
cfg
.
PeerstoreMemory
:
return
pstoremem
.
NewPeerstore
(),
nil
case
cfg
.
PeerstoreDatastore
:
dcfg
:=
pcfg
.
Datastore
opts
:=
pstoreds
.
DefaultOpts
()
opts
.
GCLookaheadInterval
=
0
// ensure lookahead is disabled.
if
dcfg
.
Cache
.
Disable
{
opts
.
CacheSize
=
0
}
else
if
dcfg
.
Cache
.
Size
>
0
{
opts
.
CacheSize
=
uint
(
dcfg
.
Cache
.
Size
)
}
if
dcfg
.
GC
.
Disable
{
opts
.
GCPurgeInterval
=
0
}
else
if
dcfg
.
GC
.
PurgeIntervalMillis
>
0
{
opts
.
GCPurgeInterval
=
time
.
Duration
(
dcfg
.
GC
.
PurgeIntervalMillis
)
*
time
.
Millisecond
}
if
dcfg
.
GC
.
LookaheadIntervalMillis
>
0
{
opts
.
GCLookaheadInterval
=
time
.
Duration
(
dcfg
.
GC
.
LookaheadIntervalMillis
)
*
time
.
Millisecond
}
if
dcfg
.
GC
.
InitDelayMillis
!=
nil
{
opts
.
GCInitialDelay
=
time
.
Duration
(
*
dcfg
.
GC
.
InitDelayMillis
)
*
time
.
Millisecond
}
return
pstoreds
.
NewPeerstore
(
ctx
,
dstore
,
opts
)
}
return
nil
,
fmt
.
Errorf
(
"unsupported peerstore type: %s"
,
pcfg
.
Type
)
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论