From abd59fda2d7eac791d5b045674ac916eb9b1affe Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Fri, 2 Sep 2016 11:38:44 +0100 Subject: [PATCH] lookup localNodeID in r.Endpoint.Nodes and refactor the connection{} construction so we can add some explanation of what is going on here. --- render/detailed/connections.go | 48 +++++++++++++++++----------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/render/detailed/connections.go b/render/detailed/connections.go index 03c6c81f6..b8c7b9ec6 100644 --- a/render/detailed/connections.go +++ b/render/detailed/connections.go @@ -62,6 +62,25 @@ type connection struct { port string // always the server-side port } +func newConnection(n report.Node, node report.Node, port string, endpointID string, localAddr string) connection { + c := connection{ + localNodeID: n.ID, + remoteNodeID: node.ID, + port: port, + } + // For internet nodes we break out individual addresses, both when + // the internet node is remote (an incoming connection from the + // internet) and 'local' (ie you are loading details on the + // internet node) + if isInternetNode(n) { + // We use the *endpoint* ID here since that has the reverse + // DNS information associated with it. + c.localNodeID = endpointID + c.localAddr = localAddr + } + return c +} + func (row connection) ID() string { return fmt.Sprintf("%s:%s-%s:%s-%s", row.remoteNodeID, row.remoteAddr, row.localNodeID, row.localAddr, row.port) } @@ -77,25 +96,13 @@ func incomingConnectionsSummary(topologyID string, r report.Report, n report.Nod } // Work out what port they are talking to, and count the number of // connections to that port. - // This is complicated as for internet nodes we break out individual - // address, both when the internet node is remote (an incoming - // connection from the internet) and 'local' (ie you are loading - // details on the internet node) for _, child := range endpointChildrenOf(node) { for _, localEndpointID := range child.Adjacency.Intersection(localEndpointIDs) { _, localAddr, port, ok := report.ParseEndpointNodeID(localEndpointID) if !ok { continue } - key := connection{ - localNodeID: n.ID, - remoteNodeID: node.ID, - port: port, - } - if isInternetNode(n) { - key.localNodeID = localEndpointID - key.localAddr = localAddr - } + key := newConnection(n, node, port, localEndpointID, localAddr) counts[key] = counts[key] + 1 } } @@ -138,15 +145,7 @@ func outgoingConnectionsSummary(topologyID string, r report.Report, n report.Nod if !ok { continue } - key := connection{ - localNodeID: n.ID, - remoteNodeID: node.ID, - port: port, - } - if isInternetNode(n) { - key.localNodeID = remoteEndpointID - key.localAddr = localAddr - } + key := newConnection(n, node, port, remoteEndpointID, localAddr) counts[key] = counts[key] + 1 } } @@ -207,9 +206,10 @@ func connectionRows(r report.Report, ns report.Nodes, in map[connection]int, inc connection.Linkable = false } if includeLocal { - // Does localNode have a DNS record in it? + // Does localNode (which, in this case, is an endpoint) + // have a DNS record in it? label := row.localAddr - if set, ok := ns[row.localNodeID].Sets.Lookup(endpoint.ReverseDNSNames); ok && len(set) > 0 { + if set, ok := r.Endpoint.Nodes[row.localNodeID].Sets.Lookup(endpoint.ReverseDNSNames); ok && len(set) > 0 { label = fmt.Sprintf("%s (%s)", set[0], label) } connection.Metadata = append(connection.Metadata,