From 009efebdafd21b63f284f70691b1cc39ff75e8bd Mon Sep 17 00:00:00 2001 From: vyzo Date: Thu, 22 Feb 2018 11:01:14 +0200 Subject: [PATCH] harden piggybackControl don't create a control object if the graft/prune are stale and only assign the relevant fields. --- gossipsub.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/gossipsub.go b/gossipsub.go index b50de38..5ff4386 100644 --- a/gossipsub.go +++ b/gossipsub.go @@ -520,14 +520,22 @@ func (gs *GossipSubRouter) piggybackControl(p peer.ID, out *RPC, ctl *pb.Control } } + if len(tograft) == 0 && len(toprune) == 0 { + return + } + xctl := out.Control if xctl == nil { xctl = &pb.ControlMessage{} out.Control = xctl } - xctl.Graft = append(xctl.Graft, tograft...) - xctl.Prune = append(xctl.Prune, toprune...) + if len(tograft) > 0 { + xctl.Graft = append(xctl.Graft, tograft...) + } + if len(toprune) > 0 { + xctl.Prune = append(xctl.Prune, toprune...) + } } func (gs *GossipSubRouter) getPeers(topic string, count int, filter func(peer.ID) bool) []peer.ID {