This commit is contained in:
crusader 2018-04-28 01:20:01 +09:00
parent bbb569b9da
commit f01cb68527
16 changed files with 42 additions and 42 deletions

View File

@ -44,10 +44,10 @@ func GetDiscoverer() Discoverer {
type Discoverer interface {
Retain() chan *DiscoveryData
Release(dataChan chan *DiscoveryData)
DiscoverZone(dataChan chan *DiscoveryData, dz *ocmd.DiscoveryZone)
DiscoverHost(dataChan chan *DiscoveryData, zone *ocmd.Zone, dh *ocmd.DiscoveryHost)
DiscoverPort(dataChan chan *DiscoveryData, host *ocmd.Host, dp *ocmd.DiscoveryPort)
DiscoverSerice(dataChan chan *DiscoveryData, port *ocmd.Port, ds *ocmd.DiscoveryService)
DiscoverZone(dataChan chan *DiscoveryData, dz *ocmd.DiscoverZone)
DiscoverHost(dataChan chan *DiscoveryData, zone *ocmd.Zone, dh *ocmd.DiscoverHost)
DiscoverPort(dataChan chan *DiscoveryData, host *ocmd.Host, dp *ocmd.DiscoverPort)
DiscoverSerice(dataChan chan *DiscoveryData, port *ocmd.Port, ds *ocmd.DiscoverService)
}
type defaultDiscoverer struct {
@ -75,7 +75,7 @@ func (d *defaultDiscoverer) Stop(dataChan chan *DiscoveryData) {
}
}
func (d *defaultDiscoverer) DiscoverZone(dataChan chan *DiscoveryData, dz *ocmd.DiscoveryZone) {
func (d *defaultDiscoverer) DiscoverZone(dataChan chan *DiscoveryData, dz *ocmd.DiscoverZone) {
var wg sync.WaitGroup
d.stopChan = make(chan struct{})
@ -91,7 +91,7 @@ func (d *defaultDiscoverer) DiscoverZone(dataChan chan *DiscoveryData, dz *ocmd.
dataChan <- retainDiscoveryData(DiscoveryDataTypeStop, util.Now(), nil, nil)
}
func (d *defaultDiscoverer) DiscoverHost(dataChan chan *DiscoveryData, zone *ocmd.Zone, dh *ocmd.DiscoveryHost) {
func (d *defaultDiscoverer) DiscoverHost(dataChan chan *DiscoveryData, zone *ocmd.Zone, dh *ocmd.DiscoverHost) {
var wg sync.WaitGroup
d.stopChan = make(chan struct{})
@ -107,7 +107,7 @@ func (d *defaultDiscoverer) DiscoverHost(dataChan chan *DiscoveryData, zone *ocm
dataChan <- retainDiscoveryData(DiscoveryDataTypeStop, util.Now(), nil, nil)
}
func (d *defaultDiscoverer) DiscoverPort(dataChan chan *DiscoveryData, host *ocmd.Host, dp *ocmd.DiscoveryPort) {
func (d *defaultDiscoverer) DiscoverPort(dataChan chan *DiscoveryData, host *ocmd.Host, dp *ocmd.DiscoverPort) {
var wg sync.WaitGroup
d.stopChan = make(chan struct{})
@ -123,7 +123,7 @@ func (d *defaultDiscoverer) DiscoverPort(dataChan chan *DiscoveryData, host *ocm
dataChan <- retainDiscoveryData(DiscoveryDataTypeStop, util.Now(), nil, nil)
}
func (d *defaultDiscoverer) DiscoverSerice(dataChan chan *DiscoveryData, port *ocmd.Port, ds *ocmd.DiscoveryService) {
func (d *defaultDiscoverer) DiscoverSerice(dataChan chan *DiscoveryData, port *ocmd.Port, ds *ocmd.DiscoverService) {
var wg sync.WaitGroup
d.stopChan = make(chan struct{})
@ -139,7 +139,7 @@ func (d *defaultDiscoverer) DiscoverSerice(dataChan chan *DiscoveryData, port *o
dataChan <- retainDiscoveryData(DiscoveryDataTypeStop, util.Now(), nil, nil)
}
func (d *defaultDiscoverer) innerDiscoverZone(wg *sync.WaitGroup, dataChan chan *DiscoveryData, dz *ocmd.DiscoveryZone) {
func (d *defaultDiscoverer) innerDiscoverZone(wg *sync.WaitGroup, dataChan chan *DiscoveryData, dz *ocmd.DiscoverZone) {
defer func() {
wg.Done()
}()
@ -151,12 +151,12 @@ func (d *defaultDiscoverer) innerDiscoverZone(wg *sync.WaitGroup, dataChan chan
func(result interface{}) {
z := result.(*ocmd.Zone)
dataChan <- retainDiscoveryData(DiscoveryDataTypeZone, util.Now(), z, nil)
if nil != dz.DiscoveryHost {
if nil != dz.DiscoverHost {
cr, _ := cidr.NewCIDRRanger(z.Network)
dh := &ocmd.DiscoveryHost{
dh := &ocmd.DiscoverHost{
FirstScanRange: cr.First().String(),
LastScanRange: cr.Last().String(),
DiscoveryPort: dz.DiscoveryHost.DiscoveryPort,
DiscoverPort: dz.DiscoverHost.DiscoverPort,
}
wg.Add(1)
go d.innerDiscoverHost(wg, dataChan, z, dh)
@ -168,7 +168,7 @@ func (d *defaultDiscoverer) innerDiscoverZone(wg *sync.WaitGroup, dataChan chan
)
}
func (d *defaultDiscoverer) innerDiscoverHost(wg *sync.WaitGroup, dataChan chan *DiscoveryData, zone *ocmd.Zone, dh *ocmd.DiscoveryHost) {
func (d *defaultDiscoverer) innerDiscoverHost(wg *sync.WaitGroup, dataChan chan *DiscoveryData, zone *ocmd.Zone, dh *ocmd.DiscoverHost) {
defer func() {
wg.Done()
}()
@ -180,9 +180,9 @@ func (d *defaultDiscoverer) innerDiscoverHost(wg *sync.WaitGroup, dataChan chan
func(result interface{}) {
h := result.(*ocmd.Host)
dataChan <- retainDiscoveryData(DiscoveryDataTypeHost, util.Now(), h, nil)
if nil != dh.DiscoveryPort {
if nil != dh.DiscoverPort {
wg.Add(1)
go d.innerDiscoverPort(wg, dataChan, h, dh.DiscoveryPort)
go d.innerDiscoverPort(wg, dataChan, h, dh.DiscoverPort)
}
},
func(err error) {
@ -191,7 +191,7 @@ func (d *defaultDiscoverer) innerDiscoverHost(wg *sync.WaitGroup, dataChan chan
)
}
func (d *defaultDiscoverer) innerDiscoverPort(wg *sync.WaitGroup, dataChan chan *DiscoveryData, host *ocmd.Host, dp *ocmd.DiscoveryPort) {
func (d *defaultDiscoverer) innerDiscoverPort(wg *sync.WaitGroup, dataChan chan *DiscoveryData, host *ocmd.Host, dp *ocmd.DiscoverPort) {
defer func() {
wg.Done()
}()
@ -203,9 +203,9 @@ func (d *defaultDiscoverer) innerDiscoverPort(wg *sync.WaitGroup, dataChan chan
func(result interface{}) {
p := result.(*ocmd.Port)
dataChan <- retainDiscoveryData(DiscoveryDataTypePort, util.Now(), p, nil)
if nil != dp.DiscoveryService {
if nil != dp.DiscoverService {
wg.Add(1)
go d.innerDiscoverSerice(wg, dataChan, p, dp.DiscoveryService)
go d.innerDiscoverSerice(wg, dataChan, p, dp.DiscoverService)
}
},
func(err error) {
@ -214,7 +214,7 @@ func (d *defaultDiscoverer) innerDiscoverPort(wg *sync.WaitGroup, dataChan chan
)
}
func (d *defaultDiscoverer) innerDiscoverSerice(wg *sync.WaitGroup, dataChan chan *DiscoveryData, port *ocmd.Port, ds *ocmd.DiscoveryService) {
func (d *defaultDiscoverer) innerDiscoverSerice(wg *sync.WaitGroup, dataChan chan *DiscoveryData, port *ocmd.Port, ds *ocmd.DiscoverService) {
defer func() {
wg.Done()
}()

View File

@ -9,7 +9,7 @@ import (
"git.loafle.net/overflow/container_discovery/internal/discoverer/ipv6"
)
func scanHost(zone *ocmd.Zone, dh *ocmd.DiscoveryHost, resultChan chan interface{}, errChan chan error, doneChan chan<- struct{}, stopChan chan struct{}) {
func scanHost(zone *ocmd.Zone, dh *ocmd.DiscoverHost, resultChan chan interface{}, errChan chan error, doneChan chan<- struct{}, stopChan chan struct{}) {
defer func() {
doneChan <- struct{}{}
}()

View File

@ -15,7 +15,7 @@ import (
"git.loafle.net/overflow/container_discovery/internal/pcap"
)
func ScanHost(zone *ocmd.Zone, dh *ocmd.DiscoveryHost, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
func ScanHost(zone *ocmd.Zone, dh *ocmd.DiscoverHost, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
ps, err := pcap.RetainScanner(zone)
if nil != err {
errChan <- fmt.Errorf("Discovery: Cannot retain pcap instance %v", err)
@ -155,7 +155,7 @@ func handlePacketARP(zone *ocmd.Zone, hostRanges []net.IP, hosts map[string]*ocm
return h
}
func getTargetHostRange(dh *ocmd.DiscoveryHost, cr cidr.CIDRRanger) ([]net.IP, error) {
func getTargetHostRange(dh *ocmd.DiscoverHost, cr cidr.CIDRRanger) ([]net.IP, error) {
var firstIP net.IP
if "" != dh.FirstScanRange {
firstIP = net.ParseIP(dh.FirstScanRange)

View File

@ -6,7 +6,7 @@ import (
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
)
func ScanPort(host *ocmd.Host, dp *ocmd.DiscoveryPort, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
func ScanPort(host *ocmd.Host, dp *ocmd.DiscoverPort, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
var wg sync.WaitGroup
if dp.IncludeTCP {

View File

@ -18,7 +18,7 @@ import (
"github.com/google/gopacket/layers"
)
func scanPortTCP(host *ocmd.Host, dp *ocmd.DiscoveryPort, resultChan chan interface{}, errChan chan error, stopChan chan struct{}, wg *sync.WaitGroup) {
func scanPortTCP(host *ocmd.Host, dp *ocmd.DiscoverPort, resultChan chan interface{}, errChan chan error, stopChan chan struct{}, wg *sync.WaitGroup) {
defer func() {
wg.Done()
}()
@ -81,7 +81,7 @@ func scanPortTCP(host *ocmd.Host, dp *ocmd.DiscoveryPort, resultChan chan interf
}
}
func sendTCP(host *ocmd.Host, dp *ocmd.DiscoveryPort, stopChan chan struct{}) error {
func sendTCP(host *ocmd.Host, dp *ocmd.DiscoverPort, stopChan chan struct{}) error {
tcpPacket, err := makePacketPortTCP(host)
if nil != err {
return err
@ -123,7 +123,7 @@ Loop:
return nil
}
func handlePacketTCP(host *ocmd.Host, dp *ocmd.DiscoveryPort, ports map[int]*ocmd.Port, packet *layers.TCP) *ocmd.Port {
func handlePacketTCP(host *ocmd.Host, dp *ocmd.DiscoverPort, ports map[int]*ocmd.Port, packet *layers.TCP) *ocmd.Port {
if nil == packet || packet.DstPort != 60000 {
return nil
}

View File

@ -19,7 +19,7 @@ import (
"github.com/google/gopacket/layers"
)
func scanPortUDP(host *ocmd.Host, dp *ocmd.DiscoveryPort, resultChan chan interface{}, errChan chan error, stopChan chan struct{}, wg *sync.WaitGroup) {
func scanPortUDP(host *ocmd.Host, dp *ocmd.DiscoverPort, resultChan chan interface{}, errChan chan error, stopChan chan struct{}, wg *sync.WaitGroup) {
defer func() {
wg.Done()
}()
@ -83,7 +83,7 @@ func scanPortUDP(host *ocmd.Host, dp *ocmd.DiscoveryPort, resultChan chan interf
}
}
func sendUDP(host *ocmd.Host, dp *ocmd.DiscoveryPort, stopChan chan struct{}) error {
func sendUDP(host *ocmd.Host, dp *ocmd.DiscoverPort, stopChan chan struct{}) error {
ip := net.ParseIP(host.IP)
if nil == ip {
return fmt.Errorf("Discovery: IP(%s) of host is not valid", host.IP)
@ -137,7 +137,7 @@ func sendUDP(host *ocmd.Host, dp *ocmd.DiscoveryPort, stopChan chan struct{}) er
return nil
}
func handlePacketUDP(host *ocmd.Host, dp *ocmd.DiscoveryPort, ports map[int]*ocmd.Port, packet gopacket.Packet) *ocmd.Port {
func handlePacketUDP(host *ocmd.Host, dp *ocmd.DiscoverPort, ports map[int]*ocmd.Port, packet gopacket.Packet) *ocmd.Port {
ipLayer := packet.Layer(layers.LayerTypeIPv4)
if ipLayer.(*layers.IPv4).SrcIP.String() == host.Zone.IP {

View File

@ -9,7 +9,7 @@ import (
"github.com/google/gopacket/layers"
)
func ScanService(port *ocmd.Port, ds *ocmd.DiscoveryService, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
func ScanService(port *ocmd.Port, ds *ocmd.DiscoverService, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
portNumber, err := cuej.NumberToInt(port.PortNumber)
if err != nil {
errChan <- fmt.Errorf("Discovery: Service scan port[%s] error %v ", port.PortNumber, err)

View File

@ -13,7 +13,7 @@ import (
"git.loafle.net/overflow/container_discovery/internal/matcher"
)
func scanServiceTCP(port *ocmd.Port, ds *ocmd.DiscoveryService, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) bool {
func scanServiceTCP(port *ocmd.Port, ds *ocmd.DiscoverService, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) bool {
hostIP := port.Host.IP
portNumber, err := cuej.NumberToInt(port.PortNumber)
if err != nil {

View File

@ -9,7 +9,7 @@ import (
"git.loafle.net/overflow/container_discovery/internal/matcher"
)
func scanServiceUDP(port *ocmd.Port, ds *ocmd.DiscoveryService, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) bool {
func scanServiceUDP(port *ocmd.Port, ds *ocmd.DiscoverService, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) bool {
portNumber, err := cuej.NumberToInt(port.PortNumber)
if err != nil {
errChan <- fmt.Errorf("Discovery: Service scan port[%s] error %v ", port.PortNumber, err)

View File

@ -4,6 +4,6 @@ import (
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
)
func ScanHost(zone *ocmd.Zone, dh *ocmd.DiscoveryHost, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
func ScanHost(zone *ocmd.Zone, dh *ocmd.DiscoverHost, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
}

View File

@ -4,6 +4,6 @@ import (
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
)
func ScanPort(host *ocmd.Host, dp *ocmd.DiscoveryPort, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
func ScanPort(host *ocmd.Host, dp *ocmd.DiscoverPort, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
}

View File

@ -4,6 +4,6 @@ import (
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
)
func ScanService(port *ocmd.Port, ds *ocmd.DiscoveryService, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
func ScanService(port *ocmd.Port, ds *ocmd.DiscoverService, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
}

View File

@ -9,7 +9,7 @@ import (
"git.loafle.net/overflow/container_discovery/internal/discoverer/ipv6"
)
func scanPort(host *ocmd.Host, dp *ocmd.DiscoveryPort, resultChan chan interface{}, errChan chan error, doneChan chan<- struct{}, stopChan chan struct{}) {
func scanPort(host *ocmd.Host, dp *ocmd.DiscoverPort, resultChan chan interface{}, errChan chan error, doneChan chan<- struct{}, stopChan chan struct{}) {
defer func() {
doneChan <- struct{}{}
}()

View File

@ -9,7 +9,7 @@ import (
"git.loafle.net/overflow/container_discovery/internal/discoverer/ipv6"
)
func scanService(port *ocmd.Port, ds *ocmd.DiscoveryService, resultChan chan interface{}, errChan chan error, doneChan chan<- struct{}, stopChan chan struct{}) {
func scanService(port *ocmd.Port, ds *ocmd.DiscoverService, resultChan chan interface{}, errChan chan error, doneChan chan<- struct{}, stopChan chan struct{}) {
defer func() {
doneChan <- struct{}{}
}()

View File

@ -8,7 +8,7 @@ import (
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
)
func scanZone(dz *ocmd.DiscoveryZone, resultChan chan interface{}, errChan chan error, doneChan chan<- struct{}, stopChan chan struct{}) {
func scanZone(dz *ocmd.DiscoverZone, resultChan chan interface{}, errChan chan error, doneChan chan<- struct{}, stopChan chan struct{}) {
defer func() {
doneChan <- struct{}{}
}()

View File

@ -52,7 +52,7 @@ func (s *DiscoveryService) DestroyService() {
}
func (s *DiscoveryService) DiscoverZone(requesterID string, dz *ocmd.DiscoveryZone) error {
func (s *DiscoveryService) DiscoverZone(requesterID string, dz *ocmd.DiscoverZone) error {
go s.handleDiscovery(requesterID, func(dataChan chan *discoverer.DiscoveryData) {
s.discoverer.DiscoverZone(dataChan, dz)
})
@ -60,7 +60,7 @@ func (s *DiscoveryService) DiscoverZone(requesterID string, dz *ocmd.DiscoveryZo
return nil
}
func (s *DiscoveryService) DiscoverHost(requesterID string, zone *ocmd.Zone, dh *ocmd.DiscoveryHost) error {
func (s *DiscoveryService) DiscoverHost(requesterID string, zone *ocmd.Zone, dh *ocmd.DiscoverHost) error {
go s.handleDiscovery(requesterID, func(dataChan chan *discoverer.DiscoveryData) {
s.discoverer.DiscoverHost(dataChan, zone, dh)
})
@ -68,7 +68,7 @@ func (s *DiscoveryService) DiscoverHost(requesterID string, zone *ocmd.Zone, dh
return nil
}
func (s *DiscoveryService) DiscoverPort(requesterID string, host *ocmd.Host, dp *ocmd.DiscoveryPort) error {
func (s *DiscoveryService) DiscoverPort(requesterID string, host *ocmd.Host, dp *ocmd.DiscoverPort) error {
go s.handleDiscovery(requesterID, func(dataChan chan *discoverer.DiscoveryData) {
s.discoverer.DiscoverPort(dataChan, host, dp)
})
@ -76,7 +76,7 @@ func (s *DiscoveryService) DiscoverPort(requesterID string, host *ocmd.Host, dp
return nil
}
func (s *DiscoveryService) DiscoverService(requesterID string, port *ocmd.Port, ds *ocmd.DiscoveryService) error {
func (s *DiscoveryService) DiscoverService(requesterID string, port *ocmd.Port, ds *ocmd.DiscoverService) error {
go s.handleDiscovery(requesterID, func(dataChan chan *discoverer.DiscoveryData) {
s.discoverer.DiscoverSerice(dataChan, port, ds)
})