les: do not disconnect another server (#20453)

This commit is contained in:
Felföldi Zsolt 2019-12-25 02:06:00 +01:00 committed by GitHub
parent a67fe48b43
commit 3bb6815fc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 9 deletions

@ -113,7 +113,7 @@ type peer struct {
fcParams flowcontrol.ServerParams
fcCosts requestCostTable
trusted bool
trusted, server bool
onlyAnnounce bool
chainSince, chainRecent uint64
stateSince, stateRecent uint64
@ -675,11 +675,16 @@ func (p *peer) Handshake(td *big.Int, head common.Hash, headNum uint64, genesis
}
if server != nil {
if recv.get("announceType", &p.announceType) != nil {
// set default announceType on server side
p.announceType = announceTypeSimple
p.server = recv.get("flowControl/MRR", nil) == nil
if p.server {
p.announceType = announceTypeNone // connected to another server, send no messages
} else {
if recv.get("announceType", &p.announceType) != nil {
// set default announceType on server side
p.announceType = announceTypeSimple
}
p.fcClient = flowcontrol.NewClientNode(server.fcManager, server.defParams)
}
p.fcClient = flowcontrol.NewClientNode(server.fcManager, server.defParams)
} else {
if recv.get("serveChainSince", &p.chainSince) != nil {
p.onlyAnnounce = true
@ -726,6 +731,7 @@ func (p *peer) Handshake(td *big.Int, head common.Hash, headNum uint64, genesis
}
}
}
p.server = true
}
p.headInfo = &announceData{Td: rTd, Hash: rHash, Number: rNum}
return nil

@ -108,10 +108,6 @@ func (h *serverHandler) runPeer(version uint, p *p2p.Peer, rw p2p.MsgReadWriter)
}
func (h *serverHandler) handle(p *peer) error {
// Reject light clients if server is not synced.
if !h.synced() {
return p2p.DiscRequested
}
p.Log().Debug("Light Ethereum peer connected", "name", p.Name())
// Execute the LES handshake
@ -125,6 +121,15 @@ func (h *serverHandler) handle(p *peer) error {
p.Log().Debug("Light Ethereum handshake failed", "err", err)
return err
}
if p.server {
// connected to another server, no messages expected, just wait for disconnection
_, err := p.rw.ReadMsg()
return err
}
// Reject light clients if server is not synced.
if !h.synced() {
return p2p.DiscRequested
}
defer p.fcClient.Disconnect()
// Disconnect the inbound peer if it's rejected by clientPool