Skip to content
Snippets Groups Projects
Unverified Commit 7dfd6728 authored by capossele's avatar capossele
Browse files

:recycle: improve analysis plugin

parent e9b8ce05
No related branches found
No related tags found
No related merge requests found
...@@ -25,6 +25,7 @@ var ( ...@@ -25,6 +25,7 @@ var (
lock sync.RWMutex lock sync.RWMutex
) )
// NeighborMetric contains the number of inbound/outbound neighbors.
type NeighborMetric struct { type NeighborMetric struct {
Inbound uint Inbound uint
Outbound uint Outbound uint
...@@ -35,7 +36,7 @@ func NumOfNeighbors() map[string]*NeighborMetric { ...@@ -35,7 +36,7 @@ func NumOfNeighbors() map[string]*NeighborMetric {
lock.RLock() lock.RLock()
defer lock.RUnlock() defer lock.RUnlock()
result := make(map[string]*NeighborMetric) result := make(map[string]*NeighborMetric)
for nodeID, _ := range nodes { for nodeID := range nodes {
// number of outgoing neighbors // number of outgoing neighbors
if _, exist := result[nodeID]; !exist { if _, exist := result[nodeID]; !exist {
result[nodeID] = &NeighborMetric{Outbound: uint(len(links[nodeID]))} result[nodeID] = &NeighborMetric{Outbound: uint(len(links[nodeID]))}
...@@ -44,7 +45,7 @@ func NumOfNeighbors() map[string]*NeighborMetric { ...@@ -44,7 +45,7 @@ func NumOfNeighbors() map[string]*NeighborMetric {
} }
// fill in incoming neighbors // fill in incoming neighbors
for outNeighborID, _ := range links[nodeID] { for outNeighborID := range links[nodeID] {
if _, exist := result[outNeighborID]; !exist { if _, exist := result[outNeighborID]; !exist {
result[outNeighborID] = &NeighborMetric{Inbound: 1} result[outNeighborID] = &NeighborMetric{Inbound: 1}
} else { } else {
...@@ -60,13 +61,13 @@ func NetworkGraph() *graph.Graph { ...@@ -60,13 +61,13 @@ func NetworkGraph() *graph.Graph {
lock.RLock() lock.RLock()
defer lock.RUnlock() defer lock.RUnlock()
var nodeIDs []string var nodeIDs []string
for id, _ := range nodes { for id := range nodes {
nodeIDs = append(nodeIDs, id) nodeIDs = append(nodeIDs, id)
} }
g := graph.New(nodeIDs) g := graph.New(nodeIDs)
for src, trgMap := range links { for src, trgMap := range links {
for dst, _ := range trgMap { for dst := range trgMap {
g.AddEdge(src, dst) g.AddEdge(src, dst)
} }
} }
......
...@@ -86,7 +86,7 @@ func run(_ *node.Plugin) { ...@@ -86,7 +86,7 @@ func run(_ *node.Plugin) {
func HandleConnection(conn *network.ManagedConnection) { func HandleConnection(conn *network.ManagedConnection) {
err := conn.SetReadTimeout(IdleTimeout) err := conn.SetReadTimeout(IdleTimeout)
if err != nil { if err != nil {
log.Debugw("Error setting read timeout; closing connection", "err", err) log.Warnw("Error setting read timeout; closing connection", "err", err)
_ = conn.Close() _ = conn.Close()
return return
} }
...@@ -103,7 +103,7 @@ func HandleConnection(conn *network.ManagedConnection) { ...@@ -103,7 +103,7 @@ func HandleConnection(conn *network.ManagedConnection) {
buffer := make([]byte, 2048) buffer := make([]byte, 2048)
_, err := conn.Read(buffer) _, err := conn.Read(buffer)
if err != nil && err != io.EOF && !strings.Contains(err.Error(), "use of closed network connection") { if err != nil && err != io.EOF && !strings.Contains(err.Error(), "use of closed network connection") {
log.Debugw("Read error", "err", err) log.Warnw("Read error", "err", err)
} }
// always close the connection when we've stopped reading from it // always close the connection when we've stopped reading from it
_ = conn.Close() _ = conn.Close()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment