Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
bf380b87
提交
bf380b87
authored
4月 15, 2019
作者:
Łukasz Magiera
提交者:
Steven Allen
4月 17, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Cleanup routing related units
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
23f50ab0
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
79 行增加
和
61 行删除
+79
-61
groups.go
core/node/groups.go
+6
-2
libp2p.go
core/node/libp2p.go
+73
-59
没有找到文件。
core/node/groups.go
浏览文件 @
bf380b87
...
...
@@ -35,15 +35,19 @@ var BaseLibP2P = fx.Options(
)
func
LibP2P
(
cfg
*
BuildCfg
)
fx
.
Option
{
return
fx
.
Options
(
opts
:=
fx
.
Options
(
BaseLibP2P
,
maybeProvide
(
P2PNoSecurity
,
cfg
.
DisableEncryptedConnections
),
maybeProvide
(
Pubsub
,
cfg
.
getOpt
(
"pubsub"
)
||
cfg
.
getOpt
(
"ipnsps"
)),
fx
.
Provide
(
P2PSmuxTransport
(
cfg
.
getOpt
(
"mplex"
))),
fx
.
Provide
(
P2POnlineRouting
(
cfg
.
getOpt
(
"ipnsps"
))),
fx
.
Provide
(
P2PRouting
),
fx
.
Provide
(
P2PBaseRouting
),
maybeProvide
(
P2PPubsubRouter
,
cfg
.
getOpt
(
"ipnsps"
)),
)
return
opts
}
func
Storage
(
cfg
*
BuildCfg
)
fx
.
Option
{
...
...
core/node/libp2p.go
浏览文件 @
bf380b87
...
...
@@ -6,6 +6,7 @@ import (
"fmt"
"io/ioutil"
"os"
"sort"
"strings"
"time"
...
...
@@ -398,10 +399,8 @@ type P2PHostOut struct {
Host
host
.
Host
Routing
BaseRouting
IpfsDHT
*
dht
.
IpfsDHT
}
// TODO: move some of this into params struct
func
P2PHost
(
mctx
MetricsCtx
,
lc
fx
.
Lifecycle
,
params
P2PHostIn
)
(
out
P2PHostOut
,
err
error
)
{
opts
:=
[]
libp2p
.
Option
{
libp2p
.
NoListenAddrs
}
for
_
,
o
:=
range
params
.
Opts
{
...
...
@@ -438,80 +437,95 @@ func P2PHost(mctx MetricsCtx, lc fx.Lifecycle, params P2PHostIn) (out P2PHostOut
},
})
// TODO: break this up into more DI units
// TODO: I'm not a fan of type assertions like this but the
// `RoutingOption` system doesn't currently provide access to the
// IpfsNode.
//
// Ideally, we'd do something like:
//
// 1. Add some fancy method to introspect into tiered routers to extract
// things like the pubsub router or the DHT (complicated, messy,
// probably not worth it).
// 2. Pass the IpfsNode into the RoutingOption (would also remove the
// PSRouter case below.
// 3. Introduce some kind of service manager? (my personal favorite but
// that requires a fair amount of work).
if
dht
,
ok
:=
out
.
Routing
.
(
*
dht
.
IpfsDHT
);
ok
{
out
.
IpfsDHT
=
dht
return
out
,
err
}
type
Router
struct
{
routing
.
IpfsRouting
Priority
int
// less = more important
}
type
p2pRouterOut
struct
{
fx
.
Out
Router
Router
`group:"routers"`
}
func
P2PBaseRouting
(
lc
fx
.
Lifecycle
,
in
BaseRouting
)
(
out
p2pRouterOut
,
dr
*
dht
.
IpfsDHT
)
{
if
dht
,
ok
:=
in
.
(
*
dht
.
IpfsDHT
);
ok
{
dr
=
dht
lc
.
Append
(
fx
.
Hook
{
OnStop
:
func
(
ctx
context
.
Context
)
error
{
return
out
.
IpfsDHT
.
Close
()
return
dr
.
Close
()
},
})
}
return
out
,
err
return
p2pRouterOut
{
Router
:
Router
{
Priority
:
1000
,
IpfsRouting
:
in
,
},
},
dr
}
type
p2pRoutingIn
struct
{
type
p2p
Online
RoutingIn
struct
{
fx
.
In
R
epo
repo
.
Repo
R
outers
[]
Router
`group:"routers"`
Validator
record
.
Validator
Host
host
.
Host
PubSub
*
pubsub
.
PubSub
`optional:"true"`
}
BaseRouting
BaseRouting
func
P2PRouting
(
in
p2pOnlineRoutingIn
)
routing
.
IpfsRouting
{
routers
:=
in
.
Routers
sort
.
SliceStable
(
routers
,
func
(
i
,
j
int
)
bool
{
return
routers
[
i
]
.
Priority
<
routers
[
j
]
.
Priority
})
irouters
:=
make
([]
routing
.
IpfsRouting
,
len
(
routers
))
for
i
,
v
:=
range
routers
{
irouters
[
i
]
=
v
.
IpfsRouting
}
return
routinghelpers
.
Tiered
{
Routers
:
irouters
,
Validator
:
in
.
Validator
,
}
}
type
p2p
RoutingOut
struct
{
fx
.
Out
type
p2p
PSRoutingIn
struct
{
fx
.
In
IpfsRouting
routing
.
IpfsRouting
PSRouter
*
namesys
.
PubsubValueStore
}
func
P2POnlineRouting
(
ipnsps
bool
)
func
(
mctx
MetricsCtx
,
lc
fx
.
Lifecycle
,
in
p2pRoutingIn
)
(
out
p2pRoutingOut
)
{
return
func
(
mctx
MetricsCtx
,
lc
fx
.
Lifecycle
,
in
p2pRoutingIn
)
(
out
p2pRoutingOut
)
{
out
.
IpfsRouting
=
in
.
BaseRouting
if
ipnsps
{
out
.
PSRouter
=
namesys
.
NewPubsubValueStore
(
lifecycleCtx
(
mctx
,
lc
),
in
.
Host
,
in
.
BaseRouting
,
in
.
PubSub
,
in
.
Validator
,
)
out
.
IpfsRouting
=
routinghelpers
.
Tiered
{
Routers
:
[]
routing
.
IpfsRouting
{
// Always check pubsub first.
&
routinghelpers
.
Compose
{
ValueStore
:
&
routinghelpers
.
LimitedValueStore
{
ValueStore
:
out
.
PSRouter
,
Namespaces
:
[]
string
{
"ipns"
},
},
},
in
.
BaseRouting
,
BaseRouting
BaseRouting
Repo
repo
.
Repo
Validator
record
.
Validator
Host
host
.
Host
PubSub
*
pubsub
.
PubSub
`optional:"true"`
}
func
P2PPubsubRouter
(
mctx
MetricsCtx
,
lc
fx
.
Lifecycle
,
in
p2pPSRoutingIn
)
(
p2pRouterOut
,
*
namesys
.
PubsubValueStore
)
{
psRouter
:=
namesys
.
NewPubsubValueStore
(
lifecycleCtx
(
mctx
,
lc
),
in
.
Host
,
in
.
BaseRouting
,
in
.
PubSub
,
in
.
Validator
,
)
return
p2pRouterOut
{
Router
:
Router
{
IpfsRouting
:
&
routinghelpers
.
Compose
{
ValueStore
:
&
routinghelpers
.
LimitedValueStore
{
ValueStore
:
psRouter
,
Namespaces
:
[]
string
{
"ipns"
},
},
Validator
:
in
.
Validator
,
}
}
return
out
}
},
Priority
:
100
,
},
},
psRouter
}
func
AutoNATService
(
mctx
MetricsCtx
,
lc
fx
.
Lifecycle
,
cfg
*
config
.
Config
,
host
host
.
Host
)
error
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论