harden piggybackControl

don't create a control object if the graft/prune are stale and only assign
the relevant fields.
This commit is contained in:
vyzo 2018-02-22 11:01:14 +02:00 committed by Steven Allen
parent bfb0664581
commit 009efebdaf
1 changed files with 10 additions and 2 deletions

View File

@ -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 {