Skip to content

Commit

Permalink
les: do not disconnect another server (#20453)
Browse files Browse the repository at this point in the history
  • Loading branch information
zsfelfoldi authored Dec 25, 2019
1 parent a67fe48 commit 3bb6815
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
16 changes: 11 additions & 5 deletions les/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions les/server_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 3bb6815

Please sign in to comment.