diff --git a/modules/events_view.go b/modules/events_view.go index e24e7b9d..5dde4280 100644 --- a/modules/events_view.go +++ b/modules/events_view.go @@ -41,7 +41,7 @@ func (s EventsStream) viewApEvent(e session.Event) { fmt.Printf("[%s] [%s] %s\n", e.Time.Format(eventTimeFormat), core.Green(e.Tag), - ap) + ap.String()) } } @@ -75,7 +75,7 @@ func (s EventsStream) viewEndpointEvent(e session.Event) { fmt.Printf("[%s] [%s] %s\n", e.Time.Format(eventTimeFormat), core.Green(e.Tag), - t) + t.String()) } } diff --git a/network/lan_endpoint.go b/network/lan_endpoint.go index 1b389a5e..86ee6b25 100644 --- a/network/lan_endpoint.go +++ b/network/lan_endpoint.go @@ -28,6 +28,7 @@ type Endpoint struct { ResolvedCallback OnHostResolvedCallback `json:"-"` FirstSeen time.Time `json:"first_seen"` LastSeen time.Time `json:"last_seen"` + Meta *Meta `json:"meta"` } func ip2int(ip net.IP) uint32 { @@ -56,6 +57,7 @@ func NewEndpointNoResolve(ip, mac, name string, bits uint32) *Endpoint { ResolvedCallback: nil, FirstSeen: now, LastSeen: now, + Meta: NewMeta(), } _, netw, _ := net.ParseCIDR(e.CIDR()) @@ -66,7 +68,6 @@ func NewEndpointNoResolve(ip, mac, name string, bits uint32) *Endpoint { func NewEndpoint(ip, mac string) *Endpoint { e := NewEndpointNoResolve(ip, mac, "", 0) - // start resolver goroutine go func() { if names, err := net.LookupAddr(e.IpAddress); err == nil && len(names) > 0 { diff --git a/network/meta.go b/network/meta.go new file mode 100644 index 00000000..d7c3bab5 --- /dev/null +++ b/network/meta.go @@ -0,0 +1,44 @@ +package network + +import ( + "encoding/json" + "sync" +) + +type Meta struct { + sync.Mutex + m map[string]interface{} +} + +// we want to protect concurrent access to the Meta +// object so the m field needs to be unexported, this +// is to have it in JSON regardless. +type metaJSON struct { + Values map[string]interface{} `json:"values"` +} + +func NewMeta() *Meta { + return &Meta{ + m: make(map[string]interface{}), + } +} + +func (m *Meta) MarshalJSON() ([]byte, error) { + return json.Marshal(metaJSON{Values: m.m}) +} + +func (m *Meta) Set(name string, value interface{}) { + m.Lock() + defer m.Unlock() + m.m[name] = value +} + +func (m *Meta) Get(name string) interface{} { + m.Lock() + defer m.Unlock() + + if v, found := m.m[name]; found == true { + return v + } + return "" +}