ing
This commit is contained in:
parent
8d1ac30e79
commit
5826f0117a
29
config.json
29
config.json
|
@ -32,6 +32,19 @@
|
|||
}
|
||||
},
|
||||
"handlers": {
|
||||
"auth": {
|
||||
"entry": "/auth",
|
||||
"socket": {
|
||||
"MaxMessageSize": 8192,
|
||||
"WriteTimeout": 0,
|
||||
"ReadTimeout": 0,
|
||||
"PongTimeout": 60,
|
||||
"PingTimeout": 10,
|
||||
"PingPeriod": 10,
|
||||
"BinaryMessage": false
|
||||
}
|
||||
},
|
||||
|
||||
"probe": {
|
||||
"entry": "/probe",
|
||||
"socket": {
|
||||
|
@ -44,8 +57,20 @@
|
|||
"BinaryMessage": false
|
||||
}
|
||||
},
|
||||
"auth": {
|
||||
"entry": "/auth",
|
||||
"metric": {
|
||||
"entry": "/metric",
|
||||
"socket": {
|
||||
"MaxMessageSize": 8192,
|
||||
"WriteTimeout": 0,
|
||||
"ReadTimeout": 0,
|
||||
"PongTimeout": 60,
|
||||
"PingTimeout": 10,
|
||||
"PingPeriod": 10,
|
||||
"BinaryMessage": false
|
||||
}
|
||||
},
|
||||
"file": {
|
||||
"entry": "/file",
|
||||
"socket": {
|
||||
"MaxMessageSize": 8192,
|
||||
"WriteTimeout": 0,
|
||||
|
|
50
server/file_servlet.go
Normal file
50
server/file_servlet.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"git.loafle.net/commons_go/logging"
|
||||
"git.loafle.net/overflow/overflow_gateway_probe/grpc"
|
||||
ogw "git.loafle.net/overflow/overflow_gateway_websocket"
|
||||
"github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
func newFileServlet() Servlet {
|
||||
s := &fileServlet{}
|
||||
return s
|
||||
}
|
||||
|
||||
type fileServlet struct {
|
||||
}
|
||||
|
||||
func (s *fileServlet) IsCanConnect(ctx *fasthttp.RequestCtx) bool {
|
||||
var buf []byte
|
||||
if buf = ctx.Request.Header.Peek(ProbeHeader_ProbeKey); nil != buf {
|
||||
return false
|
||||
}
|
||||
probeKey := string(buf)
|
||||
|
||||
var err error
|
||||
gctx := context.Background()
|
||||
params := []string{probeKey}
|
||||
|
||||
var result string
|
||||
if result, err = grpc.Exec(gctx, "ProbeService.readByProbeKey", params); nil != err {
|
||||
logging.Logger.Warn(fmt.Sprintf("Probe: Invalid connect ProbeKey[%s] ip[%s]", probeKey, ctx.RemoteAddr().String()))
|
||||
return false
|
||||
}
|
||||
var probe Probe
|
||||
if err = json.Unmarshal([]byte(result), &probe); nil != err {
|
||||
logging.Logger.Warn(fmt.Sprintf("Probe: Cannot conver json[%s] ip[%s]", result, ctx.RemoteAddr().String()))
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *fileServlet) SessionUID(soc ogw.Socket) string {
|
||||
|
||||
return ""
|
||||
}
|
50
server/metric_servlet.go
Normal file
50
server/metric_servlet.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"git.loafle.net/commons_go/logging"
|
||||
"git.loafle.net/overflow/overflow_gateway_probe/grpc"
|
||||
ogw "git.loafle.net/overflow/overflow_gateway_websocket"
|
||||
"github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
func newMetricServlet() Servlet {
|
||||
s := &metricServlet{}
|
||||
return s
|
||||
}
|
||||
|
||||
type metricServlet struct {
|
||||
}
|
||||
|
||||
func (s *metricServlet) IsCanConnect(ctx *fasthttp.RequestCtx) bool {
|
||||
var buf []byte
|
||||
if buf = ctx.Request.Header.Peek(ProbeHeader_ProbeKey); nil != buf {
|
||||
return false
|
||||
}
|
||||
probeKey := string(buf)
|
||||
|
||||
var err error
|
||||
gctx := context.Background()
|
||||
params := []string{probeKey}
|
||||
|
||||
var result string
|
||||
if result, err = grpc.Exec(gctx, "ProbeService.readByProbeKey", params); nil != err {
|
||||
logging.Logger.Warn(fmt.Sprintf("Probe: Invalid connect ProbeKey[%s] ip[%s]", probeKey, ctx.RemoteAddr().String()))
|
||||
return false
|
||||
}
|
||||
var probe Probe
|
||||
if err = json.Unmarshal([]byte(result), &probe); nil != err {
|
||||
logging.Logger.Warn(fmt.Sprintf("Probe: Cannot conver json[%s] ip[%s]", result, ctx.RemoteAddr().String()))
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *metricServlet) SessionUID(soc ogw.Socket) string {
|
||||
|
||||
return ""
|
||||
}
|
|
@ -1,10 +1,21 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"git.loafle.net/commons_go/logging"
|
||||
"git.loafle.net/overflow/overflow_gateway_probe/grpc"
|
||||
ogw "git.loafle.net/overflow/overflow_gateway_websocket"
|
||||
"github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
const (
|
||||
ProbeHeader_ProbeKey = "overFlow-Probe-Key"
|
||||
ProbeHeader_Probe_EncryptionKey = "overFlow-Probe-EncryptionKey"
|
||||
)
|
||||
|
||||
func newProbeServlet() Servlet {
|
||||
s := &probeServlet{}
|
||||
return s
|
||||
|
@ -14,12 +25,44 @@ type probeServlet struct {
|
|||
}
|
||||
|
||||
func (s *probeServlet) IsCanConnect(ctx *fasthttp.RequestCtx) bool {
|
||||
var buf []byte
|
||||
if buf = ctx.Request.Header.Peek(ProbeHeader_ProbeKey); nil != buf {
|
||||
return false
|
||||
}
|
||||
probeKey := string(buf)
|
||||
|
||||
return false
|
||||
var err error
|
||||
gctx := context.Background()
|
||||
params := []string{probeKey}
|
||||
|
||||
var result string
|
||||
if result, err = grpc.Exec(gctx, "ProbeService.readByProbeKey", params); nil != err {
|
||||
logging.Logger.Warn(fmt.Sprintf("Probe: Invalid connect ProbeKey[%s] ip[%s]", probeKey, ctx.RemoteAddr().String()))
|
||||
return false
|
||||
}
|
||||
var probe Probe
|
||||
if err = json.Unmarshal([]byte(result), &probe); nil != err {
|
||||
logging.Logger.Warn(fmt.Sprintf("Probe: Cannot conver json[%s] ip[%s]", result, ctx.RemoteAddr().String()))
|
||||
return false
|
||||
}
|
||||
|
||||
ctx.Response.Header.Set(ProbeHeader_Probe_EncryptionKey, probe.EncryptionKey)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *probeServlet) SessionUID(soc ogw.Socket) string {
|
||||
var buf []byte
|
||||
if buf = soc.Conn().Headers().Peek(ProbeHeader_ProbeKey); nil != buf {
|
||||
return string(buf)
|
||||
}
|
||||
|
||||
return ""
|
||||
|
||||
}
|
||||
|
||||
type Probe struct {
|
||||
ID uint64 `json:"id"`
|
||||
Description string `json:"description"`
|
||||
ProbeKey string `json:"probeKey"`
|
||||
EncryptionKey string `json:"encryptionKey"`
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ var ofSigningKey []byte
|
|||
func newServerHandler(ctx context.Context) ogw.ServerHandler {
|
||||
h := &serverHandlers{
|
||||
ctx: ctx,
|
||||
servlets: make(map[string]Servlet, 2),
|
||||
servlets: make(map[string]Servlet, 4),
|
||||
}
|
||||
h.HandshakeTimeout = conf.Config.Websocket.HandshakeTimeout * time.Second
|
||||
h.ReadBufferSize = conf.Config.Websocket.ReadBufferSize
|
||||
|
@ -25,6 +25,8 @@ func newServerHandler(ctx context.Context) ogw.ServerHandler {
|
|||
|
||||
h.servlets["/auth"] = newAuthServlet()
|
||||
h.servlets["/probe"] = newProbeServlet()
|
||||
h.servlets["/metric"] = newMetricServlet()
|
||||
h.servlets["/file"] = newFileServlet()
|
||||
|
||||
return h
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user