good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
6ceb253f
Commit
6ceb253f
authored
Apr 15, 2015
by
Péter Szilágyi
Browse files
Options
Downloads
Patches
Plain Diff
whisper: use async handshakes to handle blocking peers
parent
46ea193a
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
whisper/common_test.go
+0
-40
0 additions, 40 deletions
whisper/common_test.go
whisper/peer.go
+11
-6
11 additions, 6 deletions
whisper/peer.go
whisper/whisper_test.go
+1
-1
1 addition, 1 deletion
whisper/whisper_test.go
with
12 additions
and
47 deletions
whisper/common_test.go
deleted
100644 → 0
+
0
−
40
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
}
}
}
This diff is collapsed.
Click to expand it.
whisper/peer.go
+
11
−
6
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
...
...
This diff is collapsed.
Click to expand it.
whisper/whisper_test.go
+
1
−
1
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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment