From 8711e2b6366109912057e8fb20add325a1051a4e Mon Sep 17 00:00:00 2001 From: b00ris Date: Wed, 5 Sep 2018 11:57:45 +0300 Subject: whisper: add light mode check to handshake (#16725) --- whisper/whisperv6/peer.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'whisper/whisperv6/peer.go') diff --git a/whisper/whisperv6/peer.go b/whisper/whisperv6/peer.go index 79cc21270..621d51208 100644 --- a/whisper/whisperv6/peer.go +++ b/whisper/whisperv6/peer.go @@ -79,11 +79,14 @@ func (peer *Peer) stop() { func (peer *Peer) handshake() error { // Send the handshake status message asynchronously errc := make(chan error, 1) + isLightNode := peer.host.LightClientMode() + isRestrictedLightNodeConnection := peer.host.LightClientModeConnectionRestricted() go func() { pow := peer.host.MinPow() powConverted := math.Float64bits(pow) bloom := peer.host.BloomFilter() - errc <- p2p.SendItems(peer.ws, statusCode, ProtocolVersion, powConverted, bloom) + + errc <- p2p.SendItems(peer.ws, statusCode, ProtocolVersion, powConverted, bloom, isLightNode) }() // Fetch the remote status packet and verify protocol match @@ -127,6 +130,11 @@ func (peer *Peer) handshake() error { } } + isRemotePeerLightNode, err := s.Bool() + if isRemotePeerLightNode && isLightNode && isRestrictedLightNodeConnection { + return fmt.Errorf("peer [%x] is useless: two light client communication restricted", peer.ID()) + } + if err := <-errc; err != nil { return fmt.Errorf("peer [%x] failed to send status packet: %v", peer.ID(), err) } -- cgit v1.2.3