diff options
author | gluk256 <gluk256@users.noreply.github.com> | 2017-12-21 22:17:27 +0800 |
---|---|---|
committer | Felix Lange <fjl@users.noreply.github.com> | 2017-12-21 22:17:27 +0800 |
commit | 38b1e8ee207da636d95bea760f577eca462307a6 (patch) | |
tree | 3bb47e1be937bcdbae94b55b772c8ce8422cf386 /whisper/whisperv6/peer.go | |
parent | b0d41e386e456cefd593db303a9f5284bf08cd07 (diff) | |
download | dexon-38b1e8ee207da636d95bea760f577eca462307a6.tar dexon-38b1e8ee207da636d95bea760f577eca462307a6.tar.gz dexon-38b1e8ee207da636d95bea760f577eca462307a6.tar.bz2 dexon-38b1e8ee207da636d95bea760f577eca462307a6.tar.lz dexon-38b1e8ee207da636d95bea760f577eca462307a6.tar.xz dexon-38b1e8ee207da636d95bea760f577eca462307a6.tar.zst dexon-38b1e8ee207da636d95bea760f577eca462307a6.zip |
whisper/whisperv6: PoW requirement (#15701)
New Whisper-level message introduced (PoW requirement),
corresponding logic added, plus some tests.
Diffstat (limited to 'whisper/whisperv6/peer.go')
-rw-r--r-- | whisper/whisperv6/peer.go | 31 |
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) +} |