diff --git a/auth/auth.go b/auth/auth.go index 07c35f5..131c363 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -11,16 +11,22 @@ import ( ooccn "git.loafle.net/overflow/overflow_commons_go/config/noauthprobe" oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client" "git.loafle.net/overflow/overflow_probes/auth/client" - oopar "git.loafle.net/overflow/overflow_probes/auth/rpc" + oopas "git.loafle.net/overflow/overflow_probes/auth/service" "git.loafle.net/overflow/overflow_probes/config" ) -type Auther interface { +func New() AuthManager { + am := &authManagers{} + + return am +} + +type AuthManager interface { EndableStart(doneChan chan<- error) error Stop() } -type auth struct { +type authManagers struct { doneChan chan<- error cClient oogwc.Client @@ -34,38 +40,32 @@ type auth struct { stopWg sync.WaitGroup } -func New() Auther { - a := &auth{} - - return a -} - -func (a *auth) EndableStart(doneChan chan<- error) error { - if nil != a.stopChan { +func (am *authManagers) EndableStart(doneChan chan<- error) error { + if nil != am.stopChan { logging.Logger().Panic("Auth: auth is already running. Stop it before starting it again") } - a.configPath = path.Join(*config.ConfigDir, ooccn.ConfigFileName) + am.configPath = path.Join(*config.ConfigDir, ooccn.ConfigFileName) conf := cc.New() - if cc.Exists(a.configPath) { - if err := conf.Load(&a.config, a.configPath); nil != err { - return fmt.Errorf("Auth: Loading of NoAuth config file[%s] failed error[%v]", a.configPath, err) + if cc.Exists(am.configPath) { + if err := conf.Load(&am.config, am.configPath); nil != err { + return fmt.Errorf("Auth: Loading of NoAuth config file[%s] failed error[%v]", am.configPath, err) } } - if nil != a.config.DenyDate { - return fmt.Errorf("Cannot start because this probe have been denied from overFlow at %s", a.config.DenyDate.String()) + if nil != am.config.DenyDate { + return fmt.Errorf("Cannot start because this probe have been denied from overFlow at %s", am.config.DenyDate.String()) } - a.serviceDoneChan = make(chan error, 1) + am.serviceDoneChan = make(chan error, 1) rpcRegistry := crr.NewRPCRegistry() - napService := &oopar.NoAuthProbeService{ - DoneChan: a.serviceDoneChan, - ConfigPath: a.configPath, - Config: a.config, + napService := &oopas.NoAuthProbeService{ + DoneChan: am.serviceDoneChan, + ConfigPath: am.configPath, + Config: am.config, } rpcRegistry.RegisterService(napService, "") @@ -74,52 +74,52 @@ func (a *auth) EndableStart(doneChan chan<- error) error { if nil == sb { return fmt.Errorf("Auth: Cannot create SocketBuilder") } - a.cClient = client.NewClient(ch, sb) + am.cClient = client.NewClient(ch, sb) - a.doneChan = doneChan - a.stopChan = make(chan struct{}) + am.doneChan = doneChan + am.stopChan = make(chan struct{}) - a.stopWg.Add(1) - go a.handleAuth() + am.stopWg.Add(1) + go am.handleAuth() return nil } -func (a *auth) Stop() { - a.destroy(nil) +func (am *authManagers) Stop() { + am.destroy(nil) } -func (a *auth) destroy(err error) { - if a.stopChan == nil { +func (am *authManagers) destroy(err error) { + if am.stopChan == nil { logging.Logger().Warn("Auth: auth must be started before stopping it") } - close(a.stopChan) - a.stopWg.Wait() - a.stopChan = nil + close(am.stopChan) + am.stopWg.Wait() + am.stopChan = nil - a.cClient.Close() - close(a.serviceDoneChan) + am.cClient.Close() + close(am.serviceDoneChan) logging.Logger().Info(fmt.Sprintf("Auth: stopped")) - a.doneChan <- err + am.doneChan <- err } -func (a *auth) handleAuth() { +func (am *authManagers) handleAuth() { var err error defer func() { - a.stopWg.Done() - a.destroy(err) + am.stopWg.Done() + am.destroy(err) }() - if err = a.cClient.Connect(); nil != err { + if err = am.cClient.Connect(); nil != err { return } for { select { - case err = <-a.serviceDoneChan: + case err = <-am.serviceDoneChan: return - case <-a.stopChan: + case <-am.stopChan: return } } diff --git a/auth/client/socket_builders.go b/auth/client/socket_builders.go index 28beb84..a56b5f0 100644 --- a/auth/client/socket_builders.go +++ b/auth/client/socket_builders.go @@ -6,11 +6,11 @@ import ( "git.loafle.net/commons_go/logging" cwfc "git.loafle.net/commons_go/websocket_fasthttp/client" oocmn "git.loafle.net/overflow/overflow_commons_go/modules/noauthprobe" - oopar "git.loafle.net/overflow/overflow_probes/auth/rpc" + oopas "git.loafle.net/overflow/overflow_probes/auth/service" oopcc "git.loafle.net/overflow/overflow_probes/central/client" ) -func NewSocketBuilder(napService *oopar.NoAuthProbeService) cwfc.SocketBuilder { +func NewSocketBuilder(napService *oopas.NoAuthProbeService) cwfc.SocketBuilder { sb := &SocketBuilders{ napService: napService, } @@ -25,7 +25,7 @@ func NewSocketBuilder(napService *oopar.NoAuthProbeService) cwfc.SocketBuilder { type SocketBuilders struct { *oopcc.SocketBuilders - napService *oopar.NoAuthProbeService + napService *oopas.NoAuthProbeService } func (sb *SocketBuilders) SocketHandler() cwfc.SocketHandler { diff --git a/auth/client/socket_handlers.go b/auth/client/socket_handlers.go index 060a73f..01020f0 100644 --- a/auth/client/socket_handlers.go +++ b/auth/client/socket_handlers.go @@ -8,13 +8,13 @@ import ( cwfc "git.loafle.net/commons_go/websocket_fasthttp/client" ooccn "git.loafle.net/overflow/overflow_commons_go/config/noauthprobe" oocmn "git.loafle.net/overflow/overflow_commons_go/modules/noauthprobe" - oopar "git.loafle.net/overflow/overflow_probes/auth/rpc" + oopas "git.loafle.net/overflow/overflow_probes/auth/service" ) type SocketHandlers struct { cwfc.SocketHandlers - napService *oopar.NoAuthProbeService + napService *oopas.NoAuthProbeService } func (sh *SocketHandlers) OnConnect(socketContext cwfc.SocketContext, res *http.Response) { @@ -34,7 +34,7 @@ func (sh *SocketHandlers) OnDisconnect(soc cwfc.Socket) { } -func newSocketHandler(napService *oopar.NoAuthProbeService) cwfc.SocketHandler { +func newSocketHandler(napService *oopas.NoAuthProbeService) cwfc.SocketHandler { return &SocketHandlers{ napService: napService, } diff --git a/auth/rpc.go b/auth/rpc.go deleted file mode 100644 index e0a83a2..0000000 --- a/auth/rpc.go +++ /dev/null @@ -1,19 +0,0 @@ -package auth - -import ( - crr "git.loafle.net/commons_go/rpc/registry" - oopar "git.loafle.net/overflow/overflow_probes/auth/rpc" -) - -func initRPCRegistry(a *auth) crr.RPCInvoker { - rpcRegistry := crr.NewRPCRegistry() - - napService := &oopar.NoAuthProbeService{ - DoneChan: a.serviceDoneChan, - ConfigPath: a.configPath, - Config: a.config, - } - rpcRegistry.RegisterService(napService, "") - - return rpcRegistry -} diff --git a/auth/rpc/rpc.go b/auth/rpc/rpc.go deleted file mode 100644 index 9ab1e3e..0000000 --- a/auth/rpc/rpc.go +++ /dev/null @@ -1 +0,0 @@ -package rpc diff --git a/auth/rpc/NoAuthProbeService.go b/auth/service/NoAuthProbeService.go similarity index 100% rename from auth/rpc/NoAuthProbeService.go rename to auth/service/NoAuthProbeService.go diff --git a/probe/client/client.go b/client/data/client.go similarity index 94% rename from probe/client/client.go rename to client/data/client.go index 076a324..481baae 100644 --- a/probe/client/client.go +++ b/client/data/client.go @@ -1,4 +1,4 @@ -package client +package data import ( cwfc "git.loafle.net/commons_go/websocket_fasthttp/client" diff --git a/probe/client/client_handlers.go b/client/data/client_handlers.go similarity index 97% rename from probe/client/client_handlers.go rename to client/data/client_handlers.go index 8f47846..2da6f47 100644 --- a/probe/client/client_handlers.go +++ b/client/data/client_handlers.go @@ -1,4 +1,4 @@ -package client +package data import ( "fmt" diff --git a/probe/client/socket_builders.go b/client/data/socket_builders.go similarity index 98% rename from probe/client/socket_builders.go rename to client/data/socket_builders.go index 28beb84..005e906 100644 --- a/probe/client/socket_builders.go +++ b/client/data/socket_builders.go @@ -1,4 +1,4 @@ -package client +package data import ( "net/http" diff --git a/probe/client/socket_handlers.go b/client/data/socket_handlers.go similarity index 98% rename from probe/client/socket_handlers.go rename to client/data/socket_handlers.go index 060a73f..bfb3378 100644 --- a/probe/client/socket_handlers.go +++ b/client/data/socket_handlers.go @@ -1,4 +1,4 @@ -package client +package data import ( "fmt" diff --git a/client/file/client.go b/client/file/client.go new file mode 100644 index 0000000..4bb9040 --- /dev/null +++ b/client/file/client.go @@ -0,0 +1,11 @@ +package file + +import ( + cwfc "git.loafle.net/commons_go/websocket_fasthttp/client" + oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client" +) + +func NewClient(ch oogwc.ClientHandler, sb cwfc.SocketBuilder) oogwc.Client { + + return oogwc.New(ch, sb) +} diff --git a/client/file/client_handlers.go b/client/file/client_handlers.go new file mode 100644 index 0000000..62696b4 --- /dev/null +++ b/client/file/client_handlers.go @@ -0,0 +1,31 @@ +package file + +import ( + "fmt" + + "git.loafle.net/commons_go/logging" + crc "git.loafle.net/commons_go/rpc/client" + crr "git.loafle.net/commons_go/rpc/registry" + oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client" +) + +func NewClientHandler(rpcInvoker crr.RPCInvoker) oogwc.ClientHandler { + ch := &ClientHandlers{} + ch.ClientHandler = oogwc.NewClientHandler(rpcInvoker) + + return ch +} + +type ClientHandlers struct { + oogwc.ClientHandler +} + +func (ch *ClientHandlers) Init(clientCTX crc.ClientContext) error { + logging.Logger().Info(fmt.Sprintf("Probe: client has been initialized")) + + return nil +} + +func (ch *ClientHandlers) Destroy(clientCTX crc.ClientContext) { + logging.Logger().Info(fmt.Sprintf("Probe: client has been destroyed")) +} diff --git a/client/file/socket_builders.go b/client/file/socket_builders.go new file mode 100644 index 0000000..5d22d82 --- /dev/null +++ b/client/file/socket_builders.go @@ -0,0 +1,51 @@ +package file + +import ( + "net/http" + + "git.loafle.net/commons_go/logging" + cwfc "git.loafle.net/commons_go/websocket_fasthttp/client" + oocmn "git.loafle.net/overflow/overflow_commons_go/modules/noauthprobe" + oopar "git.loafle.net/overflow/overflow_probes/auth/rpc" + oopcc "git.loafle.net/overflow/overflow_probes/central/client" +) + +func NewSocketBuilder(napService *oopar.NoAuthProbeService) cwfc.SocketBuilder { + sb := &SocketBuilders{ + napService: napService, + } + sb.SocketBuilders = oopcc.NewSocketBuilder(oocmn.HTTPEntry_NoAuthProbe) + if nil == sb.SocketBuilders { + return nil + } + + return sb +} + +type SocketBuilders struct { + *oopcc.SocketBuilders + + napService *oopar.NoAuthProbeService +} + +func (sb *SocketBuilders) SocketHandler() cwfc.SocketHandler { + return newSocketHandler(sb.napService) +} + +func (sb *SocketBuilders) GetRequestHeader() http.Header { + h := sb.napService.GetRequestHeader() + header := http.Header{} + for k, v := range h { + header[k] = v + } + + return header +} + +func (sb *SocketBuilders) Validate() { + sb.SocketBuilders.Validate() + + if nil == sb.napService { + logging.Logger().Panic("Auth: NoAuthProbeService must be specified") + } +} diff --git a/client/file/socket_handlers.go b/client/file/socket_handlers.go new file mode 100644 index 0000000..cc2dcfb --- /dev/null +++ b/client/file/socket_handlers.go @@ -0,0 +1,41 @@ +package file + +import ( + "fmt" + "net/http" + + "git.loafle.net/commons_go/logging" + cwfc "git.loafle.net/commons_go/websocket_fasthttp/client" + ooccn "git.loafle.net/overflow/overflow_commons_go/config/noauthprobe" + oocmn "git.loafle.net/overflow/overflow_commons_go/modules/noauthprobe" + oopar "git.loafle.net/overflow/overflow_probes/auth/rpc" +) + +type SocketHandlers struct { + cwfc.SocketHandlers + + napService *oopar.NoAuthProbeService +} + +func (sh *SocketHandlers) OnConnect(socketContext cwfc.SocketContext, res *http.Response) { + logging.Logger().Info(fmt.Sprintf("Auth: client has been connected res[%v]", res)) + + switch sh.napService.Config.State() { + case ooccn.NoAuthProbeStateTypeNotRegisterd: + tempProbeKey := res.Header.Get(oocmn.HTTPResponseHeaderKey_NoAuthProbe_SetTempProbeKey) + sh.napService.SetTempProbeKey(tempProbeKey) + case ooccn.NoAuthProbeStateTypeRegisterd: + } + +} + +func (sh *SocketHandlers) OnDisconnect(soc cwfc.Socket) { + logging.Logger().Info(fmt.Sprintf("Auth: client has been disconnected soc[%v]", soc)) + +} + +func newSocketHandler(napService *oopar.NoAuthProbeService) cwfc.SocketHandler { + return &SocketHandlers{ + napService: napService, + } +} diff --git a/client/probe/client.go b/client/probe/client.go new file mode 100644 index 0000000..9a23e1e --- /dev/null +++ b/client/probe/client.go @@ -0,0 +1,11 @@ +package probe + +import ( + cwfc "git.loafle.net/commons_go/websocket_fasthttp/client" + oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client" +) + +func NewClient(ch oogwc.ClientHandler, sb cwfc.SocketBuilder) oogwc.Client { + + return oogwc.New(ch, sb) +} diff --git a/client/probe/client_handlers.go b/client/probe/client_handlers.go new file mode 100644 index 0000000..e3f5b4b --- /dev/null +++ b/client/probe/client_handlers.go @@ -0,0 +1,31 @@ +package probe + +import ( + "fmt" + + "git.loafle.net/commons_go/logging" + crc "git.loafle.net/commons_go/rpc/client" + crr "git.loafle.net/commons_go/rpc/registry" + oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client" +) + +func NewClientHandler(rpcInvoker crr.RPCInvoker) oogwc.ClientHandler { + ch := &ClientHandlers{} + ch.ClientHandler = oogwc.NewClientHandler(rpcInvoker) + + return ch +} + +type ClientHandlers struct { + oogwc.ClientHandler +} + +func (ch *ClientHandlers) Init(clientCTX crc.ClientContext) error { + logging.Logger().Info(fmt.Sprintf("Probe: client has been initialized")) + + return nil +} + +func (ch *ClientHandlers) Destroy(clientCTX crc.ClientContext) { + logging.Logger().Info(fmt.Sprintf("Probe: client has been destroyed")) +} diff --git a/client/probe/socket_builders.go b/client/probe/socket_builders.go new file mode 100644 index 0000000..f218adf --- /dev/null +++ b/client/probe/socket_builders.go @@ -0,0 +1,51 @@ +package probe + +import ( + "net/http" + + "git.loafle.net/commons_go/logging" + cwfc "git.loafle.net/commons_go/websocket_fasthttp/client" + oocmn "git.loafle.net/overflow/overflow_commons_go/modules/noauthprobe" + oopar "git.loafle.net/overflow/overflow_probes/auth/rpc" + oopcc "git.loafle.net/overflow/overflow_probes/central/client" +) + +func NewSocketBuilder(napService *oopar.NoAuthProbeService) cwfc.SocketBuilder { + sb := &SocketBuilders{ + napService: napService, + } + sb.SocketBuilders = oopcc.NewSocketBuilder(oocmn.HTTPEntry_NoAuthProbe) + if nil == sb.SocketBuilders { + return nil + } + + return sb +} + +type SocketBuilders struct { + *oopcc.SocketBuilders + + napService *oopar.NoAuthProbeService +} + +func (sb *SocketBuilders) SocketHandler() cwfc.SocketHandler { + return newSocketHandler(sb.napService) +} + +func (sb *SocketBuilders) GetRequestHeader() http.Header { + h := sb.napService.GetRequestHeader() + header := http.Header{} + for k, v := range h { + header[k] = v + } + + return header +} + +func (sb *SocketBuilders) Validate() { + sb.SocketBuilders.Validate() + + if nil == sb.napService { + logging.Logger().Panic("Auth: NoAuthProbeService must be specified") + } +} diff --git a/client/probe/socket_handlers.go b/client/probe/socket_handlers.go new file mode 100644 index 0000000..0123acd --- /dev/null +++ b/client/probe/socket_handlers.go @@ -0,0 +1,41 @@ +package probe + +import ( + "fmt" + "net/http" + + "git.loafle.net/commons_go/logging" + cwfc "git.loafle.net/commons_go/websocket_fasthttp/client" + ooccn "git.loafle.net/overflow/overflow_commons_go/config/noauthprobe" + oocmn "git.loafle.net/overflow/overflow_commons_go/modules/noauthprobe" + oopar "git.loafle.net/overflow/overflow_probes/auth/rpc" +) + +type SocketHandlers struct { + cwfc.SocketHandlers + + napService *oopar.NoAuthProbeService +} + +func (sh *SocketHandlers) OnConnect(socketContext cwfc.SocketContext, res *http.Response) { + logging.Logger().Info(fmt.Sprintf("Auth: client has been connected res[%v]", res)) + + switch sh.napService.Config.State() { + case ooccn.NoAuthProbeStateTypeNotRegisterd: + tempProbeKey := res.Header.Get(oocmn.HTTPResponseHeaderKey_NoAuthProbe_SetTempProbeKey) + sh.napService.SetTempProbeKey(tempProbeKey) + case ooccn.NoAuthProbeStateTypeRegisterd: + } + +} + +func (sh *SocketHandlers) OnDisconnect(soc cwfc.Socket) { + logging.Logger().Info(fmt.Sprintf("Auth: client has been disconnected soc[%v]", soc)) + +} + +func newSocketHandler(napService *oopar.NoAuthProbeService) cwfc.SocketHandler { + return &SocketHandlers{ + napService: napService, + } +} diff --git a/collector/collector.go b/collector/collector.go deleted file mode 100644 index 64b744c..0000000 --- a/collector/collector.go +++ /dev/null @@ -1,35 +0,0 @@ -package collector - -type Collector interface { - StartSensor() error - StopSensor() error - AddSensor() error - RemoveSensor() error - UpdateSensor() error -} - -type collector struct { -} - -func New() (Collector, error) { - - c := &collector{} - - return c, nil -} - -func (c *collector) StartSensor() error { - return nil -} -func (c *collector) StopSensor() error { - return nil -} -func (c *collector) AddSensor() error { - return nil -} -func (c *collector) RemoveSensor() error { - return nil -} -func (c *collector) UpdateSensor() error { - return nil -} diff --git a/probe/probe.go b/probe/probe.go index 2f8df31..020d8ab 100644 --- a/probe/probe.go +++ b/probe/probe.go @@ -1 +1,90 @@ package probe + +import ( + "fmt" + "sync" + + "git.loafle.net/commons_go/logging" + crr "git.loafle.net/commons_go/rpc/registry" + oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client" +) + +func New() ProbeManager { + a := &probeManagers{} + + return a +} + +type ProbeManager interface { + Start() error + Stop() +} + +type probeManagers struct { + cClient oogwc.Client + + stopChan chan struct{} + stopWg sync.WaitGroup +} + +func (pm *probeManagers) Start() error { + if nil != pm.stopChan { + logging.Logger().Panic("Probe: already running. Stop it before starting it again") + } + + rpcRegistry := crr.NewRPCRegistry() + + // napService := &oopar.NoAuthProbeService{ + // DoneChan: pm.serviceDoneChan, + // ConfigPath: pm.configPath, + // Config: pm.config, + // } + // rpcRegistry.RegisterService(napService, "") + + // ch := client.NewClientHandler(rpcRegistry) + // sb := client.NewSocketBuilder(napService) + // if nil == sb { + // return fmt.Errorf("Auth: Cannot create SocketBuilder") + // } + // pm.cClient = client.NewClient(ch, sb) + + pm.stopChan = make(chan struct{}) + + pm.stopWg.Add(1) + go pm.handleProbe() + + return nil +} + +func (pm *probeManagers) Stop() { + if pm.stopChan == nil { + logging.Logger().Warn("Auth: auth must be started before stopping it") + } + close(pm.stopChan) + pm.stopWg.Wait() + pm.stopChan = nil + + pm.cClient.Close() + + logging.Logger().Info(fmt.Sprintf("Auth: stopped")) + +} + +func (pm *probeManagers) handleProbe() { + var err error + defer func() { + pm.stopWg.Done() + pm.Stop() + }() + + if err = pm.cClient.Connect(); nil != err { + return + } + + for { + select { + case <-pm.stopChan: + return + } + } +} diff --git a/service/CrawlerService.go b/service/CrawlerService.go new file mode 100644 index 0000000..6d43c33 --- /dev/null +++ b/service/CrawlerService.go @@ -0,0 +1 @@ +package service diff --git a/service/ProbeService.go b/service/ProbeService.go new file mode 100644 index 0000000..344e88c --- /dev/null +++ b/service/ProbeService.go @@ -0,0 +1,2 @@ +package service + diff --git a/service/SensorService.go b/service/SensorService.go new file mode 100644 index 0000000..a89c6c7 --- /dev/null +++ b/service/SensorService.go @@ -0,0 +1,4 @@ +package service + +type SensorService struct { +}