This commit is contained in:
crusader 2018-09-12 10:55:35 +09:00
parent c920ee3c3f
commit 725389f033
4 changed files with 62 additions and 4 deletions

View File

@ -5,6 +5,13 @@ import (
"git.loafle.net/overflow/model/util" "git.loafle.net/overflow/model/util"
) )
const (
DefaultOsType = "UNKNOWN"
DefaultHostType = "HOST"
DefaultHostVendor = "UNKNOWN"
DefaultHostModel = "UNKNOWN"
)
type Host struct { type Host struct {
MetaIPType *meta.MetaIPType `json:"metaIPType,omitempty"` MetaIPType *meta.MetaIPType `json:"metaIPType,omitempty"`
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
@ -13,9 +20,9 @@ type Host struct {
OsType string `json:"osType,omitempty"` OsType string `json:"osType,omitempty"`
DeviceType string `json:"deviceType,omitempty"` HostType string `json:"hostType,omitempty"`
DeviceVendor string `json:"deviceVendor,omitempty"` HostVendor string `json:"hostVendor,omitempty"`
DeviceModel string `json:"deviceModel,omitempty"` HostModel string `json:"hostModel,omitempty"`
Meta map[string]map[string]string `json:"meta,omitempty"` Meta map[string]map[string]string `json:"meta,omitempty"`
DiscoveredBy []string `json:"discoveredBy,omitempty"` DiscoveredBy []string `json:"discoveredBy,omitempty"`
@ -24,3 +31,15 @@ type Host struct {
Zone *Zone `json:"zone,omitempty"` Zone *Zone `json:"zone,omitempty"`
PortList []*Port `json:"portList,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,
}
}

View File

@ -2,6 +2,7 @@ package discovery
import ( import (
"encoding/json" "encoding/json"
"strconv"
"git.loafle.net/overflow/model/meta" "git.loafle.net/overflow/model/meta"
"git.loafle.net/overflow/model/util" "git.loafle.net/overflow/model/util"
@ -20,3 +21,11 @@ type Port struct {
ServiceList []*Service `json:"serviceList,omitempty"` ServiceList []*Service `json:"serviceList,omitempty"`
UDPLayer gopacket.Layer `json:"-"` 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)),
}
}

View File

@ -5,15 +5,36 @@ import (
"git.loafle.net/overflow/model/util" "git.loafle.net/overflow/model/util"
) )
const (
DefaultServiceType = "ETC"
DefaultServiceVendor = "UNKNOWN"
DefaultServiceVersion = "UNKNOWN"
)
type Service struct { type Service struct {
MetaCryptoType *meta.MetaCryptoType `json:"metaCryptoType,omitempty"` MetaCryptoType *meta.MetaCryptoType `json:"metaCryptoType,omitempty"`
Key string `json:"key,omitempty"` Key string `json:"key,omitempty"`
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
Description string `json:"description,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"` Meta map[string]map[string]string `json:"meta,omitempty"`
DiscoveredBy []string `json:"discoveredBy,omitempty"` DiscoveredBy []string `json:"discoveredBy,omitempty"`
DiscoveredDate *util.Timestamp `json:"discoveredDate,omitempty"` DiscoveredDate *util.Timestamp `json:"discoveredDate,omitempty"`
Port *Port `json:"port,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,
}
}

View File

@ -8,9 +8,9 @@ import (
) )
type Zone struct { type Zone struct {
MetaIPType *meta.MetaIPType `json:"metaIPType,omitempty"`
Network string `json:"network,omitempty"` Network string `json:"network,omitempty"`
Iface string `json:"iface,omitempty"` Iface string `json:"iface,omitempty"`
MetaIPType *meta.MetaIPType `json:"metaIPType,omitempty"`
Address string `json:"address,omitempty"` Address string `json:"address,omitempty"`
Mac string `json:"mac,omitempty"` Mac string `json:"mac,omitempty"`
@ -20,3 +20,12 @@ type Zone struct {
mtx sync.RWMutex `json:"-"` 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,
}
}