diff --git a/les/peer.go b/les/peer.go index ab5b30a65..801147df6 100644 --- a/les/peer.go +++ b/les/peer.go @@ -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 diff --git a/les/server_handler.go b/les/server_handler.go index 16249ef1b..4b505c2bc 100644 --- a/les/server_handler.go +++ b/les/server_handler.go @@ -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