Skip to content

Commit

Permalink
feat: 通讯层加密
Browse files Browse the repository at this point in the history
  • Loading branch information
showurl committed Jul 7, 2023
1 parent b1e0a0b commit 3369ce1
Show file tree
Hide file tree
Showing 48 changed files with 2,589 additions and 3,324 deletions.
23 changes: 21 additions & 2 deletions app/gateway/client/gatewayservice/gatewayService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions app/gateway/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import (
"flag"
"github.com/cherish-chat/xxim-server/app/gateway"
)

var configFile = flag.String("f", "etc/gateway.yaml", "the config file")

func main() {
flag.Parse()

gateway.Run(*configFile)
}
11 changes: 3 additions & 8 deletions app/gateway/gateway.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main
package gateway

import (
"flag"
"github.com/cherish-chat/xxim-server/app/gateway/internal/server"
"github.com/zeromicro/go-zero/core/logx"

Expand All @@ -17,13 +16,9 @@ import (
"google.golang.org/grpc/reflection"
)

var configFile = flag.String("f", "etc/gateway.yaml", "the config file")

func main() {
flag.Parse()

func Run(configFile string) {
var c config.Config
conf.MustLoad(*configFile, &c)
conf.MustLoad(configFile, &c)
ctx := svc.NewServiceContext(c)

s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package connectionhandler

import (
"context"
gatewayservicelogic "github.com/cherish-chat/xxim-server/app/gateway/internal/logic/gatewayservice"
"github.com/cherish-chat/xxim-server/app/gateway/internal/svc"
"github.com/cherish-chat/xxim-server/app/gateway/internal/types"
"github.com/cherish-chat/xxim-server/common/i18n"
"github.com/cherish-chat/xxim-server/common/pb"
"github.com/cherish-chat/xxim-server/common/utils"
"google.golang.org/protobuf/proto"
)

type ConnectionHandler struct {
svcCtx *svc.ServiceContext
}

func NewConnectionHandler(svcCtx *svc.ServiceContext) *ConnectionHandler {
return &ConnectionHandler{svcCtx: svcCtx}
}

// VerifyConnection 验证连接
func (h *ConnectionHandler) VerifyConnection(ctx context.Context, connection *gatewayservicelogic.Connection, apiRequest *pb.GatewayApiRequest) (pb.ResponseCode, []byte, error) {
request := &pb.VerifyConnectionReq{}
response := &pb.VerifyConnectionResp{}
err := proto.Unmarshal(apiRequest.Body, request)
if err != nil {
responseHeader := i18n.NewInvalidDataError(err.Error())
response.SetHeader(responseHeader)
return pb.ResponseCode_INVALID_DATA, types.MarshalWriteData(&pb.GatewayApiResponse{
RequestId: apiRequest.RequestId,
Path: apiRequest.Path,
Header: i18n.NewInvalidDataError(err.Error()),
Body: utils.Proto.Marshal(response),
}), err
}
response, err = gatewayservicelogic.NewVerifyConnectionLogic(ctx, h.svcCtx).VerifyConnection_(connection, request)
if err != nil {
responseHeader := i18n.NewServerError(h.svcCtx.Config.Mode, err)
response.SetHeader(responseHeader)
return pb.ResponseCode_SERVER_ERROR, types.MarshalWriteData(&pb.GatewayApiResponse{
Header: responseHeader,
Body: utils.Proto.Marshal(response),
RequestId: apiRequest.RequestId,
Path: apiRequest.Path,
}), err
}
gatewayservicelogic.ConnectionLogic.OnVerified(connection)
responseHeader := i18n.NewOkHeader()
return pb.ResponseCode_SUCCESS, types.MarshalWriteData(&pb.GatewayApiResponse{
Header: responseHeader,
RequestId: apiRequest.RequestId,
Path: apiRequest.Path,
Body: utils.Proto.Marshal(response),
}), nil
}

func (h *ConnectionHandler) AuthenticationConnection(ctx context.Context, connection *gatewayservicelogic.Connection, apiRequest *pb.GatewayApiRequest) (pb.ResponseCode, []byte, error) {
request := &pb.AuthenticationConnectionReq{}
response := &pb.AuthenticationConnectionResp{}
err := proto.Unmarshal(apiRequest.Body, request)
if err != nil {
responseHeader := i18n.NewInvalidDataError(err.Error())
response.SetHeader(responseHeader)
return pb.ResponseCode_INVALID_DATA, types.MarshalWriteData(&pb.GatewayApiResponse{
RequestId: apiRequest.RequestId,
Path: apiRequest.Path,
Header: i18n.NewInvalidDataError(err.Error()),
Body: utils.Proto.Marshal(response),
}), err
}
response, err = gatewayservicelogic.NewAuthenticationConnectionLogic(ctx, h.svcCtx).AuthenticationConnection_(connection, request)
if err != nil {
responseHeader := i18n.NewServerError(h.svcCtx.Config.Mode, err)
response.SetHeader(responseHeader)
return pb.ResponseCode_SERVER_ERROR, types.MarshalWriteData(&pb.GatewayApiResponse{
Header: responseHeader,
Body: utils.Proto.Marshal(response),
RequestId: apiRequest.RequestId,
Path: apiRequest.Path,
}), err
}
responseHeader := i18n.NewOkHeader()
return pb.ResponseCode_SUCCESS, types.MarshalWriteData(&pb.GatewayApiResponse{
Header: responseHeader,
RequestId: apiRequest.RequestId,
Path: apiRequest.Path,
Body: utils.Proto.Marshal(response),
}), nil
}
38 changes: 0 additions & 38 deletions app/gateway/internal/handler/keepalivehandler.go

This file was deleted.

Loading

0 comments on commit 3369ce1

Please sign in to comment.