whisper: add light mode check to handshake (#16725)

This commit is contained in:
b00ris
2018-09-05 11:57:45 +03:00
committed by Guillaume Ballet
parent cf33d8b83c
commit 8711e2b636
8 changed files with 126 additions and 18 deletions

View File

@@ -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)
}