ing
This commit is contained in:
parent
c2137ebb50
commit
06b8871a9c
|
@ -1,66 +1,110 @@
|
||||||
package servlet
|
package servlet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
//crpj "git.loafle.net/commons/rpc-go/protocol/json"
|
"fmt"
|
||||||
//"git.loafle.net/commons/server-go"
|
"encoding/json"
|
||||||
//
|
"context"
|
||||||
//"log"
|
"crypto/rsa"
|
||||||
//"github.com/valyala/fasthttp"
|
"sync"
|
||||||
//"crypto/rsa"
|
|
||||||
//"sync"
|
"github.com/valyala/fasthttp"
|
||||||
|
|
||||||
|
"git.loafle.net/commons/server-go"
|
||||||
|
"git.loafle.net/commons/server-go/socket"
|
||||||
|
"git.loafle.net/overflow/gateway/external/grpc"
|
||||||
|
og "git.loafle.net/overflow/gateway"
|
||||||
|
ocpc "git.loafle.net/overflow/commons-go/probe/constants"
|
||||||
|
ocpm "git.loafle.net/overflow/commons-go/probe/model"
|
||||||
|
ogrs "git.loafle.net/overflow/gateway_rpc/servlet"
|
||||||
)
|
)
|
||||||
|
|
||||||
//type WebappServlet interface {
|
type DataServlet interface {
|
||||||
// ogrs.RPCServlet
|
ogrs.RPCServlet
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//type WebappServlets struct {
|
type DataServlets struct {
|
||||||
// ogrs.RPCServlets
|
ogrs.RPCServlets
|
||||||
//
|
|
||||||
// VerifyKey *rsa.PublicKey
|
VerifyKey *rsa.PublicKey
|
||||||
// SignKey *rsa.PrivateKey
|
SignKey *rsa.PrivateKey
|
||||||
//
|
|
||||||
// connections sync.Map
|
connections sync.Map
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//func init() {
|
func (s *DataServlets) Init(serverCtx server.ServerCtx) error {
|
||||||
// // member RSA file read
|
if err := s.RPCServlets.Init(serverCtx); nil != err {
|
||||||
//}
|
return err
|
||||||
//
|
}
|
||||||
//func (s *RPCServlet) Handshake(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx) (*fasthttp.ResponseHeader, error) {
|
|
||||||
// // probe key extraction
|
return nil
|
||||||
//
|
}
|
||||||
// return nil, nil
|
|
||||||
//}
|
func (s *DataServlets) OnStart(serverCtx server.ServerCtx) error {
|
||||||
//
|
if err := s.RPCServlets.OnStart(serverCtx); nil != err {
|
||||||
//func (s *RPCServlet) Handle(
|
return err
|
||||||
// servletCtx server.ServletCtx,
|
}
|
||||||
// stopChan <-chan struct{},
|
|
||||||
// doneChan chan<- struct{},
|
return nil
|
||||||
// readChan <-chan []byte,
|
}
|
||||||
// writeChan chan<- []byte ) {
|
|
||||||
// defer func() {
|
func (s *DataServlets) OnStop(serverCtx server.ServerCtx) {
|
||||||
// doneChan <- struct{}{}
|
|
||||||
// }()
|
s.RPCServlets.OnStop(serverCtx)
|
||||||
//
|
}
|
||||||
// sc := crpj.NewServerCodec()
|
|
||||||
//
|
func (s *DataServlets) Destroy(serverCtx server.ServerCtx) {
|
||||||
// for {
|
|
||||||
// select {
|
s.RPCServlets.Destroy(serverCtx)
|
||||||
// case msg, ok := <-readChan:
|
}
|
||||||
// if !ok {
|
|
||||||
// return
|
func (s *DataServlets) Handshake(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx) (*fasthttp.ResponseHeader, error) {
|
||||||
// }
|
// probe key extraction
|
||||||
// // grpc exec method call
|
bMethod := ctx.Request.Header.Peek(ocpc.HTTPRequestHeaderKey_Probe_Method)
|
||||||
// src, _ := sc.NewRequest(msg)
|
if nil == bMethod {
|
||||||
// m := src.Method()
|
return nil, fmt.Errorf("Unexpected probe method: %v", bMethod)
|
||||||
// p,_ := src.Params()
|
}
|
||||||
// log.Println("METHOD : %s", m)
|
|
||||||
// log.Println("Params : %s", p)
|
method := string(bMethod)
|
||||||
// case <-stopChan:
|
|
||||||
// return
|
switch method {
|
||||||
// }
|
case ocpc.HTTPRequestHeaderValue_Probe_Method_Connect:
|
||||||
//
|
default:
|
||||||
// }
|
return nil, fmt.Errorf("Unexpected noauth probe httpRequestHeaderValue: %v", method)
|
||||||
//
|
}
|
||||||
//}
|
|
||||||
|
bProbeKey := ctx.Request.Header.Peek(ocpc.HTTPRequestHeaderKey_Probe_ProbeKey)
|
||||||
|
if nil == bProbeKey {
|
||||||
|
return nil, fmt.Errorf("Unexpected probe key : %v", bProbeKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
probeKey := string(bProbeKey)
|
||||||
|
|
||||||
|
grpcCTX := context.Background()
|
||||||
|
r, err := grpc.Exec(grpcCTX, "ProbeService.readByProbeKey", probeKey)
|
||||||
|
if nil != err {
|
||||||
|
return nil, fmt.Errorf("grpc call Error: %s", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
probe := ocpm.Probe{}
|
||||||
|
err = json.Unmarshal([]byte(r), probe)
|
||||||
|
if nil != err {
|
||||||
|
return nil, fmt.Errorf("grpc result unMarshal Error: %s", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
extHeader := &fasthttp.ResponseHeader{}
|
||||||
|
extHeader.Add(ocpc.HTTPResponseHeaderKey_Probe_SetEncryptionKey, probe.EncryptionKey)
|
||||||
|
|
||||||
|
servletCtx.SetAttribute(og.SessionIDKey, probe.ProbeKey)
|
||||||
|
servletCtx.SetAttribute(og.SessionClientTypeKey, og.PROBE)
|
||||||
|
servletCtx.SetAttribute(og.SessionTargetIDKey, probe.ProbeKey)
|
||||||
|
|
||||||
|
return extHeader, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *DataServlets) OnConnect(servletCtx server.ServletCtx, conn socket.Conn) {
|
||||||
|
s.RPCServlets.OnConnect(servletCtx, conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *DataServlets) OnDisconnect(servletCtx server.ServletCtx) {
|
||||||
|
s.RPCServlets.OnDisconnect(servletCtx)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user