diff --git a/db/db.go b/db/db.go index 63469c31..12b70647 100644 --- a/db/db.go +++ b/db/db.go @@ -309,26 +309,27 @@ func (db *DB) InsertOrUpdateHostFlows(flows []*tcpflow.HostFlow) error { return nil } -// AddrPort are IP addr and port. -type AddrPort struct { - IPAddr net.IP - Port int - Pgid int - Pname string - Connections int +// Node represents a minimum unit of a graph tree. +type Node struct { + IPAddr net.IP + Port int // 0 if active node + Pgid int // Process Group ID (Linux) + Pname string // Process Name (Linux) } -func (a *AddrPort) String() string { - port := fmt.Sprintf("%d", a.Port) - if a.Port == 0 { +func (n *Node) String() string { + port := fmt.Sprintf("%d", n.Port) + if n.Port == 0 { port = "many" } - return fmt.Sprintf("%s:%s ('%s', pgid=%d, connections=%d)", a.IPAddr, port, a.Pname, a.Pgid, a.Connections) + return fmt.Sprintf("%s:%s ('%s', pgid=%d)", + n.IPAddr, port, n.Pname, n.Pgid) } +// Flows represents a flow between a active node and a passive node. type Flow struct { - ActiveNode *AddrPort - PassiveNode *AddrPort + ActiveNode *Node + PassiveNode *Node Connections int } @@ -395,13 +396,13 @@ func (db *DB) FindPassiveFlows(addrs []net.IP) (Flows, error) { } key := fmt.Sprintf("%s-%s", pipv4, ppname) flows[key] = append(flows[key], &Flow{ - ActiveNode: &AddrPort{ + ActiveNode: &Node{ IPAddr: net.ParseIP(aipv4), Port: 0, Pgid: apgid, Pname: apname, }, - PassiveNode: &AddrPort{ + PassiveNode: &Node{ IPAddr: net.ParseIP(pipv4), Port: pport, Pgid: ppgid, @@ -475,13 +476,13 @@ func (db *DB) FindActiveFlows(addrs []net.IP) (Flows, error) { } key := fmt.Sprintf("%s-%s", aipv4, apname) flows[key] = append(flows[key], &Flow{ - ActiveNode: &AddrPort{ + ActiveNode: &Node{ IPAddr: net.ParseIP(aipv4), Port: 0, Pgid: apgid, Pname: apname, }, - PassiveNode: &AddrPort{ + PassiveNode: &Node{ IPAddr: net.ParseIP(pipv4), Port: pport, Pgid: ppgid, diff --git a/db/db_test.go b/db/db_test.go index 4be3a7e4..e9600499 100644 --- a/db/db_test.go +++ b/db/db_test.go @@ -289,13 +289,13 @@ func TestFindPassiveFlows(t *testing.T) { want := Flows{ "192.168.3.1-unicorn": []*Flow{ { - ActiveNode: &AddrPort{ + ActiveNode: &Node{ IPAddr: net.ParseIP("192.168.2.1"), Port: 0, Pgid: 4123, Pname: "nginx", }, - PassiveNode: &AddrPort{ + PassiveNode: &Node{ IPAddr: net.ParseIP("192.168.3.1"), Port: 8000, Pgid: 10021, @@ -304,13 +304,13 @@ func TestFindPassiveFlows(t *testing.T) { Connections: 10, }, { - ActiveNode: &AddrPort{ + ActiveNode: &Node{ IPAddr: net.ParseIP("192.168.5.1"), Port: 0, Pgid: 13456, Pname: "varnish", }, - PassiveNode: &AddrPort{ + PassiveNode: &Node{ IPAddr: net.ParseIP("192.168.3.1"), Port: 8000, Pgid: 10021, @@ -375,13 +375,13 @@ func TestFindActiveFlows(t *testing.T) { want := Flows{ "192.168.2.1-unicorn": []*Flow{ { - ActiveNode: &AddrPort{ + ActiveNode: &Node{ IPAddr: net.ParseIP("192.168.2.1"), Port: 0, Pgid: 4123, Pname: "unicorn", }, - PassiveNode: &AddrPort{ + PassiveNode: &Node{ IPAddr: net.ParseIP("192.168.3.1"), Port: 3306, Pgid: 10021, @@ -390,13 +390,13 @@ func TestFindActiveFlows(t *testing.T) { Connections: 10, }, { - ActiveNode: &AddrPort{ + ActiveNode: &Node{ IPAddr: net.ParseIP("192.168.2.1"), Port: 0, Pgid: 4123, Pname: "unicorn", }, - PassiveNode: &AddrPort{ + PassiveNode: &Node{ IPAddr: net.ParseIP("192.168.4.1"), Port: 11211, Pgid: 21199,