aboutsummaryrefslogtreecommitdiffstats
path: root/whisper/peer.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-06 00:21:32 +0800
committerobscuren <geffobscura@gmail.com>2015-03-06 00:21:32 +0800
commitba0c41436c8a067937aa0845963f9ec3b81e7aed (patch)
tree7bd9bbc9422353ab341f01581abeb346b5a6cacf /whisper/peer.go
parentfabaf4f1f01db773f6c0c2e9a9499736b1a40848 (diff)
parent215c763d53fc8e06e8c9807875eacaccf3ef45fa (diff)
downloaddexon-ba0c41436c8a067937aa0845963f9ec3b81e7aed.tar
dexon-ba0c41436c8a067937aa0845963f9ec3b81e7aed.tar.gz
dexon-ba0c41436c8a067937aa0845963f9ec3b81e7aed.tar.bz2
dexon-ba0c41436c8a067937aa0845963f9ec3b81e7aed.tar.lz
dexon-ba0c41436c8a067937aa0845963f9ec3b81e7aed.tar.xz
dexon-ba0c41436c8a067937aa0845963f9ec3b81e7aed.tar.zst
dexon-ba0c41436c8a067937aa0845963f9ec3b81e7aed.zip
Merge branch 'p2p-handshake-2' of https://github.com/fjl/go-ethereum into fjl-p2p-handshake-2
Diffstat (limited to 'whisper/peer.go')
-rw-r--r--whisper/peer.go27
1 files changed, 10 insertions, 17 deletions
diff --git a/whisper/peer.go b/whisper/peer.go
index 332ddd22a..66cfec88c 100644
--- a/whisper/peer.go
+++ b/whisper/peer.go
@@ -2,10 +2,10 @@ package whisper
import (
"fmt"
- "io/ioutil"
"time"
"github.com/ethereum/go-ethereum/p2p"
+ "github.com/ethereum/go-ethereum/rlp"
"gopkg.in/fatih/set.v0"
)
@@ -77,8 +77,7 @@ func (self *peer) broadcast(envelopes []*Envelope) error {
}
if i > 0 {
- msg := p2p.NewMsg(envelopesMsg, envs[:i]...)
- if err := self.ws.WriteMsg(msg); err != nil {
+ if err := p2p.EncodeMsg(self.ws, envelopesMsg, envs[:i]...); err != nil {
return err
}
self.peer.DebugDetailln("broadcasted", i, "message(s)")
@@ -93,34 +92,28 @@ func (self *peer) addKnown(envelope *Envelope) {
func (self *peer) handleStatus() error {
ws := self.ws
-
if err := ws.WriteMsg(self.statusMsg()); err != nil {
return err
}
-
msg, err := ws.ReadMsg()
if err != nil {
return err
}
-
if msg.Code != statusMsg {
return fmt.Errorf("peer send %x before status msg", msg.Code)
}
-
- data, err := ioutil.ReadAll(msg.Payload)
- if err != nil {
- return err
+ s := rlp.NewStream(msg.Payload)
+ if _, err := s.List(); err != nil {
+ return fmt.Errorf("bad status message: %v", err)
}
-
- if len(data) == 0 {
- return fmt.Errorf("malformed status. data len = 0")
+ pv, err := s.Uint()
+ if err != nil {
+ return fmt.Errorf("bad status message: %v", err)
}
-
- if pv := data[0]; pv != protocolVersion {
+ if pv != protocolVersion {
return fmt.Errorf("protocol version mismatch %d != %d", pv, protocolVersion)
}
-
- return nil
+ return msg.Discard() // ignore anything after protocol version
}
func (self *peer) statusMsg() p2p.Msg {