les: do not disconnect another server (#20453)
This commit is contained in:
parent
a67fe48b43
commit
3bb6815fc1
@ -113,7 +113,7 @@ type peer struct {
|
|||||||
fcParams flowcontrol.ServerParams
|
fcParams flowcontrol.ServerParams
|
||||||
fcCosts requestCostTable
|
fcCosts requestCostTable
|
||||||
|
|
||||||
trusted bool
|
trusted, server bool
|
||||||
onlyAnnounce bool
|
onlyAnnounce bool
|
||||||
chainSince, chainRecent uint64
|
chainSince, chainRecent uint64
|
||||||
stateSince, stateRecent 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 server != nil {
|
||||||
|
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 {
|
if recv.get("announceType", &p.announceType) != nil {
|
||||||
// set default announceType on server side
|
// set default announceType on server side
|
||||||
p.announceType = announceTypeSimple
|
p.announceType = announceTypeSimple
|
||||||
}
|
}
|
||||||
p.fcClient = flowcontrol.NewClientNode(server.fcManager, server.defParams)
|
p.fcClient = flowcontrol.NewClientNode(server.fcManager, server.defParams)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if recv.get("serveChainSince", &p.chainSince) != nil {
|
if recv.get("serveChainSince", &p.chainSince) != nil {
|
||||||
p.onlyAnnounce = true
|
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}
|
p.headInfo = &announceData{Td: rTd, Hash: rHash, Number: rNum}
|
||||||
return nil
|
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 {
|
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())
|
p.Log().Debug("Light Ethereum peer connected", "name", p.Name())
|
||||||
|
|
||||||
// Execute the LES handshake
|
// Execute the LES handshake
|
||||||
@ -125,6 +121,15 @@ func (h *serverHandler) handle(p *peer) error {
|
|||||||
p.Log().Debug("Light Ethereum handshake failed", "err", err)
|
p.Log().Debug("Light Ethereum handshake failed", "err", err)
|
||||||
return 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()
|
defer p.fcClient.Disconnect()
|
||||||
|
|
||||||
// Disconnect the inbound peer if it's rejected by clientPool
|
// Disconnect the inbound peer if it's rejected by clientPool
|
||||||
|
Loading…
Reference in New Issue
Block a user