Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
1e457b65
Commit
1e457b65
authored
Feb 22, 2018
by
Anton Evangelatov
Committed by
Felix Lange
Feb 22, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
p2p: don't send DiscReason when using net.Pipe (#16004)
parent
bb5349b1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
5 deletions
+43
-5
rlpx.go
p2p/rlpx.go
+8
-2
rlpx_test.go
p2p/rlpx_test.go
+35
-3
No files found.
p2p/rlpx.go
View file @
1e457b65
...
...
@@ -108,8 +108,14 @@ func (t *rlpx) close(err error) {
// Tell the remote end why we're disconnecting if possible.
if
t
.
rw
!=
nil
{
if
r
,
ok
:=
err
.
(
DiscReason
);
ok
&&
r
!=
DiscNetworkError
{
t
.
fd
.
SetWriteDeadline
(
time
.
Now
()
.
Add
(
discWriteTimeout
))
SendItems
(
t
.
rw
,
discMsg
,
r
)
// rlpx tries to send DiscReason to disconnected peer
// if the connection is net.Pipe (in-memory simulation)
// it hangs forever, since net.Pipe does not implement
// a write deadline. Because of this only try to send
// the disconnect reason message if there is no error.
if
err
:=
t
.
fd
.
SetWriteDeadline
(
time
.
Now
()
.
Add
(
discWriteTimeout
));
err
==
nil
{
SendItems
(
t
.
rw
,
discMsg
,
r
)
}
}
}
t
.
fd
.
Close
()
...
...
p2p/rlpx_test.go
View file @
1e457b65
...
...
@@ -156,14 +156,18 @@ func TestProtocolHandshake(t *testing.T) {
node1
=
&
discover
.
Node
{
ID
:
discover
.
PubkeyID
(
&
prv1
.
PublicKey
),
IP
:
net
.
IP
{
5
,
6
,
7
,
8
},
TCP
:
44
}
hs1
=
&
protoHandshake
{
Version
:
3
,
ID
:
node1
.
ID
,
Caps
:
[]
Cap
{{
"c"
,
1
},
{
"d"
,
3
}}}
fd0
,
fd1
=
net
.
Pipe
()
wg
sync
.
WaitGroup
wg
sync
.
WaitGroup
)
fd0
,
fd1
,
err
:=
tcpPipe
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
wg
.
Add
(
2
)
go
func
()
{
defer
wg
.
Done
()
defer
fd
1
.
Close
()
defer
fd
0
.
Close
()
rlpx
:=
newRLPX
(
fd0
)
remid
,
err
:=
rlpx
.
doEncHandshake
(
prv0
,
node1
)
if
err
!=
nil
{
...
...
@@ -597,3 +601,31 @@ func TestHandshakeForwardCompatibility(t *testing.T) {
t
.
Errorf
(
"ingress-mac('foo') mismatch:
\n
got %x
\n
want %x"
,
fooIngressHash
,
wantFooIngressHash
)
}
}
// tcpPipe creates an in process full duplex pipe based on a localhost TCP socket
func
tcpPipe
()
(
net
.
Conn
,
net
.
Conn
,
error
)
{
l
,
err
:=
net
.
Listen
(
"tcp"
,
"127.0.0.1:0"
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
defer
l
.
Close
()
var
aconn
net
.
Conn
aerr
:=
make
(
chan
error
,
1
)
go
func
()
{
var
err
error
aconn
,
err
=
l
.
Accept
()
aerr
<-
err
}()
dconn
,
err
:=
net
.
Dial
(
"tcp"
,
l
.
Addr
()
.
String
())
if
err
!=
nil
{
<-
aerr
return
nil
,
nil
,
err
}
if
err
:=
<-
aerr
;
err
!=
nil
{
dconn
.
Close
()
return
nil
,
nil
,
err
}
return
aconn
,
dconn
,
nil
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment