This commit is contained in:
crusader 2018-06-04 20:56:19 +09:00
parent 218c4c050c
commit 2345777e47
4 changed files with 8 additions and 6 deletions

2
Gopkg.lock generated
View File

@ -34,7 +34,7 @@
"protocol/json", "protocol/json",
"registry" "registry"
] ]
revision = "1092f7a7ae44ef2f907579af217f1a594e48959c" revision = "dcc3af07239b3f6fcbae3529bcb52c522b02053d"
[[projects]] [[projects]]
branch = "master" branch = "master"

View File

@ -43,6 +43,7 @@ func GetDiscoverer() Discoverer {
type Discoverer interface { type Discoverer interface {
Retain() chan *DiscoveryData Retain() chan *DiscoveryData
Release(dataChan chan *DiscoveryData) Release(dataChan chan *DiscoveryData)
Stop()
DiscoverZone(dataChan chan *DiscoveryData, dz *ocmd.DiscoverZone) DiscoverZone(dataChan chan *DiscoveryData, dz *ocmd.DiscoverZone)
DiscoverHost(dataChan chan *DiscoveryData, zone *ocmd.Zone, dh *ocmd.DiscoverHost) DiscoverHost(dataChan chan *DiscoveryData, zone *ocmd.Zone, dh *ocmd.DiscoverHost)
DiscoverPort(dataChan chan *DiscoveryData, host *ocmd.Host, dp *ocmd.DiscoverPort) DiscoverPort(dataChan chan *DiscoveryData, host *ocmd.Host, dp *ocmd.DiscoverPort)
@ -67,7 +68,7 @@ func (d *defaultDiscoverer) Release(dataChan chan *DiscoveryData) {
d.dataChanPool <- dataChan d.dataChanPool <- dataChan
} }
func (d *defaultDiscoverer) Stop(dataChan chan *DiscoveryData) { func (d *defaultDiscoverer) Stop() {
if nil != d.stopChan { if nil != d.stopChan {
close(d.stopChan) close(d.stopChan)
d.stopChan = nil d.stopChan = nil

View File

@ -75,13 +75,13 @@ var (
"UNKNOWN", "UNKNOWN",
"SSH", "SSH",
"WMI", "WMI",
"SNMP", "SNMP V3",
}, },
} }
dha = &ocmd.DiscoverHost{ dha = &ocmd.DiscoverHost{
FirstScanRangeV4: "192.168.1.1", FirstScanRangeV4: "192.168.1.0",
LastScanRangeV4: "192.168.1.254", LastScanRangeV4: "192.168.1.255",
DiscoverPort: &ocmd.DiscoverPort{ DiscoverPort: &ocmd.DiscoverPort{
FirstScanRange: 1, FirstScanRange: 1,
LastScanRange: 50000, LastScanRange: 50000,

View File

@ -85,7 +85,7 @@ func (s *DiscoveryService) DiscoverService(requesterID string, port *ocmd.Port,
return nil return nil
} }
func (s *DiscoveryService) StopRequest(requesterID string) error { func (s *DiscoveryService) StopDiscovery(requesterID string) error {
_stopChan, ok := s.pendingDiscovery.Load(requesterID) _stopChan, ok := s.pendingDiscovery.Load(requesterID)
if !ok { if !ok {
return fmt.Errorf("discovery request for [%s] is not exist", requesterID) return fmt.Errorf("discovery request for [%s] is not exist", requesterID)
@ -152,6 +152,7 @@ func (s *DiscoveryService) handleDiscovery(requesterID string, discoveryFunc fun
} }
data.Release() data.Release()
case <-stopChan: case <-stopChan:
s.discoverer.Stop()
return nil return nil
} }
} }