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
6ceb253f
Commit
6ceb253f
authored
Apr 15, 2015
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
whisper: use async handshakes to handle blocking peers
parent
46ea193a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
47 deletions
+12
-47
common_test.go
whisper/common_test.go
+0
-40
peer.go
whisper/peer.go
+11
-6
whisper_test.go
whisper/whisper_test.go
+1
-1
No files found.
whisper/common_test.go
deleted
100644 → 0
View file @
46ea193a
// Contains some common utility functions for testing.
package
whisper
import
(
"bytes"
"io/ioutil"
"github.com/ethereum/go-ethereum/p2p"
)
// bufMsgPipe creates a buffered message pipe between two endpoints.
func
bufMsgPipe
()
(
*
p2p
.
MsgPipeRW
,
*
p2p
.
MsgPipeRW
)
{
A
,
midA
:=
p2p
.
MsgPipe
()
midB
,
B
:=
p2p
.
MsgPipe
()
go
copyMsgPipe
(
midA
,
midB
)
go
copyMsgPipe
(
midB
,
midA
)
return
A
,
B
}
// copyMsgPipe copies messages from the src pipe to the dest.
func
copyMsgPipe
(
dst
,
src
*
p2p
.
MsgPipeRW
)
{
defer
dst
.
Close
()
for
{
msg
,
err
:=
src
.
ReadMsg
()
if
err
!=
nil
{
return
}
data
,
err
:=
ioutil
.
ReadAll
(
msg
.
Payload
)
if
err
!=
nil
{
return
}
msg
.
Payload
=
bytes
.
NewReader
(
data
)
if
err
:=
dst
.
WriteMsg
(
msg
);
err
!=
nil
{
return
}
}
}
whisper/peer.go
View file @
6ceb253f
...
@@ -53,10 +53,12 @@ func (self *peer) stop() {
...
@@ -53,10 +53,12 @@ func (self *peer) stop() {
// handshake sends the protocol initiation status message to the remote peer and
// handshake sends the protocol initiation status message to the remote peer and
// verifies the remote status too.
// verifies the remote status too.
func
(
self
*
peer
)
handshake
()
error
{
func
(
self
*
peer
)
handshake
()
error
{
// Send own status message, fetch remote one
// Send the handshake status message asynchronously
if
err
:=
p2p
.
SendItems
(
self
.
ws
,
statusCode
,
protocolVersion
);
err
!=
nil
{
errc
:=
make
(
chan
error
,
1
)
return
err
go
func
()
{
}
errc
<-
p2p
.
SendItems
(
self
.
ws
,
statusCode
,
protocolVersion
)
}()
// Fetch the remote status packet and verify protocol match
packet
,
err
:=
self
.
ws
.
ReadMsg
()
packet
,
err
:=
self
.
ws
.
ReadMsg
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -64,7 +66,6 @@ func (self *peer) handshake() error {
...
@@ -64,7 +66,6 @@ func (self *peer) handshake() error {
if
packet
.
Code
!=
statusCode
{
if
packet
.
Code
!=
statusCode
{
return
fmt
.
Errorf
(
"peer sent %x before status packet"
,
packet
.
Code
)
return
fmt
.
Errorf
(
"peer sent %x before status packet"
,
packet
.
Code
)
}
}
// Decode the rest of the status packet and verify protocol match
s
:=
rlp
.
NewStream
(
packet
.
Payload
)
s
:=
rlp
.
NewStream
(
packet
.
Payload
)
if
_
,
err
:=
s
.
List
();
err
!=
nil
{
if
_
,
err
:=
s
.
List
();
err
!=
nil
{
return
fmt
.
Errorf
(
"bad status message: %v"
,
err
)
return
fmt
.
Errorf
(
"bad status message: %v"
,
err
)
...
@@ -76,7 +77,11 @@ func (self *peer) handshake() error {
...
@@ -76,7 +77,11 @@ func (self *peer) handshake() error {
if
peerVersion
!=
protocolVersion
{
if
peerVersion
!=
protocolVersion
{
return
fmt
.
Errorf
(
"protocol version mismatch %d != %d"
,
peerVersion
,
protocolVersion
)
return
fmt
.
Errorf
(
"protocol version mismatch %d != %d"
,
peerVersion
,
protocolVersion
)
}
}
return
packet
.
Discard
()
// ignore anything after protocol version
// Wait until out own status is consumed too
if
err
:=
<-
errc
;
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to send status packet: %v"
,
err
)
}
return
nil
}
}
// update executes periodic operations on the peer, including message transmission
// update executes periodic operations on the peer, including message transmission
...
...
whisper/whisper_test.go
View file @
6ceb253f
...
@@ -21,7 +21,7 @@ func startTestCluster(n int) []*Whisper {
...
@@ -21,7 +21,7 @@ func startTestCluster(n int) []*Whisper {
}
}
// Wire all the peers to the root one
// Wire all the peers to the root one
for
i
:=
1
;
i
<
n
;
i
++
{
for
i
:=
1
;
i
<
n
;
i
++
{
src
,
dst
:=
buf
MsgPipe
()
src
,
dst
:=
p2p
.
MsgPipe
()
go
whispers
[
0
]
.
handlePeer
(
nodes
[
i
],
src
)
go
whispers
[
0
]
.
handlePeer
(
nodes
[
i
],
src
)
go
whispers
[
i
]
.
handlePeer
(
nodes
[
0
],
dst
)
go
whispers
[
i
]
.
handlePeer
(
nodes
[
0
],
dst
)
...
...
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