Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
93854bba
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
93854bba
编写于
11月 26, 2018
作者:
J
Janoš Guljaš
提交者:
Anton Evangelatov
11月 26, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
swarm/network/simulation: fix New function for-loop scope (#18161)
上级
f0515800
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
56 addition
and
1 deletion
+56
-1
swarm/network/simulation/node_test.go
swarm/network/simulation/node_test.go
+35
-0
swarm/network/simulation/simulation.go
swarm/network/simulation/simulation.go
+7
-0
swarm/network/simulation/simulation_test.go
swarm/network/simulation/simulation_test.go
+13
-0
swarm/network/stream/delivery.go
swarm/network/stream/delivery.go
+1
-1
未找到文件。
swarm/network/simulation/node_test.go
浏览文件 @
93854bba
...
...
@@ -160,6 +160,41 @@ func TestAddNodeWithService(t *testing.T) {
}
}
func
TestAddNodeMultipleServices
(
t
*
testing
.
T
)
{
sim
:=
New
(
map
[
string
]
ServiceFunc
{
"noop1"
:
noopServiceFunc
,
"noop2"
:
noopService2Func
,
})
defer
sim
.
Close
()
id
,
err
:=
sim
.
AddNode
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
n
:=
sim
.
Net
.
GetNode
(
id
)
.
Node
.
(
*
adapters
.
SimNode
)
if
n
.
Service
(
"noop1"
)
==
nil
{
t
.
Error
(
"service noop1 not found on node"
)
}
if
n
.
Service
(
"noop2"
)
==
nil
{
t
.
Error
(
"service noop2 not found on node"
)
}
}
func
TestAddNodeDuplicateServiceError
(
t
*
testing
.
T
)
{
sim
:=
New
(
map
[
string
]
ServiceFunc
{
"noop1"
:
noopServiceFunc
,
"noop2"
:
noopServiceFunc
,
})
defer
sim
.
Close
()
wantErr
:=
"duplicate service: *simulation.noopService"
_
,
err
:=
sim
.
AddNode
()
if
err
.
Error
()
!=
wantErr
{
t
.
Errorf
(
"got error %q, want %q"
,
err
,
wantErr
)
}
}
func
TestAddNodes
(
t
*
testing
.
T
)
{
sim
:=
New
(
noopServiceFuncMap
)
defer
sim
.
Close
()
...
...
swarm/network/simulation/simulation.go
浏览文件 @
93854bba
...
...
@@ -68,6 +68,10 @@ type ServiceFunc func(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Se
// New creates a new Simulation instance with new
// simulations.Network initialized with provided services.
// Services map must have unique keys as service names and
// every ServiceFunc must return a node.Service of the unique type.
// This restriction is required by node.Node.Start() function
// which is used to start node.Service returned by ServiceFunc.
func
New
(
services
map
[
string
]
ServiceFunc
)
(
s
*
Simulation
)
{
s
=
&
Simulation
{
buckets
:
make
(
map
[
enode
.
ID
]
*
sync
.
Map
),
...
...
@@ -76,6 +80,9 @@ func New(services map[string]ServiceFunc) (s *Simulation) {
adapterServices
:=
make
(
map
[
string
]
adapters
.
ServiceFunc
,
len
(
services
))
for
name
,
serviceFunc
:=
range
services
{
// Scope this variables correctly
// as they will be in the adapterServices[name] function accessed later.
name
,
serviceFunc
:=
name
,
serviceFunc
s
.
serviceNames
=
append
(
s
.
serviceNames
,
name
)
adapterServices
[
name
]
=
func
(
ctx
*
adapters
.
ServiceContext
)
(
node
.
Service
,
error
)
{
b
:=
new
(
sync
.
Map
)
...
...
swarm/network/simulation/simulation_test.go
浏览文件 @
93854bba
...
...
@@ -205,3 +205,16 @@ func (t *noopService) Start(server *p2p.Server) error {
func
(
t
*
noopService
)
Stop
()
error
{
return
nil
}
// a helper function for most basic noop service
// of a different type then noopService to test
// multiple services on one node.
func
noopService2Func
(
ctx
*
adapters
.
ServiceContext
,
b
*
sync
.
Map
)
(
node
.
Service
,
func
(),
error
)
{
return
new
(
noopService2
),
nil
,
nil
}
// noopService2 is the service that does not do anything
// but implements node.Service interface.
type
noopService2
struct
{
noopService
}
swarm/network/stream/delivery.go
浏览文件 @
93854bba
...
...
@@ -255,7 +255,7 @@ func (d *Delivery) RequestFromPeers(ctx context.Context, req *network.Request) (
}
sp
=
d
.
getPeer
(
id
)
if
sp
==
nil
{
log
.
Warn
(
"Delivery.RequestFromPeers: peer not found"
,
"id"
,
id
)
//
log.Warn("Delivery.RequestFromPeers: peer not found", "id", id)
return
true
}
spID
=
&
id
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录