ing
This commit is contained in:
parent
2f67baeb46
commit
3037d18a5f
|
@ -16,5 +16,5 @@ type Port struct {
|
||||||
PortType string `json:"portType,omitempty"`
|
PortType string `json:"portType,omitempty"`
|
||||||
PortNumber int `json:"portNumber,omitempty"`
|
PortNumber int `json:"portNumber,omitempty"`
|
||||||
|
|
||||||
UDPLayer gopacket.Layer
|
UDPLayer gopacket.Layer `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,8 @@ type Zone struct {
|
||||||
Iface string `json:"iface"`
|
Iface string `json:"iface"`
|
||||||
Mac string `json:"mac"`
|
Mac string `json:"mac"`
|
||||||
|
|
||||||
hosts map[string]*Host
|
hosts map[string]*Host `json:"-"`
|
||||||
mtx sync.RWMutex
|
mtx sync.RWMutex `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (z *Zone) AddHost(h *Host) {
|
func (z *Zone) AddHost(h *Host) {
|
||||||
|
|
|
@ -4,10 +4,10 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"git.loafle.net/commons_go/util/net/cidr"
|
|
||||||
|
|
||||||
"git.loafle.net/commons_go/logging"
|
"git.loafle.net/commons_go/logging"
|
||||||
|
"git.loafle.net/commons_go/util/net/cidr"
|
||||||
"git.loafle.net/overflow/overflow_discovery/api/module/discovery/model"
|
"git.loafle.net/overflow/overflow_discovery/api/module/discovery/model"
|
||||||
|
"git.loafle.net/overflow/overflow_discovery/rpc/notify"
|
||||||
)
|
)
|
||||||
|
|
||||||
var discoverer *discovery
|
var discoverer *discovery
|
||||||
|
@ -80,6 +80,7 @@ func (d *discovery) discoverZone(dz *model.DiscoveryZone) {
|
||||||
func(result interface{}) {
|
func(result interface{}) {
|
||||||
z := result.(*model.Zone)
|
z := result.(*model.Zone)
|
||||||
logging.Logger().Info(fmt.Sprintf("zone: %v", z))
|
logging.Logger().Info(fmt.Sprintf("zone: %v", z))
|
||||||
|
d.sendResult("DiscoveryService.DiscoveredZone", z)
|
||||||
if nil != dz.DiscoveryHost {
|
if nil != dz.DiscoveryHost {
|
||||||
cr, _ := cidr.NewCIDRRanger(z.Network)
|
cr, _ := cidr.NewCIDRRanger(z.Network)
|
||||||
dh := &model.DiscoveryHost{
|
dh := &model.DiscoveryHost{
|
||||||
|
@ -102,6 +103,7 @@ func (d *discovery) discoverHost(zone *model.Zone, dh *model.DiscoveryHost) {
|
||||||
h := result.(*model.Host)
|
h := result.(*model.Host)
|
||||||
zone.AddHost(h)
|
zone.AddHost(h)
|
||||||
logging.Logger().Info(fmt.Sprintf("host: %v", h))
|
logging.Logger().Info(fmt.Sprintf("host: %v", h))
|
||||||
|
d.sendResult("DiscoveryService.DiscoveredHost", h)
|
||||||
if nil != dh.DiscoveryPort {
|
if nil != dh.DiscoveryPort {
|
||||||
d.discoverPort(h, dh.DiscoveryPort)
|
d.discoverPort(h, dh.DiscoveryPort)
|
||||||
}
|
}
|
||||||
|
@ -117,6 +119,7 @@ func (d *discovery) discoverPort(host *model.Host, dp *model.DiscoveryPort) {
|
||||||
func(result interface{}) {
|
func(result interface{}) {
|
||||||
p := result.(*model.Port)
|
p := result.(*model.Port)
|
||||||
logging.Logger().Info(fmt.Sprintf("port: %v", p))
|
logging.Logger().Info(fmt.Sprintf("port: %v", p))
|
||||||
|
d.sendResult("DiscoveryService.DiscoveredPort", p)
|
||||||
if nil != dp.DiscoveryService {
|
if nil != dp.DiscoveryService {
|
||||||
d.discoverService(p, dp.DiscoveryService)
|
d.discoverService(p, dp.DiscoveryService)
|
||||||
}
|
}
|
||||||
|
@ -131,13 +134,14 @@ func (d *discovery) discoverService(port *model.Port, ds *model.DiscoveryService
|
||||||
},
|
},
|
||||||
func(result interface{}) {
|
func(result interface{}) {
|
||||||
s := result.(*model.Service)
|
s := result.(*model.Service)
|
||||||
|
d.sendResult("DiscoveryService.DiscoveredService", s)
|
||||||
logging.Logger().Info(fmt.Sprintf("service: %s(%s)[%s:%d]", s.ServiceName, s.CryptoType, port.Host.IP, port.PortNumber))
|
logging.Logger().Info(fmt.Sprintf("service: %s(%s)[%s:%d]", s.ServiceName, s.CryptoType, port.Host.IP, port.PortNumber))
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *discovery) sendResult() {
|
func (d *discovery) sendResult(method string, args ...interface{}) {
|
||||||
|
go notify.Notifier.Notify(method, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *discovery) sendError() {
|
func (d *discovery) sendError() {
|
||||||
|
|
|
@ -52,6 +52,11 @@ func scanServiceTCP(port *model.Port, ds *model.DiscoveryService, resultChan cha
|
||||||
if nil != s {
|
if nil != s {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-stopChan:
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if nil != s {
|
if nil != s {
|
||||||
|
|
27
rpc/notify/notify.go
Normal file
27
rpc/notify/notify.go
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
package notify
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
|
||||||
|
"git.loafle.net/commons_go/rpc/notify"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NotifyInit(conn net.Conn) {
|
||||||
|
Notifier = New()
|
||||||
|
Notifier.Start(conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NotifyDestroy() {
|
||||||
|
Notifier.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
var Notifier notify.Notifier
|
||||||
|
|
||||||
|
func New() notify.Notifier {
|
||||||
|
|
||||||
|
nh := NewNotifyHandler()
|
||||||
|
|
||||||
|
n := notify.New(nh)
|
||||||
|
|
||||||
|
return n
|
||||||
|
}
|
7
rpc/notify/notify_handler.go
Normal file
7
rpc/notify/notify_handler.go
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
package notify
|
||||||
|
|
||||||
|
import "git.loafle.net/commons_go/rpc/notify"
|
||||||
|
|
||||||
|
type NotifyHandler interface {
|
||||||
|
notify.NotifyHandler
|
||||||
|
}
|
17
rpc/notify/notify_handlers.go
Normal file
17
rpc/notify/notify_handlers.go
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
package notify
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.loafle.net/commons_go/rpc/notify"
|
||||||
|
"git.loafle.net/commons_go/rpc/protocol/json"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewNotifyHandler() NotifyHandler {
|
||||||
|
nh := &NotifyHandlers{}
|
||||||
|
nh.Codec = json.NewClientCodec()
|
||||||
|
|
||||||
|
return nh
|
||||||
|
}
|
||||||
|
|
||||||
|
type NotifyHandlers struct {
|
||||||
|
notify.NotifyHandlers
|
||||||
|
}
|
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
"git.loafle.net/commons_go/logging"
|
"git.loafle.net/commons_go/logging"
|
||||||
"git.loafle.net/overflow/overflow_discovery/discovery"
|
"git.loafle.net/overflow/overflow_discovery/discovery"
|
||||||
|
"git.loafle.net/overflow/overflow_discovery/rpc/notify"
|
||||||
|
|
||||||
crs "git.loafle.net/commons_go/rpc/server"
|
crs "git.loafle.net/commons_go/rpc/server"
|
||||||
"git.loafle.net/commons_go/server"
|
"git.loafle.net/commons_go/server"
|
||||||
|
@ -43,10 +44,18 @@ func (sh *ServerHandlers) OnConnect(conn net.Conn) (net.Conn, error) {
|
||||||
if conn, err = sh.ServerHandlers.OnConnect(conn); nil != err {
|
if conn, err = sh.ServerHandlers.OnConnect(conn); nil != err {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return newConn(conn, "jsonrpc"), nil
|
nConn := newConn(conn, "jsonrpc")
|
||||||
|
|
||||||
|
notify.NotifyInit(nConn)
|
||||||
|
|
||||||
|
return nConn, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sh *ServerHandlers) Handle(conn net.Conn, stopChan <-chan struct{}, doneChan chan<- struct{}) {
|
func (sh *ServerHandlers) Handle(conn net.Conn, stopChan <-chan struct{}, doneChan chan<- struct{}) {
|
||||||
|
defer func() {
|
||||||
|
notify.NotifyDestroy()
|
||||||
|
}()
|
||||||
|
|
||||||
dConn := conn.(Conn)
|
dConn := conn.(Conn)
|
||||||
contentType := dConn.GetContentType()
|
contentType := dConn.GetContentType()
|
||||||
codec, err := sh.rpcSH.GetCodec(contentType)
|
codec, err := sh.rpcSH.GetCodec(contentType)
|
||||||
|
@ -74,6 +83,7 @@ func (sh *ServerHandlers) Handle(conn net.Conn, stopChan <-chan struct{}, doneCh
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sh *ServerHandlers) OnStop() {
|
func (sh *ServerHandlers) OnStop() {
|
||||||
|
|
||||||
discovery.DiscoveryDestroy()
|
discovery.DiscoveryDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user