diff --git a/discovery/Host.go b/discovery/Host.go index b837489..f56ae0e 100644 --- a/discovery/Host.go +++ b/discovery/Host.go @@ -5,6 +5,13 @@ import ( "git.loafle.net/overflow/model/util" ) +const ( + DefaultOsType = "UNKNOWN" + DefaultHostType = "HOST" + DefaultHostVendor = "UNKNOWN" + DefaultHostModel = "UNKNOWN" +) + type Host struct { MetaIPType *meta.MetaIPType `json:"metaIPType,omitempty"` Name string `json:"name,omitempty"` @@ -13,9 +20,9 @@ type Host struct { OsType string `json:"osType,omitempty"` - DeviceType string `json:"deviceType,omitempty"` - DeviceVendor string `json:"deviceVendor,omitempty"` - DeviceModel string `json:"deviceModel,omitempty"` + HostType string `json:"hostType,omitempty"` + HostVendor string `json:"hostVendor,omitempty"` + HostModel string `json:"hostModel,omitempty"` Meta map[string]map[string]string `json:"meta,omitempty"` DiscoveredBy []string `json:"discoveredBy,omitempty"` @@ -24,3 +31,15 @@ type Host struct { Zone *Zone `json:"zone,omitempty"` PortList []*Port `json:"portList,omitempty"` } + +func NewHost(zone *Zone, metaIPType *meta.MetaIPType, address string) *Host { + return &Host{ + Zone: zone, + MetaIPType: metaIPType, + Address: address, + OsType: DefaultOsType, + HostType: DefaultHostType, + HostVendor: DefaultHostVendor, + HostModel: DefaultHostModel, + } +} diff --git a/discovery/Port.go b/discovery/Port.go index 323f69b..338274c 100644 --- a/discovery/Port.go +++ b/discovery/Port.go @@ -2,6 +2,7 @@ package discovery import ( "encoding/json" + "strconv" "git.loafle.net/overflow/model/meta" "git.loafle.net/overflow/model/util" @@ -20,3 +21,11 @@ type Port struct { ServiceList []*Service `json:"serviceList,omitempty"` UDPLayer gopacket.Layer `json:"-"` } + +func NewPort(host *Host, metaPortType *meta.MetaPortType, portNumber int) *Port { + return &Port{ + Host: host, + MetaPortType: metaPortType, + PortNumber: json.Number(strconv.Itoa(portNumber)), + } +} diff --git a/discovery/Service.go b/discovery/Service.go index e242257..205b694 100644 --- a/discovery/Service.go +++ b/discovery/Service.go @@ -5,15 +5,36 @@ import ( "git.loafle.net/overflow/model/util" ) +const ( + DefaultServiceType = "ETC" + DefaultServiceVendor = "UNKNOWN" + DefaultServiceVersion = "UNKNOWN" +) + type Service struct { MetaCryptoType *meta.MetaCryptoType `json:"metaCryptoType,omitempty"` Key string `json:"key,omitempty"` Name string `json:"name,omitempty"` Description string `json:"description,omitempty"` + ServiceType string `json:"serviceType,omitempty"` + ServiceVendor string `json:"serviceVendor,omitempty"` + ServiceVersion string `json:"serviceVersion,omitempty"` + Meta map[string]map[string]string `json:"meta,omitempty"` DiscoveredBy []string `json:"discoveredBy,omitempty"` DiscoveredDate *util.Timestamp `json:"discoveredDate,omitempty"` Port *Port `json:"port,omitempty"` } + +func NewService(port *Port, metaCryptoType *meta.MetaCryptoType, key string) *Service { + return &Service{ + Port: port, + MetaCryptoType: metaCryptoType, + Key: key, + ServiceType: DefaultServiceType, + ServiceVendor: DefaultServiceVendor, + ServiceVersion: DefaultServiceVersion, + } +} diff --git a/discovery/Zone.go b/discovery/Zone.go index 3b44e8b..6be8545 100644 --- a/discovery/Zone.go +++ b/discovery/Zone.go @@ -8,9 +8,9 @@ import ( ) type Zone struct { + MetaIPType *meta.MetaIPType `json:"metaIPType,omitempty"` Network string `json:"network,omitempty"` Iface string `json:"iface,omitempty"` - MetaIPType *meta.MetaIPType `json:"metaIPType,omitempty"` Address string `json:"address,omitempty"` Mac string `json:"mac,omitempty"` @@ -20,3 +20,12 @@ type Zone struct { mtx sync.RWMutex `json:"-"` } + +func NewZone(metaIPType *meta.MetaIPType, network string, iface string, address string) *Zone { + return &Zone{ + MetaIPType: metaIPType, + Network: network, + Iface: iface, + Address: address, + } +}