container_discovery/internal/discoverer/ipv4/service_udp.go
crusader 5f80794d28 ing
2018-06-21 19:54:31 +09:00

43 lines
1.2 KiB
Go

package ipv4
import (
"fmt"
csm "git.loafle.net/commons/service_matcher-go"
cuej "git.loafle.net/commons/util-go/encoding/json"
occu "git.loafle.net/overflow/commons-go/core/util"
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
ocmm "git.loafle.net/overflow/commons-go/model/meta"
"git.loafle.net/overflow/container_discovery/internal/matcher"
)
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)
return false
}
ms := matcher.GetUDPMatchers()
mi := csm.NewMatchInfo(port.Host.Address, portNumber)
for i := 0; i < len(ms); i++ {
m := ms[i]
p := csm.NewPacket(port.UDPLayer.LayerPayload(), len(port.UDPLayer.LayerPayload()))
if m.Match(mi, 0, p) {
s := &ocmd.Service{
Key: m.Key(),
Port: port,
MetaCryptoType: ocmm.ToMetaCryptoType(ocmm.MetaCryptoTypeEnumNONE),
DiscoveredDate: occu.NowPtr(),
}
resultChan <- s
return true
}
}
return false
}