This commit is contained in:
crusader 2018-03-27 00:43:44 +09:00
parent 25d97c07f9
commit a15effa1ad

View File

@ -32,6 +32,7 @@ func DiscoverZone(probeService *oopcs.ProbeService, requesterID string, dz *disc
return return
} }
discoverer.stopWg.Add(1)
discoverer.discoverZone(probeService, requesterID, dz) discoverer.discoverZone(probeService, requesterID, dz)
discoverer.stopWg.Wait() discoverer.stopWg.Wait()
@ -44,6 +45,7 @@ func DiscoverHost(probeService *oopcs.ProbeService, requesterID string, zone *di
logging.Logger().Warnf("Discovery: Discovery is running already") logging.Logger().Warnf("Discovery: Discovery is running already")
return return
} }
discoverer.stopWg.Add(1)
discoverer.discoverHost(probeService, requesterID, zone, dh) discoverer.discoverHost(probeService, requesterID, zone, dh)
discoverer.stopWg.Wait() discoverer.stopWg.Wait()
discoverer.complete() discoverer.complete()
@ -55,6 +57,7 @@ func DiscoverPort(probeService *oopcs.ProbeService, requesterID string, host *di
logging.Logger().Warnf("Discovery: Discovery is running already") logging.Logger().Warnf("Discovery: Discovery is running already")
return return
} }
discoverer.stopWg.Add(1)
discoverer.discoverPort(probeService, requesterID, host, dp) discoverer.discoverPort(probeService, requesterID, host, dp)
discoverer.stopWg.Wait() discoverer.stopWg.Wait()
discoverer.complete() discoverer.complete()
@ -66,6 +69,7 @@ func DiscoverService(probeService *oopcs.ProbeService, requesterID string, port
logging.Logger().Warnf("Discovery: Discovery is running already") logging.Logger().Warnf("Discovery: Discovery is running already")
return return
} }
discoverer.stopWg.Add(1)
discoverer.discoverService(probeService, requesterID, port, ds) discoverer.discoverService(probeService, requesterID, port, ds)
discoverer.stopWg.Wait() discoverer.stopWg.Wait()
discoverer.complete() discoverer.complete()
@ -129,6 +133,9 @@ func (d *discovery) stop() {
} }
func (d *discovery) discoverZone(probeService *oopcs.ProbeService, requesterID string, dz *discoveryM.DiscoveryZone) { func (d *discovery) discoverZone(probeService *oopcs.ProbeService, requesterID string, dz *discoveryM.DiscoveryZone) {
defer func() {
d.stopWg.Done()
}()
go taskScan(d, go taskScan(d,
func(resultChan chan interface{}, errChan chan error, doneChan chan struct{}, stopChan chan struct{}) { func(resultChan chan interface{}, errChan chan error, doneChan chan struct{}, stopChan chan struct{}) {
scanZone(dz, resultChan, errChan, doneChan, stopChan) scanZone(dz, resultChan, errChan, doneChan, stopChan)
@ -144,6 +151,7 @@ func (d *discovery) discoverZone(probeService *oopcs.ProbeService, requesterID s
LastScanRange: cr.Last().String(), LastScanRange: cr.Last().String(),
DiscoveryPort: dz.DiscoveryHost.DiscoveryPort, DiscoveryPort: dz.DiscoveryHost.DiscoveryPort,
} }
d.stopWg.Add(1)
d.discoverHost(probeService, requesterID, z, dh) d.discoverHost(probeService, requesterID, z, dh)
} }
}, },
@ -151,6 +159,9 @@ func (d *discovery) discoverZone(probeService *oopcs.ProbeService, requesterID s
} }
func (d *discovery) discoverHost(probeService *oopcs.ProbeService, requesterID string, zone *discoveryM.Zone, dh *discoveryM.DiscoveryHost) { func (d *discovery) discoverHost(probeService *oopcs.ProbeService, requesterID string, zone *discoveryM.Zone, dh *discoveryM.DiscoveryHost) {
defer func() {
d.stopWg.Done()
}()
go taskScan(d, go taskScan(d,
func(resultChan chan interface{}, errChan chan error, doneChan chan struct{}, stopChan chan struct{}) { func(resultChan chan interface{}, errChan chan error, doneChan chan struct{}, stopChan chan struct{}) {
scanHost(zone, dh, resultChan, errChan, doneChan, stopChan) scanHost(zone, dh, resultChan, errChan, doneChan, stopChan)
@ -160,6 +171,7 @@ func (d *discovery) discoverHost(probeService *oopcs.ProbeService, requesterID s
logging.Logger().Debugf("host: %v", h) logging.Logger().Debugf("host: %v", h)
probeService.Send("DiscoveryService.DiscoveredHost", requesterID, h) probeService.Send("DiscoveryService.DiscoveredHost", requesterID, h)
if nil != dh.DiscoveryPort { if nil != dh.DiscoveryPort {
d.stopWg.Add(1)
d.discoverPort(probeService, requesterID, h, dh.DiscoveryPort) d.discoverPort(probeService, requesterID, h, dh.DiscoveryPort)
} }
}, },
@ -167,6 +179,9 @@ func (d *discovery) discoverHost(probeService *oopcs.ProbeService, requesterID s
} }
func (d *discovery) discoverPort(probeService *oopcs.ProbeService, requesterID string, host *discoveryM.Host, dp *discoveryM.DiscoveryPort) { func (d *discovery) discoverPort(probeService *oopcs.ProbeService, requesterID string, host *discoveryM.Host, dp *discoveryM.DiscoveryPort) {
defer func() {
d.stopWg.Done()
}()
go taskScan(d, go taskScan(d,
func(resultChan chan interface{}, errChan chan error, doneChan chan struct{}, stopChan chan struct{}) { func(resultChan chan interface{}, errChan chan error, doneChan chan struct{}, stopChan chan struct{}) {
scanPort(host, dp, resultChan, errChan, doneChan, stopChan) scanPort(host, dp, resultChan, errChan, doneChan, stopChan)
@ -176,6 +191,7 @@ func (d *discovery) discoverPort(probeService *oopcs.ProbeService, requesterID s
logging.Logger().Debugf("port: %v", p) logging.Logger().Debugf("port: %v", p)
probeService.Send("DiscoveryService.DiscoveredPort", requesterID, p) probeService.Send("DiscoveryService.DiscoveredPort", requesterID, p)
if nil != dp.DiscoveryService { if nil != dp.DiscoveryService {
d.stopWg.Add(1)
d.discoverService(probeService, requesterID, p, dp.DiscoveryService) d.discoverService(probeService, requesterID, p, dp.DiscoveryService)
} }
}, },
@ -183,6 +199,9 @@ func (d *discovery) discoverPort(probeService *oopcs.ProbeService, requesterID s
} }
func (d *discovery) discoverService(probeService *oopcs.ProbeService, requesterID string, port *discoveryM.Port, ds *discoveryM.DiscoveryService) { func (d *discovery) discoverService(probeService *oopcs.ProbeService, requesterID string, port *discoveryM.Port, ds *discoveryM.DiscoveryService) {
defer func() {
d.stopWg.Done()
}()
go taskScan(d, go taskScan(d,
func(resultChan chan interface{}, errChan chan error, doneChan chan struct{}, stopChan chan struct{}) { func(resultChan chan interface{}, errChan chan error, doneChan chan struct{}, stopChan chan struct{}) {
scanService(port, ds, resultChan, errChan, doneChan, stopChan) scanService(port, ds, resultChan, errChan, doneChan, stopChan)
@ -190,7 +209,6 @@ func (d *discovery) discoverService(probeService *oopcs.ProbeService, requesterI
func(result interface{}) { func(result interface{}) {
s := result.(*discoveryM.Service) s := result.(*discoveryM.Service)
probeService.Send("DiscoveryService.DiscoveredService", requesterID, s) probeService.Send("DiscoveryService.DiscoveredService", requesterID, s)
logging.Logger().Debugf("service: %s(%s)[%s:%s]", s.ServiceName, s.CryptoType, port.Host.IP, port.PortNumber)
}, },
) )
} }