From 660a3c8a42bce73b7aaecb8355702614ae7732cd Mon Sep 17 00:00:00 2001 From: Levente Pap <levente.pap@iota.org> Date: Tue, 28 Apr 2020 12:35:42 +0200 Subject: [PATCH] Fix #372 Analysis client plugin panic without gossip (#384) --- plugins/analysis/client/plugin.go | 32 ++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/plugins/analysis/client/plugin.go b/plugins/analysis/client/plugin.go index 8d1b8b0f..af7b3b6e 100644 --- a/plugins/analysis/client/plugin.go +++ b/plugins/analysis/client/plugin.go @@ -88,20 +88,26 @@ func reportHeartbeat(dispatchers *EventDispatchers) { nodeID = local.GetInstance().ID().Bytes() } - // Get outboundIds (chosen neighbors) - outgoingNeighbors := autopeering.Selection.GetOutgoingNeighbors() - outboundIds := make([][]byte, len(outgoingNeighbors)) - for i, neighbor := range outgoingNeighbors { - // Doesn't copy the ID, take care not to modify underlying bytearray! - outboundIds[i] = neighbor.ID().Bytes() - } + var outboundIds [][]byte + var inboundIds [][]byte - // Get inboundIds (accepted neighbors) - incomingNeighbors := autopeering.Selection.GetIncomingNeighbors() - inboundIds := make([][]byte, len(incomingNeighbors)) - for i, neighbor := range incomingNeighbors { - // Doesn't copy the ID, take care not to modify underlying bytearray! - inboundIds[i] = neighbor.ID().Bytes() + // When gossip (and autopeering selection) is enabled, we have neighbors to report + if autopeering.Selection != nil { + // Get outboundIds (chosen neighbors) + outgoingNeighbors := autopeering.Selection.GetOutgoingNeighbors() + outboundIds = make([][]byte, len(outgoingNeighbors)) + for i, neighbor := range outgoingNeighbors { + // Doesn't copy the ID, take care not to modify underlying bytearray! + outboundIds[i] = neighbor.ID().Bytes() + } + + // Get inboundIds (accepted neighbors) + incomingNeighbors := autopeering.Selection.GetIncomingNeighbors() + inboundIds = make([][]byte, len(incomingNeighbors)) + for i, neighbor := range incomingNeighbors { + // Doesn't copy the ID, take care not to modify underlying bytearray! + inboundIds[i] = neighbor.ID().Bytes() + } } packet := &heartbeat.Packet{OwnID: nodeID, OutboundIDs: outboundIds, InboundIDs: inboundIds} -- GitLab