From a9b53f6d76a2a3da17c6f9e7bc3ae1a42ab8f591 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Tue, 30 Jun 2015 13:01:49 +0100 Subject: [PATCH] refactoring some common logic --- probe/endpoint/reporter.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/probe/endpoint/reporter.go b/probe/endpoint/reporter.go index 87acdc031..4f5a7c7d5 100644 --- a/probe/endpoint/reporter.go +++ b/probe/endpoint/reporter.go @@ -85,11 +85,7 @@ func (r *Reporter) addConnection(rpt *report.Report, c *procspy.Connection) { } } - // Count the TCP connection. - edgeMeta := rpt.Address.EdgeMetadatas[edgeKey] - edgeMeta.WithConnCountTCP = true - edgeMeta.MaxConnCountTCP++ - rpt.Address.EdgeMetadatas[edgeKey] = edgeMeta + countTCPConnection(rpt.Address.EdgeMetadatas, edgeKey) if c.Proc.PID > 0 { var ( @@ -111,10 +107,14 @@ func (r *Reporter) addConnection(rpt *report.Report, c *procspy.Connection) { rpt.Endpoint.NodeMetadatas[scopedLocal] = md } - // Count the TCP connection. - edgeMeta := rpt.Endpoint.EdgeMetadatas[edgeKey] - edgeMeta.WithConnCountTCP = true - edgeMeta.MaxConnCountTCP++ - rpt.Endpoint.EdgeMetadatas[edgeKey] = edgeMeta + + countTCPConnection(rpt.Endpoint.EdgeMetadatas, edgeKey) } } + +func countTCPConnection(m report.EdgeMetadatas, edgeKey string) { + edgeMeta := m[edgeKey] + edgeMeta.WithConnCountTCP = true + edgeMeta.MaxConnCountTCP++ + m[edgeKey] = edgeMeta +}