From f01cb685277d212fcdf8baadd88e606363695dc5 Mon Sep 17 00:00:00 2001 From: crusader Date: Sat, 28 Apr 2018 01:20:01 +0900 Subject: [PATCH] ing --- internal/discoverer/discoverer.go | 38 ++++++++++++------------- internal/discoverer/host.go | 2 +- internal/discoverer/ipv4/host.go | 4 +-- internal/discoverer/ipv4/port.go | 2 +- internal/discoverer/ipv4/port_tcp.go | 6 ++-- internal/discoverer/ipv4/port_udp.go | 6 ++-- internal/discoverer/ipv4/service.go | 2 +- internal/discoverer/ipv4/service_tcp.go | 2 +- internal/discoverer/ipv4/service_udp.go | 2 +- internal/discoverer/ipv6/host.go | 2 +- internal/discoverer/ipv6/port.go | 2 +- internal/discoverer/ipv6/service.go | 2 +- internal/discoverer/port.go | 2 +- internal/discoverer/service.go | 2 +- internal/discoverer/zone.go | 2 +- service/DiscoveryService.go | 8 +++--- 16 files changed, 42 insertions(+), 42 deletions(-) diff --git a/internal/discoverer/discoverer.go b/internal/discoverer/discoverer.go index 1c4876d..271fcce 100644 --- a/internal/discoverer/discoverer.go +++ b/internal/discoverer/discoverer.go @@ -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() }() diff --git a/internal/discoverer/host.go b/internal/discoverer/host.go index f92131c..feabcfc 100644 --- a/internal/discoverer/host.go +++ b/internal/discoverer/host.go @@ -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{}{} }() diff --git a/internal/discoverer/ipv4/host.go b/internal/discoverer/ipv4/host.go index f7256f6..ae0c772 100644 --- a/internal/discoverer/ipv4/host.go +++ b/internal/discoverer/ipv4/host.go @@ -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) diff --git a/internal/discoverer/ipv4/port.go b/internal/discoverer/ipv4/port.go index 67543d8..1598578 100644 --- a/internal/discoverer/ipv4/port.go +++ b/internal/discoverer/ipv4/port.go @@ -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 { diff --git a/internal/discoverer/ipv4/port_tcp.go b/internal/discoverer/ipv4/port_tcp.go index 2b45484..cbcb897 100644 --- a/internal/discoverer/ipv4/port_tcp.go +++ b/internal/discoverer/ipv4/port_tcp.go @@ -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 } diff --git a/internal/discoverer/ipv4/port_udp.go b/internal/discoverer/ipv4/port_udp.go index b3112e2..fe35deb 100644 --- a/internal/discoverer/ipv4/port_udp.go +++ b/internal/discoverer/ipv4/port_udp.go @@ -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 { diff --git a/internal/discoverer/ipv4/service.go b/internal/discoverer/ipv4/service.go index fe433c7..4d0a901 100644 --- a/internal/discoverer/ipv4/service.go +++ b/internal/discoverer/ipv4/service.go @@ -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) diff --git a/internal/discoverer/ipv4/service_tcp.go b/internal/discoverer/ipv4/service_tcp.go index efa3bd2..99f0012 100644 --- a/internal/discoverer/ipv4/service_tcp.go +++ b/internal/discoverer/ipv4/service_tcp.go @@ -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 { diff --git a/internal/discoverer/ipv4/service_udp.go b/internal/discoverer/ipv4/service_udp.go index 186af9b..6df7c12 100644 --- a/internal/discoverer/ipv4/service_udp.go +++ b/internal/discoverer/ipv4/service_udp.go @@ -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) diff --git a/internal/discoverer/ipv6/host.go b/internal/discoverer/ipv6/host.go index efa52c7..c2f7187 100644 --- a/internal/discoverer/ipv6/host.go +++ b/internal/discoverer/ipv6/host.go @@ -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{}) { } diff --git a/internal/discoverer/ipv6/port.go b/internal/discoverer/ipv6/port.go index fb52bb9..beaa31a 100644 --- a/internal/discoverer/ipv6/port.go +++ b/internal/discoverer/ipv6/port.go @@ -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{}) { } diff --git a/internal/discoverer/ipv6/service.go b/internal/discoverer/ipv6/service.go index f46b06d..dd83d55 100644 --- a/internal/discoverer/ipv6/service.go +++ b/internal/discoverer/ipv6/service.go @@ -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{}) { } diff --git a/internal/discoverer/port.go b/internal/discoverer/port.go index 59da357..f3eebec 100644 --- a/internal/discoverer/port.go +++ b/internal/discoverer/port.go @@ -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{}{} }() diff --git a/internal/discoverer/service.go b/internal/discoverer/service.go index 80f88e3..562544b 100644 --- a/internal/discoverer/service.go +++ b/internal/discoverer/service.go @@ -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{}{} }() diff --git a/internal/discoverer/zone.go b/internal/discoverer/zone.go index 39025d9..aaf2b89 100644 --- a/internal/discoverer/zone.go +++ b/internal/discoverer/zone.go @@ -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{}{} }() diff --git a/service/DiscoveryService.go b/service/DiscoveryService.go index 6d1bc1a..3768eda 100644 --- a/service/DiscoveryService.go +++ b/service/DiscoveryService.go @@ -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) })