Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
261a8077
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,发现更多精彩内容 >>
提交
261a8077
编写于
6月 10, 2015
作者:
F
Felix Lange
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
p2p/discover: deflake TestUDP_successfulPing
上级
dffe6d32
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
30 addition
and
33 deletion
+30
-33
p2p/discover/table.go
p2p/discover/table.go
+8
-0
p2p/discover/udp_test.go
p2p/discover/udp_test.go
+22
-33
未找到文件。
p2p/discover/table.go
浏览文件 @
261a8077
...
...
@@ -40,6 +40,8 @@ type Table struct {
bonding
map
[
NodeID
]
*
bondproc
bondslots
chan
struct
{}
// limits total number of active bonding processes
nodeAddedHook
func
(
*
Node
)
// for testing
net
transport
self
*
Node
// metadata of the local node
}
...
...
@@ -431,6 +433,9 @@ func (tab *Table) pingreplace(new *Node, b *bucket) {
}
copy
(
b
.
entries
[
1
:
],
b
.
entries
)
b
.
entries
[
0
]
=
new
if
tab
.
nodeAddedHook
!=
nil
{
tab
.
nodeAddedHook
(
new
)
}
}
// ping a remote endpoint and wait for a reply, also updating the node database
...
...
@@ -466,6 +471,9 @@ outer:
}
if
len
(
bucket
.
entries
)
<
bucketSize
{
bucket
.
entries
=
append
(
bucket
.
entries
,
n
)
if
tab
.
nodeAddedHook
!=
nil
{
tab
.
nodeAddedHook
(
n
)
}
}
}
}
...
...
p2p/discover/udp_test.go
浏览文件 @
261a8077
...
...
@@ -234,14 +234,12 @@ func TestUDP_findnodeMultiReply(t *testing.T) {
func
TestUDP_successfulPing
(
t
*
testing
.
T
)
{
test
:=
newUDPTest
(
t
)
added
:=
make
(
chan
*
Node
,
1
)
test
.
table
.
nodeAddedHook
=
func
(
n
*
Node
)
{
added
<-
n
}
defer
test
.
table
.
Close
()
done
:=
make
(
chan
struct
{})
go
func
()
{
// The remote side sends a ping packet to initiate the exchange.
test
.
packetIn
(
nil
,
pingPacket
,
&
ping
{
From
:
testRemote
,
To
:
testLocalAnnounced
,
Version
:
Version
,
Expiration
:
futureExp
})
close
(
done
)
}()
go
test
.
packetIn
(
nil
,
pingPacket
,
&
ping
{
From
:
testRemote
,
To
:
testLocalAnnounced
,
Version
:
Version
,
Expiration
:
futureExp
})
// the ping is replied to.
test
.
waitPacketOut
(
func
(
p
*
pong
)
{
...
...
@@ -277,35 +275,26 @@ func TestUDP_successfulPing(t *testing.T) {
})
test
.
packetIn
(
nil
,
pongPacket
,
&
pong
{
Expiration
:
futureExp
})
//
ping should return shortly after getting the pong packet.
<-
done
// check that the node was added.
//
the node should be added to the table shortly after getting the
// pong packet.
select
{
case
n
:=
<-
added
:
rid
:=
PubkeyID
(
&
test
.
remotekey
.
PublicKey
)
rnode
:=
find
(
test
.
table
,
rid
)
if
rnode
==
nil
{
t
.
Fatalf
(
"node %v not found in table"
,
rid
)
if
n
.
ID
!=
rid
{
t
.
Errorf
(
"node has wrong ID: got %v, want %v"
,
n
.
ID
,
rid
)
}
if
!
bytes
.
Equal
(
rnode
.
IP
,
test
.
remoteaddr
.
IP
)
{
t
.
Errorf
(
"node has wrong IP: got %v, want: %v"
,
rnode
.
IP
,
test
.
remoteaddr
.
IP
)
if
!
bytes
.
Equal
(
n
.
IP
,
test
.
remoteaddr
.
IP
)
{
t
.
Errorf
(
"node has wrong IP: got %v, want: %v"
,
n
.
IP
,
test
.
remoteaddr
.
IP
)
}
if
int
(
rnode
.
UDP
)
!=
test
.
remoteaddr
.
Port
{
t
.
Errorf
(
"node has wrong UDP port: got %v, want: %v"
,
rnode
.
UDP
,
test
.
remoteaddr
.
Port
)
if
int
(
n
.
UDP
)
!=
test
.
remoteaddr
.
Port
{
t
.
Errorf
(
"node has wrong UDP port: got %v, want: %v"
,
n
.
UDP
,
test
.
remoteaddr
.
Port
)
}
if
rnode
.
TCP
!=
testRemote
.
TCP
{
t
.
Errorf
(
"node has wrong TCP port: got %v, want: %v"
,
rnode
.
TCP
,
testRemote
.
TCP
)
}
}
func
find
(
tab
*
Table
,
id
NodeID
)
*
Node
{
for
_
,
b
:=
range
tab
.
buckets
{
for
_
,
e
:=
range
b
.
entries
{
if
e
.
ID
==
id
{
return
e
if
n
.
TCP
!=
testRemote
.
TCP
{
t
.
Errorf
(
"node has wrong TCP port: got %v, want: %v"
,
n
.
TCP
,
testRemote
.
TCP
)
}
case
<-
time
.
After
(
2
*
time
.
Second
)
:
t
.
Errorf
(
"node was not added within 2 seconds"
)
}
}
return
nil
}
// dgramPipe is a fake UDP socket. It queues all sent datagrams.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录