This commit is contained in:
crusader 2018-09-05 05:25:04 +09:00
parent b9ac5b2a71
commit 1aa43cf403
3 changed files with 45 additions and 48 deletions

View File

@ -56,20 +56,23 @@ func Test_ofDiscoverer_DiscoverHost(t *testing.T) {
if !ok { if !ok {
return return
} }
switch msg.Type() {
_, messageType, data, _ := msg()
switch messageType {
case types.DiscoveryMessageTypeHost: case types.DiscoveryMessageTypeHost:
log.Print("Discovered Host: ", msg.Data()) log.Print("Discovered Host: ", data)
case types.DiscoveryMessageTypePort: case types.DiscoveryMessageTypePort:
log.Print("Discovered Port: ", msg.Data(), " Host: ", msg.Data().(*omd.Port).Host) log.Print("Discovered Port: ", data, " Host: ", data.(*omd.Port).Host)
case types.DiscoveryMessageTypeService: case types.DiscoveryMessageTypeService:
log.Print("Discovered Service: ", msg.Data(), " Port: ", msg.Data().(*omd.Service).Port, " Host: ", msg.Data().(*omd.Service).Port.Host) log.Print("Discovered Service: ", data, " Port: ", data.(*omd.Service).Port, " Host: ", data.(*omd.Service).Port.Host)
case types.DiscoveryMessageTypeStart: case types.DiscoveryMessageTypeStart:
log.Print("Discovery start: ", msg.Data()) log.Print("Discovery start: ", data)
case types.DiscoveryMessageTypeStop: case types.DiscoveryMessageTypeStop:
log.Print("Discovery stop: ", msg.Data()) log.Print("Discovery stop: ", data)
close(stopChan) close(stopChan)
default: default:
// log.Print(msg.Data()) // log.Print(data)
} }
} }
} }
@ -384,35 +387,35 @@ func Test_ofDiscoverer_handleRequest(t *testing.T) {
} }
} }
func Test_ofDiscoverer_discover(t *testing.T) { // func Test_ofDiscoverer_discover(t *testing.T) {
type fields struct { // type fields struct {
stopChan chan struct{} // stopChan chan struct{}
stopWg sync.WaitGroup // stopWg sync.WaitGroup
requestQueue chan types.DiscoveryRequest // requestQueue chan types.DiscoveryRequest
messageChan chan types.DiscoveryMessage // messageChan chan types.DiscoveryMessage
} // }
type args struct { // type args struct {
req types.DiscoveryRequest // req types.DiscoveryRequest
} // }
tests := []struct { // tests := []struct {
name string // name string
fields fields // fields fields
args args // args args
}{ // }{
// TODO: Add test cases. // // TODO: Add test cases.
} // }
for _, tt := range tests { // for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { // t.Run(tt.name, func(t *testing.T) {
d := &ofDiscoverer{ // d := &ofDiscoverer{
stopChan: tt.fields.stopChan, // stopChan: tt.fields.stopChan,
stopWg: tt.fields.stopWg, // stopWg: tt.fields.stopWg,
requestQueue: tt.fields.requestQueue, // requestQueue: tt.fields.requestQueue,
messageChan: tt.fields.messageChan, // messageChan: tt.fields.messageChan,
} // }
d.discover(tt.args.req) // d.discover(tt.args.req)
}) // })
} // }
} // }
func Test_ofDiscoverer_complexDiscover(t *testing.T) { func Test_ofDiscoverer_complexDiscover(t *testing.T) {
type fields struct { type fields struct {

View File

@ -38,7 +38,7 @@ func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) err
var delay atomic.Value var delay atomic.Value
delay.Store(false) delay.Store(false)
ticker := time.NewTicker(time.Millisecond * 500) ticker := time.NewTicker(time.Millisecond * 1000)
for { for {
select { select {
case packet, ok := <-tcpChan: case packet, ok := <-tcpChan:

View File

@ -9,7 +9,6 @@ import (
"github.com/google/gopacket" "github.com/google/gopacket"
"github.com/google/gopacket/layers" "github.com/google/gopacket/layers"
"github.com/google/gopacket/pcap" "github.com/google/gopacket/pcap"
deadlock "github.com/sasha-s/go-deadlock"
) )
func NewPCapScanner(zone *omd.Zone) PCapScanner { func NewPCapScanner(zone *omd.Zone) PCapScanner {
@ -49,24 +48,19 @@ type pCapScan struct {
pCapHandle *pcap.Handle pCapHandle *pcap.Handle
zone *omd.Zone zone *omd.Zone
// arpListenerChanMtx sync.RWMutex arpListenerChanMtx sync.RWMutex
arpListenerChanMtx deadlock.RWMutex
arpListenerChans []chan *layers.ARP arpListenerChans []chan *layers.ARP
// icmp4ListenerChanMtx sync.RWMutex icmp4ListenerChanMtx sync.RWMutex
icmp4ListenerChanMtx deadlock.RWMutex
icmp4ListenerChans []chan gopacket.Packet icmp4ListenerChans []chan gopacket.Packet
// icmp6ListenerChanMtx sync.RWMutex icmp6ListenerChanMtx sync.RWMutex
icmp6ListenerChanMtx deadlock.RWMutex
icmp6ListenerChans []chan gopacket.Packet icmp6ListenerChans []chan gopacket.Packet
// tcpListenerChanMtx sync.RWMutex tcpListenerChanMtx sync.RWMutex
tcpListenerChanMtx deadlock.RWMutex
tcpListenerChans map[string][]chan *layers.TCP tcpListenerChans map[string][]chan *layers.TCP
// udpListenerChanMtx sync.RWMutex udpListenerChanMtx sync.RWMutex
udpListenerChanMtx deadlock.RWMutex
udpListenerChans map[string][]chan gopacket.Packet udpListenerChans map[string][]chan gopacket.Packet
refCount int refCount int