-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnotification.go
54 lines (48 loc) · 1.38 KB
/
notification.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package packet
import (
"github.com/irai/packet/fastlog"
)
type Notification struct {
Addr Addr
Online bool
Manufacturer string
DHCP4Name NameEntry
MDNSName NameEntry
SSDPName NameEntry
LLMNRName NameEntry
NBNSName NameEntry
IsRouter bool
}
func (n Notification) String() string {
line := Logger.Msg("")
n.FastLog(line)
return line.ToString()
}
func (n Notification) FastLog(l *fastlog.Line) *fastlog.Line {
l.Struct(n.Addr)
l.Bool("online", n.Online)
if n.Manufacturer != "" {
l.String("manufacturer", n.Manufacturer)
}
l.Struct(n.DHCP4Name)
l.Struct(n.MDNSName)
l.Struct(n.SSDPName)
l.Struct(n.LLMNRName)
l.Struct(n.NBNSName)
l.Bool("router", n.IsRouter)
return l
}
func toNotification(host *Host) Notification {
// send the MACEntry name as there can be many IPv6 hosts, some with name entries not populated yet
return Notification{Addr: host.Addr, Online: host.Online, Manufacturer: host.MACEntry.Manufacturer,
DHCP4Name: host.MACEntry.DHCP4Name, MDNSName: host.MACEntry.MDNSName, SSDPName: host.MACEntry.SSDPName,
LLMNRName: host.LLMNRName, NBNSName: host.MACEntry.NBNSName,
IsRouter: host.MACEntry.IsRouter}
}
func (h *Session) sendNotification(notification Notification) {
if len(h.C) < cap(h.C) {
h.C <- notification
return
}
Logger.Msg("notification channel is full").Int("len", len(h.C)).Struct(notification).Write()
}