ing
This commit is contained in:
parent
6bcb527545
commit
ca25ad0f57
86
auth/auth.go
86
auth/auth.go
|
@ -11,16 +11,22 @@ import (
|
||||||
ooccn "git.loafle.net/overflow/overflow_commons_go/config/noauthprobe"
|
ooccn "git.loafle.net/overflow/overflow_commons_go/config/noauthprobe"
|
||||||
oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client"
|
oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client"
|
||||||
"git.loafle.net/overflow/overflow_probes/auth/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"
|
"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
|
EndableStart(doneChan chan<- error) error
|
||||||
Stop()
|
Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
type auth struct {
|
type authManagers struct {
|
||||||
doneChan chan<- error
|
doneChan chan<- error
|
||||||
|
|
||||||
cClient oogwc.Client
|
cClient oogwc.Client
|
||||||
|
@ -34,38 +40,32 @@ type auth struct {
|
||||||
stopWg sync.WaitGroup
|
stopWg sync.WaitGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() Auther {
|
func (am *authManagers) EndableStart(doneChan chan<- error) error {
|
||||||
a := &auth{}
|
if nil != am.stopChan {
|
||||||
|
|
||||||
return a
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *auth) EndableStart(doneChan chan<- error) error {
|
|
||||||
if nil != a.stopChan {
|
|
||||||
logging.Logger().Panic("Auth: auth is already running. Stop it before starting it again")
|
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()
|
conf := cc.New()
|
||||||
if cc.Exists(a.configPath) {
|
if cc.Exists(am.configPath) {
|
||||||
if err := conf.Load(&a.config, a.configPath); nil != err {
|
if err := conf.Load(&am.config, am.configPath); nil != err {
|
||||||
return fmt.Errorf("Auth: Loading of NoAuth config file[%s] failed error[%v]", a.configPath, err)
|
return fmt.Errorf("Auth: Loading of NoAuth config file[%s] failed error[%v]", am.configPath, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if nil != a.config.DenyDate {
|
if nil != am.config.DenyDate {
|
||||||
return fmt.Errorf("Cannot start because this probe have been denied from overFlow at %s", a.config.DenyDate.String())
|
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()
|
rpcRegistry := crr.NewRPCRegistry()
|
||||||
|
|
||||||
napService := &oopar.NoAuthProbeService{
|
napService := &oopas.NoAuthProbeService{
|
||||||
DoneChan: a.serviceDoneChan,
|
DoneChan: am.serviceDoneChan,
|
||||||
ConfigPath: a.configPath,
|
ConfigPath: am.configPath,
|
||||||
Config: a.config,
|
Config: am.config,
|
||||||
}
|
}
|
||||||
rpcRegistry.RegisterService(napService, "")
|
rpcRegistry.RegisterService(napService, "")
|
||||||
|
|
||||||
|
@ -74,52 +74,52 @@ func (a *auth) EndableStart(doneChan chan<- error) error {
|
||||||
if nil == sb {
|
if nil == sb {
|
||||||
return fmt.Errorf("Auth: Cannot create SocketBuilder")
|
return fmt.Errorf("Auth: Cannot create SocketBuilder")
|
||||||
}
|
}
|
||||||
a.cClient = client.NewClient(ch, sb)
|
am.cClient = client.NewClient(ch, sb)
|
||||||
|
|
||||||
a.doneChan = doneChan
|
am.doneChan = doneChan
|
||||||
a.stopChan = make(chan struct{})
|
am.stopChan = make(chan struct{})
|
||||||
|
|
||||||
a.stopWg.Add(1)
|
am.stopWg.Add(1)
|
||||||
go a.handleAuth()
|
go am.handleAuth()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *auth) Stop() {
|
func (am *authManagers) Stop() {
|
||||||
a.destroy(nil)
|
am.destroy(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *auth) destroy(err error) {
|
func (am *authManagers) destroy(err error) {
|
||||||
if a.stopChan == nil {
|
if am.stopChan == nil {
|
||||||
logging.Logger().Warn("Auth: auth must be started before stopping it")
|
logging.Logger().Warn("Auth: auth must be started before stopping it")
|
||||||
}
|
}
|
||||||
close(a.stopChan)
|
close(am.stopChan)
|
||||||
a.stopWg.Wait()
|
am.stopWg.Wait()
|
||||||
a.stopChan = nil
|
am.stopChan = nil
|
||||||
|
|
||||||
a.cClient.Close()
|
am.cClient.Close()
|
||||||
close(a.serviceDoneChan)
|
close(am.serviceDoneChan)
|
||||||
|
|
||||||
logging.Logger().Info(fmt.Sprintf("Auth: stopped"))
|
logging.Logger().Info(fmt.Sprintf("Auth: stopped"))
|
||||||
a.doneChan <- err
|
am.doneChan <- err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *auth) handleAuth() {
|
func (am *authManagers) handleAuth() {
|
||||||
var err error
|
var err error
|
||||||
defer func() {
|
defer func() {
|
||||||
a.stopWg.Done()
|
am.stopWg.Done()
|
||||||
a.destroy(err)
|
am.destroy(err)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err = a.cClient.Connect(); nil != err {
|
if err = am.cClient.Connect(); nil != err {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case err = <-a.serviceDoneChan:
|
case err = <-am.serviceDoneChan:
|
||||||
return
|
return
|
||||||
case <-a.stopChan:
|
case <-am.stopChan:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,11 @@ import (
|
||||||
"git.loafle.net/commons_go/logging"
|
"git.loafle.net/commons_go/logging"
|
||||||
cwfc "git.loafle.net/commons_go/websocket_fasthttp/client"
|
cwfc "git.loafle.net/commons_go/websocket_fasthttp/client"
|
||||||
oocmn "git.loafle.net/overflow/overflow_commons_go/modules/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"
|
||||||
oopcc "git.loafle.net/overflow/overflow_probes/central/client"
|
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{
|
sb := &SocketBuilders{
|
||||||
napService: napService,
|
napService: napService,
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ func NewSocketBuilder(napService *oopar.NoAuthProbeService) cwfc.SocketBuilder {
|
||||||
type SocketBuilders struct {
|
type SocketBuilders struct {
|
||||||
*oopcc.SocketBuilders
|
*oopcc.SocketBuilders
|
||||||
|
|
||||||
napService *oopar.NoAuthProbeService
|
napService *oopas.NoAuthProbeService
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sb *SocketBuilders) SocketHandler() cwfc.SocketHandler {
|
func (sb *SocketBuilders) SocketHandler() cwfc.SocketHandler {
|
||||||
|
|
|
@ -8,13 +8,13 @@ import (
|
||||||
cwfc "git.loafle.net/commons_go/websocket_fasthttp/client"
|
cwfc "git.loafle.net/commons_go/websocket_fasthttp/client"
|
||||||
ooccn "git.loafle.net/overflow/overflow_commons_go/config/noauthprobe"
|
ooccn "git.loafle.net/overflow/overflow_commons_go/config/noauthprobe"
|
||||||
oocmn "git.loafle.net/overflow/overflow_commons_go/modules/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 {
|
type SocketHandlers struct {
|
||||||
cwfc.SocketHandlers
|
cwfc.SocketHandlers
|
||||||
|
|
||||||
napService *oopar.NoAuthProbeService
|
napService *oopas.NoAuthProbeService
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sh *SocketHandlers) OnConnect(socketContext cwfc.SocketContext, res *http.Response) {
|
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{
|
return &SocketHandlers{
|
||||||
napService: napService,
|
napService: napService,
|
||||||
}
|
}
|
||||||
|
|
19
auth/rpc.go
19
auth/rpc.go
|
@ -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
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
package rpc
|
|
|
@ -1,4 +1,4 @@
|
||||||
package client
|
package data
|
||||||
|
|
||||||
import (
|
import (
|
||||||
cwfc "git.loafle.net/commons_go/websocket_fasthttp/client"
|
cwfc "git.loafle.net/commons_go/websocket_fasthttp/client"
|
|
@ -1,4 +1,4 @@
|
||||||
package client
|
package data
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
|
@ -1,4 +1,4 @@
|
||||||
package client
|
package data
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
|
@ -1,4 +1,4 @@
|
||||||
package client
|
package data
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
11
client/file/client.go
Normal file
11
client/file/client.go
Normal file
|
@ -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)
|
||||||
|
}
|
31
client/file/client_handlers.go
Normal file
31
client/file/client_handlers.go
Normal file
|
@ -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"))
|
||||||
|
}
|
51
client/file/socket_builders.go
Normal file
51
client/file/socket_builders.go
Normal file
|
@ -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")
|
||||||
|
}
|
||||||
|
}
|
41
client/file/socket_handlers.go
Normal file
41
client/file/socket_handlers.go
Normal file
|
@ -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,
|
||||||
|
}
|
||||||
|
}
|
11
client/probe/client.go
Normal file
11
client/probe/client.go
Normal file
|
@ -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)
|
||||||
|
}
|
31
client/probe/client_handlers.go
Normal file
31
client/probe/client_handlers.go
Normal file
|
@ -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"))
|
||||||
|
}
|
51
client/probe/socket_builders.go
Normal file
51
client/probe/socket_builders.go
Normal file
|
@ -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")
|
||||||
|
}
|
||||||
|
}
|
41
client/probe/socket_handlers.go
Normal file
41
client/probe/socket_handlers.go
Normal file
|
@ -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,
|
||||||
|
}
|
||||||
|
}
|
|
@ -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
|
|
||||||
}
|
|
|
@ -1 +1,90 @@
|
||||||
package probe
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
1
service/CrawlerService.go
Normal file
1
service/CrawlerService.go
Normal file
|
@ -0,0 +1 @@
|
||||||
|
package service
|
2
service/ProbeService.go
Normal file
2
service/ProbeService.go
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
package service
|
||||||
|
|
4
service/SensorService.go
Normal file
4
service/SensorService.go
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
package service
|
||||||
|
|
||||||
|
type SensorService struct {
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user