diff options
Diffstat (limited to 'whisper/peer.go')
-rw-r--r-- | whisper/peer.go | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/whisper/peer.go b/whisper/peer.go index 4bd9428f5..338166c25 100644 --- a/whisper/peer.go +++ b/whisper/peer.go @@ -10,7 +10,7 @@ import ( ) const ( - protocolVersion = 0x02 + protocolVersion uint64 = 0x02 ) type peer struct { @@ -66,23 +66,19 @@ out: } func (self *peer) broadcast(envelopes []*Envelope) error { - envs := make([]interface{}, len(envelopes)) - i := 0 - for _, envelope := range envelopes { - if !self.known.Has(envelope.Hash()) { - envs[i] = envelope - self.known.Add(envelope.Hash()) - i++ + envs := make([]*Envelope, 0, len(envelopes)) + for _, env := range envelopes { + if !self.known.Has(env.Hash()) { + envs = append(envs, env) + self.known.Add(env.Hash()) } } - - if i > 0 { - if err := p2p.EncodeMsg(self.ws, envelopesMsg, envs[:i]...); err != nil { + if len(envs) > 0 { + if err := p2p.Send(self.ws, envelopesMsg, envs); err != nil { return err } - self.peer.DebugDetailln("broadcasted", i, "message(s)") + self.peer.DebugDetailln("broadcasted", len(envs), "message(s)") } - return nil } @@ -92,7 +88,7 @@ func (self *peer) addKnown(envelope *Envelope) { func (self *peer) handleStatus() error { ws := self.ws - if err := ws.WriteMsg(self.statusMsg()); err != nil { + if err := p2p.SendItems(ws, statusMsg, protocolVersion); err != nil { return err } msg, err := ws.ReadMsg() @@ -115,7 +111,3 @@ func (self *peer) handleStatus() error { } return msg.Discard() // ignore anything after protocol version } - -func (self *peer) statusMsg() p2p.Msg { - return p2p.NewMsg(statusMsg, protocolVersion) -} |