aboutsummaryrefslogtreecommitdiffstats
path: root/whisper/whisperv6/peer.go
diff options
context:
space:
mode:
Diffstat (limited to 'whisper/whisperv6/peer.go')
-rw-r--r--whisper/whisperv6/peer.go31
1 files changed, 20 insertions, 11 deletions
diff --git a/whisper/whisperv6/peer.go b/whisper/whisperv6/peer.go
index ffc39505e..65e0c77b0 100644
--- a/whisper/whisperv6/peer.go
+++ b/whisper/whisperv6/peer.go
@@ -18,6 +18,7 @@ package whisperv6
import (
"fmt"
+ "math"
"time"
"github.com/ethereum/go-ethereum/common"
@@ -29,10 +30,12 @@ import (
// peer represents a whisper protocol peer connection.
type Peer struct {
- host *Whisper
- peer *p2p.Peer
- ws p2p.MsgReadWriter
- trusted bool
+ host *Whisper
+ peer *p2p.Peer
+ ws p2p.MsgReadWriter
+
+ trusted bool
+ powRequirement float64
known *set.Set // Messages already known by the peer to avoid wasting bandwidth
@@ -42,12 +45,13 @@ type Peer struct {
// newPeer creates a new whisper peer object, but does not run the handshake itself.
func newPeer(host *Whisper, remote *p2p.Peer, rw p2p.MsgReadWriter) *Peer {
return &Peer{
- host: host,
- peer: remote,
- ws: rw,
- trusted: false,
- known: set.New(),
- quit: make(chan struct{}),
+ host: host,
+ peer: remote,
+ ws: rw,
+ trusted: false,
+ powRequirement: 0.0,
+ known: set.New(),
+ quit: make(chan struct{}),
}
}
@@ -152,7 +156,7 @@ func (p *Peer) broadcast() error {
envelopes := p.host.Envelopes()
bundle := make([]*Envelope, 0, len(envelopes))
for _, envelope := range envelopes {
- if !p.marked(envelope) {
+ if !p.marked(envelope) && envelope.PoW() >= p.powRequirement {
bundle = append(bundle, envelope)
}
}
@@ -177,3 +181,8 @@ func (p *Peer) ID() []byte {
id := p.peer.ID()
return id[:]
}
+
+func (p *Peer) notifyAboutPowRequirementChange(pow float64) error {
+ i := math.Float64bits(pow)
+ return p2p.Send(p.ws, powRequirementCode, i)
+}