Skip to content

Commit

Permalink
Rename db.Node into db.AddrPort
Browse files Browse the repository at this point in the history
  • Loading branch information
yuuki committed Nov 24, 2019
1 parent f43dbf6 commit a341424
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
35 changes: 18 additions & 17 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions db/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit a341424

Please sign in to comment.