diff --git a/servlet/auth-servlet.go b/servlet/auth-servlet.go index d7ce449..3ffaae6 100644 --- a/servlet/auth-servlet.go +++ b/servlet/auth-servlet.go @@ -12,6 +12,7 @@ import ( "git.loafle.net/commons/server-go" "git.loafle.net/commons/server-go/socket" occn "git.loafle.net/overflow/commons-go/config/noauthprobe" + ocmm "git.loafle.net/overflow/commons-go/model/meta" ocmn "git.loafle.net/overflow/commons-go/model/noauthprobe" og "git.loafle.net/overflow/gateway" "git.loafle.net/overflow/gateway/external/grpc" @@ -85,10 +86,10 @@ func (s *AuthServlets) Handshake(servletCtx server.ServletCtx, ctx *fasthttp.Req } grpcCTX := context.Background() r, err := grpc.Exec(grpcCTX, "NoAuthProbeService.regist", string(rJSON)) - if nil != err { return nil, fmt.Errorf("grpc call Error: %s", err.Error()) } + nap := &ocmn.NoAuthProbe{} err = json.Unmarshal([]byte(r), nap) if nil != err { @@ -96,7 +97,8 @@ func (s *AuthServlets) Handshake(servletCtx server.ServletCtx, ctx *fasthttp.Req } extHeader := &fasthttp.ResponseHeader{} - extHeader.Add(occn.HTTPResponseHeaderKey_NoAuthProbe_SetTempProbeKey, nap.TempProbeKey) + extHeader.Add(occn.HTTPResponseHeaderKey_NoAuthProbe_Method, occn.HTTPResponseHeaderValue_NoAuthProbe_Method_TempProbeKey) + extHeader.Add(occn.HTTPResponseHeaderKey_NoAuthProbe_Method_Param, nap.TempProbeKey) servletCtx.SetAttribute(og.SessionIDKey, nap.TempProbeKey) servletCtx.SetAttribute(og.SessionClientTypeKey, og.PROBE) @@ -111,12 +113,31 @@ func (s *AuthServlets) Handshake(servletCtx server.ServletCtx, ctx *fasthttp.Req tempProbeKey := string(bTempProbeKey) grpcCTX := context.Background() - _, err := grpc.Exec(grpcCTX, "NoAuthProbeService.readByTempProbeKey", tempProbeKey) - + r, err := grpc.Exec(grpcCTX, "NoAuthProbeService.readByTempProbeKey", tempProbeKey) if nil != err { return nil, fmt.Errorf("grpc result error: %s", err.Error()) } + nap := &ocmn.NoAuthProbe{} + err = json.Unmarshal([]byte(r), nap) + if nil != err { + return nil, fmt.Errorf("grpc result unMarshal Error: %s", err.Error()) + } + + extHeader := &fasthttp.ResponseHeader{} + + noAuthProbeStatusType := ocmm.ToNoAuthProbeStatusType(nap.Status.Name) + switch noAuthProbeStatusType { + case ocmm.NoAuthProbeStatusTypeACCEPT: + extHeader.Add(occn.HTTPResponseHeaderKey_NoAuthProbe_Method, occn.HTTPResponseHeaderValue_NoAuthProbe_Method_Accept) + extHeader.Add(occn.HTTPResponseHeaderKey_NoAuthProbe_Method_Param, nap.Probe.ProbeKey) + + case ocmm.NoAuthProbeStatusTypeDENY: + extHeader.Add(occn.HTTPResponseHeaderKey_NoAuthProbe_Method, occn.HTTPResponseHeaderValue_NoAuthProbe_Method_Deny) + + default: + } + servletCtx.SetAttribute(og.SessionIDKey, tempProbeKey) servletCtx.SetAttribute(og.SessionClientTypeKey, og.PROBE) servletCtx.SetAttribute(og.SessionTargetIDKey, tempProbeKey) @@ -130,10 +151,28 @@ func (s *AuthServlets) Handshake(servletCtx server.ServletCtx, ctx *fasthttp.Req func (s *AuthServlets) OnConnect(servletCtx server.ServletCtx, conn socket.Conn) { s.RPCServlets.OnConnect(servletCtx, conn) + + _tempProbeKey := servletCtx.GetAttribute(og.SessionIDKey) + if nil != _tempProbeKey { + grpcCTX := context.Background() + _, err := grpc.Exec(grpcCTX, "NoAuthProbeService.onConnect", _tempProbeKey.(string), conn.RemoteAddr().String()) + if nil != err { + logging.Logger().Errorf("onConnect error %v", err) + } + } } func (s *AuthServlets) OnDisconnect(servletCtx server.ServletCtx) { s.RPCServlets.OnDisconnect(servletCtx) + + _tempProbeKey := servletCtx.GetAttribute(og.SessionIDKey) + if nil != _tempProbeKey { + grpcCTX := context.Background() + _, err := grpc.Exec(grpcCTX, "NoAuthProbeService.onDisconnect", _tempProbeKey.(string)) + if nil != err { + logging.Logger().Errorf("onDisconnect error %v", err) + } + } } func (s *AuthServlets) handleSubscribe(serverCtx server.ServerCtx, subscribeChan <-chan *ogs.Message) { diff --git a/servlet/probe-servlet.go b/servlet/probe-servlet.go index 4714f35..3003f2f 100644 --- a/servlet/probe-servlet.go +++ b/servlet/probe-servlet.go @@ -96,7 +96,8 @@ func (s *ProbeServlets) Handshake(servletCtx server.ServletCtx, ctx *fasthttp.Re } extHeader := &fasthttp.ResponseHeader{} - extHeader.Add(occp.HTTPResponseHeaderKey_Probe_SetEncryptionKey, probe.EncryptionKey) + extHeader.Add(occp.HTTPResponseHeaderKey_Probe_Method, occp.HTTPResponseHeaderValue_Probe_Method_EncryptionKey) + extHeader.Add(occp.HTTPResponseHeaderKey_Probe_Method_Param, probe.EncryptionKey) servletCtx.SetAttribute(og.SessionIDKey, probeKey) servletCtx.SetAttribute(og.SessionClientTypeKey, og.PROBE) @@ -107,10 +108,28 @@ func (s *ProbeServlets) Handshake(servletCtx server.ServletCtx, ctx *fasthttp.Re func (s *ProbeServlets) OnConnect(servletCtx server.ServletCtx, conn socket.Conn) { s.RPCServlets.OnConnect(servletCtx, conn) + + _probeKey := servletCtx.GetAttribute(og.SessionIDKey) + if nil != _probeKey { + grpcCTX := context.Background() + _, err := grpc.Exec(grpcCTX, "ProbeService.onConnect", _probeKey.(string), conn.RemoteAddr().String()) + if nil != err { + logging.Logger().Errorf("onConnect error %v", err) + } + } } func (s *ProbeServlets) OnDisconnect(servletCtx server.ServletCtx) { s.RPCServlets.OnDisconnect(servletCtx) + + _probeKey := servletCtx.GetAttribute(og.SessionIDKey) + if nil != _probeKey { + grpcCTX := context.Background() + _, err := grpc.Exec(grpcCTX, "ProbeService.onDisconnect", _probeKey.(string)) + if nil != err { + logging.Logger().Errorf("onDisconnect error %v", err) + } + } } func (s *ProbeServlets) handleSubscribe(serverCtx server.ServerCtx, subscribeChan <-chan *ogs.Message) {