mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-04 16:02:26 +08:00
完善了服务器上下线,http登录负载均衡下发gate地址
This commit is contained in:
@@ -1,9 +1,5 @@
|
|||||||
http_port = 8080
|
http_port = 8080
|
||||||
|
|
||||||
[hk4e]
|
|
||||||
kcp_addr = "127.0.0.1"
|
|
||||||
kcp_port = 22103
|
|
||||||
|
|
||||||
[logger]
|
[logger]
|
||||||
level = "DEBUG"
|
level = "DEBUG"
|
||||||
mode = "BOTH"
|
mode = "BOTH"
|
||||||
|
|||||||
@@ -1,7 +1,3 @@
|
|||||||
[hk4e]
|
|
||||||
kcp_addr = "127.0.0.1"
|
|
||||||
kcp_port = 22103
|
|
||||||
|
|
||||||
[logger]
|
[logger]
|
||||||
level = "DEBUG"
|
level = "DEBUG"
|
||||||
mode = "BOTH"
|
mode = "BOTH"
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
package region
|
package region
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/base64"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"hk4e/pkg/endec"
|
"hk4e/pkg/endec"
|
||||||
"hk4e/pkg/logger"
|
"hk4e/pkg/logger"
|
||||||
"hk4e/pkg/random"
|
"hk4e/pkg/random"
|
||||||
"hk4e/protocol/proto"
|
"hk4e/protocol/proto"
|
||||||
|
|
||||||
|
pb "google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
func LoadRsaKey() (signRsaKey []byte, encRsaKeyMap map[string][]byte, pwdRsaKey []byte) {
|
func LoadRsaKey() (signRsaKey []byte, encRsaKeyMap map[string][]byte, pwdRsaKey []byte) {
|
||||||
@@ -33,20 +36,13 @@ func LoadRsaKey() (signRsaKey []byte, encRsaKeyMap map[string][]byte, pwdRsaKey
|
|||||||
return signRsaKey, encRsaKeyMap, pwdRsaKey
|
return signRsaKey, encRsaKeyMap, pwdRsaKey
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitRegion(kcpAddr string, kcpPort int32, ec2b *random.Ec2b) (*proto.QueryCurrRegionHttpRsp, *proto.QueryRegionListHttpRsp, *random.Ec2b) {
|
func NewRegionEc2b() *random.Ec2b {
|
||||||
dispatchEc2b := random.NewEc2b()
|
return random.NewEc2b()
|
||||||
if ec2b != nil {
|
}
|
||||||
dispatchEc2b = ec2b
|
|
||||||
}
|
func GetRegionList(ec2b *random.Ec2b) *proto.QueryRegionListHttpRsp {
|
||||||
dispatchEc2bData := dispatchEc2b.Bytes()
|
dispatchEc2bData := ec2b.Bytes()
|
||||||
dispatchXorKey := dispatchEc2b.XorKey()
|
dispatchXorKey := ec2b.XorKey()
|
||||||
// RegionCurr
|
|
||||||
regionCurr := new(proto.QueryCurrRegionHttpRsp)
|
|
||||||
regionCurr.RegionInfo = &proto.RegionInfo{
|
|
||||||
GateserverIp: kcpAddr,
|
|
||||||
GateserverPort: uint32(kcpPort),
|
|
||||||
SecretKey: dispatchEc2bData,
|
|
||||||
}
|
|
||||||
// RegionList
|
// RegionList
|
||||||
customConfigStr := `
|
customConfigStr := `
|
||||||
{
|
{
|
||||||
@@ -73,5 +69,37 @@ func InitRegion(kcpAddr string, kcpPort int32, ec2b *random.Ec2b) (*proto.QueryC
|
|||||||
regionList.ClientSecretKey = dispatchEc2bData
|
regionList.ClientSecretKey = dispatchEc2bData
|
||||||
regionList.ClientCustomConfigEncrypted = customConfig
|
regionList.ClientCustomConfigEncrypted = customConfig
|
||||||
regionList.EnableLoginPc = true
|
regionList.EnableLoginPc = true
|
||||||
return regionCurr, regionList, dispatchEc2b
|
return regionList
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetRegionCurr(kcpAddr string, kcpPort int32, ec2b *random.Ec2b) *proto.QueryCurrRegionHttpRsp {
|
||||||
|
dispatchEc2bData := ec2b.Bytes()
|
||||||
|
// RegionCurr
|
||||||
|
regionCurr := new(proto.QueryCurrRegionHttpRsp)
|
||||||
|
regionCurr.RegionInfo = &proto.RegionInfo{
|
||||||
|
GateserverIp: kcpAddr,
|
||||||
|
GateserverPort: uint32(kcpPort),
|
||||||
|
SecretKey: dispatchEc2bData,
|
||||||
|
}
|
||||||
|
return regionCurr
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetRegionListBase64(ec2b *random.Ec2b) string {
|
||||||
|
regionList := GetRegionList(ec2b)
|
||||||
|
regionListData, err := pb.Marshal(regionList)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("pb marshal QueryRegionListHttpRsp error: %v", err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return base64.StdEncoding.EncodeToString(regionListData)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetRegionCurrBase64(kcpAddr string, kcpPort int32, ec2b *random.Ec2b) string {
|
||||||
|
regionCurr := GetRegionCurr(kcpAddr, kcpPort, ec2b)
|
||||||
|
regionCurrData, err := pb.Marshal(regionCurr)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("pb marshal QueryCurrRegionHttpRsp error: %v", err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return base64.StdEncoding.EncodeToString(regionCurrData)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ func Run(ctx context.Context, configFile string) error {
|
|||||||
db := dao.NewDao()
|
db := dao.NewDao()
|
||||||
defer db.CloseDao()
|
defer db.CloseDao()
|
||||||
|
|
||||||
|
// natsrpc client
|
||||||
client, err := rpc.NewClient()
|
client, err := rpc.NewClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package controller
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/base64"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@@ -15,25 +14,21 @@ import (
|
|||||||
"hk4e/pkg/random"
|
"hk4e/pkg/random"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
pb "google.golang.org/protobuf/proto"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Controller struct {
|
type Controller struct {
|
||||||
dao *dao.Dao
|
dao *dao.Dao
|
||||||
discovery *rpc.DiscoveryClient
|
discovery *rpc.DiscoveryClient
|
||||||
regionListBase64 string
|
signRsaKey []byte
|
||||||
regionCurrBase64 string
|
encRsaKeyMap map[string][]byte
|
||||||
signRsaKey []byte
|
pwdRsaKey []byte
|
||||||
encRsaKeyMap map[string][]byte
|
ec2b *random.Ec2b
|
||||||
pwdRsaKey []byte
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewController(dao *dao.Dao, discovery *rpc.DiscoveryClient) (r *Controller) {
|
func NewController(dao *dao.Dao, discovery *rpc.DiscoveryClient) (r *Controller) {
|
||||||
r = new(Controller)
|
r = new(Controller)
|
||||||
r.dao = dao
|
r.dao = dao
|
||||||
r.discovery = discovery
|
r.discovery = discovery
|
||||||
r.regionListBase64 = ""
|
|
||||||
r.regionCurrBase64 = ""
|
|
||||||
r.signRsaKey, r.encRsaKeyMap, r.pwdRsaKey = region.LoadRsaKey()
|
r.signRsaKey, r.encRsaKeyMap, r.pwdRsaKey = region.LoadRsaKey()
|
||||||
rsp, err := r.discovery.GetRegionEc2B(context.TODO(), &api.NullMsg{})
|
rsp, err := r.discovery.GetRegionEc2B(context.TODO(), &api.NullMsg{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -45,19 +40,7 @@ func NewController(dao *dao.Dao, discovery *rpc.DiscoveryClient) (r *Controller)
|
|||||||
logger.Error("parse region ec2b error: %v", err)
|
logger.Error("parse region ec2b error: %v", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
regionCurr, regionList, _ := region.InitRegion(config.CONF.Hk4e.KcpAddr, config.CONF.Hk4e.KcpPort, ec2b)
|
r.ec2b = ec2b
|
||||||
regionCurrModify, err := pb.Marshal(regionCurr)
|
|
||||||
if err != nil {
|
|
||||||
logger.Error("Marshal QueryCurrRegionHttpRsp error")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
r.regionCurrBase64 = base64.StdEncoding.EncodeToString(regionCurrModify)
|
|
||||||
regionListModify, err := pb.Marshal(regionList)
|
|
||||||
if err != nil {
|
|
||||||
logger.Error("Marshal QueryRegionListHttpRsp error")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
r.regionListBase64 = base64.StdEncoding.EncodeToString(regionListModify)
|
|
||||||
go r.registerRouter()
|
go r.registerRouter()
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"hk4e/dispatch/api"
|
"hk4e/common/region"
|
||||||
|
httpapi "hk4e/dispatch/api"
|
||||||
|
"hk4e/node/api"
|
||||||
"hk4e/pkg/endec"
|
"hk4e/pkg/endec"
|
||||||
"hk4e/pkg/logger"
|
"hk4e/pkg/logger"
|
||||||
|
|
||||||
@@ -17,6 +19,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (c *Controller) query_security_file(context *gin.Context) {
|
func (c *Controller) query_security_file(context *gin.Context) {
|
||||||
|
return
|
||||||
file, err := os.ReadFile("static/security_file")
|
file, err := os.ReadFile("static/security_file")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("open security_file error")
|
logger.Error("open security_file error")
|
||||||
@@ -28,14 +31,21 @@ func (c *Controller) query_security_file(context *gin.Context) {
|
|||||||
|
|
||||||
func (c *Controller) query_region_list(context *gin.Context) {
|
func (c *Controller) query_region_list(context *gin.Context) {
|
||||||
context.Header("Content-type", "text/html; charset=UTF-8")
|
context.Header("Content-type", "text/html; charset=UTF-8")
|
||||||
_, _ = context.Writer.WriteString(c.regionListBase64)
|
regionListBase64 := region.GetRegionListBase64(c.ec2b)
|
||||||
|
_, _ = context.Writer.WriteString(regionListBase64)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) query_cur_region(context *gin.Context) {
|
func (c *Controller) query_cur_region(context *gin.Context) {
|
||||||
versionName := context.Query("version")
|
versionName := context.Query("version")
|
||||||
response := "CAESGE5vdCBGb3VuZCB2ZXJzaW9uIGNvbmZpZw=="
|
response := "CAESGE5vdCBGb3VuZCB2ZXJzaW9uIGNvbmZpZw=="
|
||||||
if len(context.Request.URL.RawQuery) > 0 {
|
if len(context.Request.URL.RawQuery) > 0 {
|
||||||
response = c.regionCurrBase64
|
addr, err := c.discovery.GetGateServerAddr(context.Request.Context(), &api.NullMsg{})
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("get gate server addr error: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
regionCurrBase64 := region.GetRegionCurrBase64(addr.IpAddr, int32(addr.Port), c.ec2b)
|
||||||
|
response = regionCurrBase64
|
||||||
}
|
}
|
||||||
reg, err := regexp.Compile("[0-9]+")
|
reg, err := regexp.Compile("[0-9]+")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -62,7 +72,7 @@ func (c *Controller) query_cur_region(context *gin.Context) {
|
|||||||
if version >= 275 {
|
if version >= 275 {
|
||||||
logger.Debug("do hk4e 2.8 rsa logic")
|
logger.Debug("do hk4e 2.8 rsa logic")
|
||||||
if context.Query("dispatchSeed") == "" {
|
if context.Query("dispatchSeed") == "" {
|
||||||
rsp := &api.QueryCurRegionRspJson{
|
rsp := &httpapi.QueryCurRegionRspJson{
|
||||||
Content: response,
|
Content: response,
|
||||||
Sign: "TW9yZSBsb3ZlIGZvciBVQSBQYXRjaCBwbGF5ZXJz",
|
Sign: "TW9yZSBsb3ZlIGZvciBVQSBQYXRjaCBwbGF5ZXJz",
|
||||||
}
|
}
|
||||||
@@ -133,7 +143,7 @@ func (c *Controller) query_cur_region(context *gin.Context) {
|
|||||||
logger.Error("rsa verify test fail")
|
logger.Error("rsa verify test fail")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rsp := &api.QueryCurRegionRspJson{
|
rsp := &httpapi.QueryCurRegionRspJson{
|
||||||
Content: base64.StdEncoding.EncodeToString(encryptedRegionInfo),
|
Content: base64.StdEncoding.EncodeToString(encryptedRegionInfo),
|
||||||
Sign: base64.StdEncoding.EncodeToString(signData),
|
Sign: base64.StdEncoding.EncodeToString(signData),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,12 @@ func Run(ctx context.Context, configFile string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
APPID = rsp.GetAppId()
|
APPID = rsp.GetAppId()
|
||||||
|
defer func() {
|
||||||
|
_, _ = client.Discovery.CancelServer(context.TODO(), &api.CancelServerReq{
|
||||||
|
ServerType: api.FIGHT,
|
||||||
|
AppId: APPID,
|
||||||
|
})
|
||||||
|
}()
|
||||||
|
|
||||||
logger.InitLogger("fight_" + APPID)
|
logger.InitLogger("fight_" + APPID)
|
||||||
logger.Warn("fight start, appid: %v", APPID)
|
logger.Warn("fight start, appid: %v", APPID)
|
||||||
|
|||||||
@@ -30,11 +30,21 @@ func Run(ctx context.Context, configFile string) error {
|
|||||||
// 注册到节点服务器
|
// 注册到节点服务器
|
||||||
rsp, err := client.Discovery.RegisterServer(context.TODO(), &api.RegisterServerReq{
|
rsp, err := client.Discovery.RegisterServer(context.TODO(), &api.RegisterServerReq{
|
||||||
ServerType: api.GATE,
|
ServerType: api.GATE,
|
||||||
|
GateServerAddr: &api.GateServerAddr{
|
||||||
|
IpAddr: config.CONF.Hk4e.KcpAddr,
|
||||||
|
Port: uint32(config.CONF.Hk4e.KcpPort),
|
||||||
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
APPID = rsp.GetAppId()
|
APPID = rsp.GetAppId()
|
||||||
|
defer func() {
|
||||||
|
_, _ = client.Discovery.CancelServer(context.TODO(), &api.CancelServerReq{
|
||||||
|
ServerType: api.GATE,
|
||||||
|
AppId: APPID,
|
||||||
|
})
|
||||||
|
}()
|
||||||
|
|
||||||
logger.InitLogger("gate_" + APPID)
|
logger.InitLogger("gate_" + APPID)
|
||||||
logger.Warn("gate start, appid: %v", APPID)
|
logger.Warn("gate start, appid: %v", APPID)
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ func Run(ctx context.Context, configFile string) error {
|
|||||||
logger.InitLogger("gm")
|
logger.InitLogger("gm")
|
||||||
logger.Warn("gm start")
|
logger.Warn("gm start")
|
||||||
|
|
||||||
|
// natsrpc client
|
||||||
client, err := rpc.NewClient()
|
client, err := rpc.NewClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var APPID string
|
var APPID string
|
||||||
|
var GSID uint32
|
||||||
|
|
||||||
func Run(ctx context.Context, configFile string) error {
|
func Run(ctx context.Context, configFile string) error {
|
||||||
config.InitConfig(configFile)
|
config.InitConfig(configFile)
|
||||||
@@ -42,9 +43,16 @@ func Run(ctx context.Context, configFile string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
APPID = rsp.GetAppId()
|
APPID = rsp.GetAppId()
|
||||||
|
GSID = rsp.GetGsId()
|
||||||
|
defer func() {
|
||||||
|
_, _ = client.Discovery.CancelServer(context.TODO(), &api.CancelServerReq{
|
||||||
|
ServerType: api.GS,
|
||||||
|
AppId: APPID,
|
||||||
|
})
|
||||||
|
}()
|
||||||
|
|
||||||
logger.InitLogger("gs_" + APPID)
|
logger.InitLogger("gs_" + APPID)
|
||||||
logger.Warn("gs start, appid: %v", APPID)
|
logger.Warn("gs start, appid: %v, gsid: %v", APPID, GSID)
|
||||||
|
|
||||||
constant.InitConstant()
|
constant.InitConstant()
|
||||||
|
|
||||||
@@ -60,7 +68,7 @@ func Run(ctx context.Context, configFile string) error {
|
|||||||
messageQueue := mq.NewMessageQueue(api.GS, APPID)
|
messageQueue := mq.NewMessageQueue(api.GS, APPID)
|
||||||
defer messageQueue.Close()
|
defer messageQueue.Close()
|
||||||
|
|
||||||
gameManager := game.NewGameManager(db, messageQueue)
|
gameManager := game.NewGameManager(db, messageQueue, GSID)
|
||||||
defer gameManager.Stop()
|
defer gameManager.Stop()
|
||||||
|
|
||||||
// natsrpc server
|
// natsrpc server
|
||||||
|
|||||||
@@ -30,11 +30,11 @@ type GameManager struct {
|
|||||||
snowflake *alg.SnowflakeWorker
|
snowflake *alg.SnowflakeWorker
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGameManager(dao *dao.Dao, messageQueue *mq.MessageQueue) (r *GameManager) {
|
func NewGameManager(dao *dao.Dao, messageQueue *mq.MessageQueue, gsId uint32) (r *GameManager) {
|
||||||
r = new(GameManager)
|
r = new(GameManager)
|
||||||
r.dao = dao
|
r.dao = dao
|
||||||
r.messageQueue = messageQueue
|
r.messageQueue = messageQueue
|
||||||
r.snowflake = alg.NewSnowflakeWorker(1)
|
r.snowflake = alg.NewSnowflakeWorker(int64(gsId))
|
||||||
GAME_MANAGER = r
|
GAME_MANAGER = r
|
||||||
LOCAL_EVENT_MANAGER = NewLocalEventManager()
|
LOCAL_EVENT_MANAGER = NewLocalEventManager()
|
||||||
ROUTE_MANAGER = NewRouteManager()
|
ROUTE_MANAGER = NewRouteManager()
|
||||||
|
|||||||
@@ -21,9 +21,18 @@ var _ = nats_go.Version
|
|||||||
|
|
||||||
// 节点服务器注册发现服务
|
// 节点服务器注册发现服务
|
||||||
type DiscoveryNATSRPCServer interface {
|
type DiscoveryNATSRPCServer interface {
|
||||||
|
// 服务器启动注册获取appid
|
||||||
RegisterServer(ctx context.Context, req *RegisterServerReq) (*RegisterServerRsp, error)
|
RegisterServer(ctx context.Context, req *RegisterServerReq) (*RegisterServerRsp, error)
|
||||||
|
// 服务器关闭取消注册
|
||||||
|
CancelServer(ctx context.Context, req *CancelServerReq) (*NullMsg, error)
|
||||||
|
// 服务器在线心跳保持
|
||||||
|
KeepaliveServer(ctx context.Context, req *KeepaliveServerReq) (*NullMsg, error)
|
||||||
|
// 获取负载最小的服务器的appid
|
||||||
GetServerAppId(ctx context.Context, req *GetServerAppIdReq) (*GetServerAppIdRsp, error)
|
GetServerAppId(ctx context.Context, req *GetServerAppIdReq) (*GetServerAppIdRsp, error)
|
||||||
|
// 获取区服密钥信息
|
||||||
GetRegionEc2B(ctx context.Context, req *NullMsg) (*RegionEc2B, error)
|
GetRegionEc2B(ctx context.Context, req *NullMsg) (*RegionEc2B, error)
|
||||||
|
// 获取负载最小的网关服务器的地址和端口
|
||||||
|
GetGateServerAddr(ctx context.Context, req *NullMsg) (*GateServerAddr, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterDiscoveryNATSRPCServer register Discovery service
|
// RegisterDiscoveryNATSRPCServer register Discovery service
|
||||||
@@ -33,9 +42,18 @@ func RegisterDiscoveryNATSRPCServer(server *natsrpc.Server, s DiscoveryNATSRPCSe
|
|||||||
|
|
||||||
// 节点服务器注册发现服务
|
// 节点服务器注册发现服务
|
||||||
type DiscoveryNATSRPCClient interface {
|
type DiscoveryNATSRPCClient interface {
|
||||||
|
// 服务器启动注册获取appid
|
||||||
RegisterServer(ctx context.Context, req *RegisterServerReq, opt ...natsrpc.CallOption) (*RegisterServerRsp, error)
|
RegisterServer(ctx context.Context, req *RegisterServerReq, opt ...natsrpc.CallOption) (*RegisterServerRsp, error)
|
||||||
|
// 服务器关闭取消注册
|
||||||
|
CancelServer(ctx context.Context, req *CancelServerReq, opt ...natsrpc.CallOption) (*NullMsg, error)
|
||||||
|
// 服务器在线心跳保持
|
||||||
|
KeepaliveServer(ctx context.Context, req *KeepaliveServerReq, opt ...natsrpc.CallOption) (*NullMsg, error)
|
||||||
|
// 获取负载最小的服务器的appid
|
||||||
GetServerAppId(ctx context.Context, req *GetServerAppIdReq, opt ...natsrpc.CallOption) (*GetServerAppIdRsp, error)
|
GetServerAppId(ctx context.Context, req *GetServerAppIdReq, opt ...natsrpc.CallOption) (*GetServerAppIdRsp, error)
|
||||||
|
// 获取区服密钥信息
|
||||||
GetRegionEc2B(ctx context.Context, req *NullMsg, opt ...natsrpc.CallOption) (*RegionEc2B, error)
|
GetRegionEc2B(ctx context.Context, req *NullMsg, opt ...natsrpc.CallOption) (*RegionEc2B, error)
|
||||||
|
// 获取负载最小的网关服务器的地址和端口
|
||||||
|
GetGateServerAddr(ctx context.Context, req *NullMsg, opt ...natsrpc.CallOption) (*GateServerAddr, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type _DiscoveryNATSRPCClient struct {
|
type _DiscoveryNATSRPCClient struct {
|
||||||
@@ -58,6 +76,16 @@ func (c *_DiscoveryNATSRPCClient) RegisterServer(ctx context.Context, req *Regis
|
|||||||
err := c.c.Request(ctx, "RegisterServer", req, rep, opt...)
|
err := c.c.Request(ctx, "RegisterServer", req, rep, opt...)
|
||||||
return rep, err
|
return rep, err
|
||||||
}
|
}
|
||||||
|
func (c *_DiscoveryNATSRPCClient) CancelServer(ctx context.Context, req *CancelServerReq, opt ...natsrpc.CallOption) (*NullMsg, error) {
|
||||||
|
rep := &NullMsg{}
|
||||||
|
err := c.c.Request(ctx, "CancelServer", req, rep, opt...)
|
||||||
|
return rep, err
|
||||||
|
}
|
||||||
|
func (c *_DiscoveryNATSRPCClient) KeepaliveServer(ctx context.Context, req *KeepaliveServerReq, opt ...natsrpc.CallOption) (*NullMsg, error) {
|
||||||
|
rep := &NullMsg{}
|
||||||
|
err := c.c.Request(ctx, "KeepaliveServer", req, rep, opt...)
|
||||||
|
return rep, err
|
||||||
|
}
|
||||||
func (c *_DiscoveryNATSRPCClient) GetServerAppId(ctx context.Context, req *GetServerAppIdReq, opt ...natsrpc.CallOption) (*GetServerAppIdRsp, error) {
|
func (c *_DiscoveryNATSRPCClient) GetServerAppId(ctx context.Context, req *GetServerAppIdReq, opt ...natsrpc.CallOption) (*GetServerAppIdRsp, error) {
|
||||||
rep := &GetServerAppIdRsp{}
|
rep := &GetServerAppIdRsp{}
|
||||||
err := c.c.Request(ctx, "GetServerAppId", req, rep, opt...)
|
err := c.c.Request(ctx, "GetServerAppId", req, rep, opt...)
|
||||||
@@ -68,3 +96,8 @@ func (c *_DiscoveryNATSRPCClient) GetRegionEc2B(ctx context.Context, req *NullMs
|
|||||||
err := c.c.Request(ctx, "GetRegionEc2B", req, rep, opt...)
|
err := c.c.Request(ctx, "GetRegionEc2B", req, rep, opt...)
|
||||||
return rep, err
|
return rep, err
|
||||||
}
|
}
|
||||||
|
func (c *_DiscoveryNATSRPCClient) GetGateServerAddr(ctx context.Context, req *NullMsg, opt ...natsrpc.CallOption) (*GateServerAddr, error) {
|
||||||
|
rep := &GateServerAddr{}
|
||||||
|
err := c.c.Request(ctx, "GetGateServerAddr", req, rep, opt...)
|
||||||
|
return rep, err
|
||||||
|
}
|
||||||
|
|||||||
@@ -157,7 +157,8 @@ type RegisterServerReq struct {
|
|||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
ServerType string `protobuf:"bytes,1,opt,name=server_type,json=serverType,proto3" json:"server_type,omitempty"`
|
ServerType string `protobuf:"bytes,1,opt,name=server_type,json=serverType,proto3" json:"server_type,omitempty"`
|
||||||
|
GateServerAddr *GateServerAddr `protobuf:"bytes,2,opt,name=gate_server_addr,json=gateServerAddr,proto3" json:"gate_server_addr,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *RegisterServerReq) Reset() {
|
func (x *RegisterServerReq) Reset() {
|
||||||
@@ -199,12 +200,20 @@ func (x *RegisterServerReq) GetServerType() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *RegisterServerReq) GetGateServerAddr() *GateServerAddr {
|
||||||
|
if x != nil {
|
||||||
|
return x.GateServerAddr
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type RegisterServerRsp struct {
|
type RegisterServerRsp struct {
|
||||||
state protoimpl.MessageState
|
state protoimpl.MessageState
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
AppId string `protobuf:"bytes,1,opt,name=app_id,json=appId,proto3" json:"app_id,omitempty"`
|
AppId string `protobuf:"bytes,1,opt,name=app_id,json=appId,proto3" json:"app_id,omitempty"`
|
||||||
|
GsId uint32 `protobuf:"varint,2,opt,name=gs_id,json=gsId,proto3" json:"gs_id,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *RegisterServerRsp) Reset() {
|
func (x *RegisterServerRsp) Reset() {
|
||||||
@@ -246,6 +255,123 @@ func (x *RegisterServerRsp) GetAppId() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *RegisterServerRsp) GetGsId() uint32 {
|
||||||
|
if x != nil {
|
||||||
|
return x.GsId
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
type CancelServerReq struct {
|
||||||
|
state protoimpl.MessageState
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
|
ServerType string `protobuf:"bytes,1,opt,name=server_type,json=serverType,proto3" json:"server_type,omitempty"`
|
||||||
|
AppId string `protobuf:"bytes,2,opt,name=app_id,json=appId,proto3" json:"app_id,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *CancelServerReq) Reset() {
|
||||||
|
*x = CancelServerReq{}
|
||||||
|
if protoimpl.UnsafeEnabled {
|
||||||
|
mi := &file_api_proto_msgTypes[5]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *CancelServerReq) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*CancelServerReq) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *CancelServerReq) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_api_proto_msgTypes[5]
|
||||||
|
if protoimpl.UnsafeEnabled && x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use CancelServerReq.ProtoReflect.Descriptor instead.
|
||||||
|
func (*CancelServerReq) Descriptor() ([]byte, []int) {
|
||||||
|
return file_api_proto_rawDescGZIP(), []int{5}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *CancelServerReq) GetServerType() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.ServerType
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *CancelServerReq) GetAppId() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.AppId
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
type KeepaliveServerReq struct {
|
||||||
|
state protoimpl.MessageState
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
|
ServerType string `protobuf:"bytes,1,opt,name=server_type,json=serverType,proto3" json:"server_type,omitempty"`
|
||||||
|
AppId string `protobuf:"bytes,2,opt,name=app_id,json=appId,proto3" json:"app_id,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *KeepaliveServerReq) Reset() {
|
||||||
|
*x = KeepaliveServerReq{}
|
||||||
|
if protoimpl.UnsafeEnabled {
|
||||||
|
mi := &file_api_proto_msgTypes[6]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *KeepaliveServerReq) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*KeepaliveServerReq) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *KeepaliveServerReq) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_api_proto_msgTypes[6]
|
||||||
|
if protoimpl.UnsafeEnabled && x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use KeepaliveServerReq.ProtoReflect.Descriptor instead.
|
||||||
|
func (*KeepaliveServerReq) Descriptor() ([]byte, []int) {
|
||||||
|
return file_api_proto_rawDescGZIP(), []int{6}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *KeepaliveServerReq) GetServerType() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.ServerType
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *KeepaliveServerReq) GetAppId() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.AppId
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
type RegionEc2B struct {
|
type RegionEc2B struct {
|
||||||
state protoimpl.MessageState
|
state protoimpl.MessageState
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
@@ -257,7 +383,7 @@ type RegionEc2B struct {
|
|||||||
func (x *RegionEc2B) Reset() {
|
func (x *RegionEc2B) Reset() {
|
||||||
*x = RegionEc2B{}
|
*x = RegionEc2B{}
|
||||||
if protoimpl.UnsafeEnabled {
|
if protoimpl.UnsafeEnabled {
|
||||||
mi := &file_api_proto_msgTypes[5]
|
mi := &file_api_proto_msgTypes[7]
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
ms.StoreMessageInfo(mi)
|
ms.StoreMessageInfo(mi)
|
||||||
}
|
}
|
||||||
@@ -270,7 +396,7 @@ func (x *RegionEc2B) String() string {
|
|||||||
func (*RegionEc2B) ProtoMessage() {}
|
func (*RegionEc2B) ProtoMessage() {}
|
||||||
|
|
||||||
func (x *RegionEc2B) ProtoReflect() protoreflect.Message {
|
func (x *RegionEc2B) ProtoReflect() protoreflect.Message {
|
||||||
mi := &file_api_proto_msgTypes[5]
|
mi := &file_api_proto_msgTypes[7]
|
||||||
if protoimpl.UnsafeEnabled && x != nil {
|
if protoimpl.UnsafeEnabled && x != nil {
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
if ms.LoadMessageInfo() == nil {
|
if ms.LoadMessageInfo() == nil {
|
||||||
@@ -283,7 +409,7 @@ func (x *RegionEc2B) ProtoReflect() protoreflect.Message {
|
|||||||
|
|
||||||
// Deprecated: Use RegionEc2B.ProtoReflect.Descriptor instead.
|
// Deprecated: Use RegionEc2B.ProtoReflect.Descriptor instead.
|
||||||
func (*RegionEc2B) Descriptor() ([]byte, []int) {
|
func (*RegionEc2B) Descriptor() ([]byte, []int) {
|
||||||
return file_api_proto_rawDescGZIP(), []int{5}
|
return file_api_proto_rawDescGZIP(), []int{7}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *RegionEc2B) GetData() []byte {
|
func (x *RegionEc2B) GetData() []byte {
|
||||||
@@ -293,6 +419,61 @@ func (x *RegionEc2B) GetData() []byte {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GateServerAddr struct {
|
||||||
|
state protoimpl.MessageState
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
|
IpAddr string `protobuf:"bytes,1,opt,name=ip_addr,json=ipAddr,proto3" json:"ip_addr,omitempty"`
|
||||||
|
Port uint32 `protobuf:"varint,2,opt,name=port,proto3" json:"port,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GateServerAddr) Reset() {
|
||||||
|
*x = GateServerAddr{}
|
||||||
|
if protoimpl.UnsafeEnabled {
|
||||||
|
mi := &file_api_proto_msgTypes[8]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GateServerAddr) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*GateServerAddr) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *GateServerAddr) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_api_proto_msgTypes[8]
|
||||||
|
if protoimpl.UnsafeEnabled && x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use GateServerAddr.ProtoReflect.Descriptor instead.
|
||||||
|
func (*GateServerAddr) Descriptor() ([]byte, []int) {
|
||||||
|
return file_api_proto_rawDescGZIP(), []int{8}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GateServerAddr) GetIpAddr() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.IpAddr
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GateServerAddr) GetPort() uint32 {
|
||||||
|
if x != nil {
|
||||||
|
return x.Port
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
var File_api_proto protoreflect.FileDescriptor
|
var File_api_proto protoreflect.FileDescriptor
|
||||||
|
|
||||||
var file_api_proto_rawDesc = []byte{
|
var file_api_proto_rawDesc = []byte{
|
||||||
@@ -304,31 +485,63 @@ var file_api_proto_rawDesc = []byte{
|
|||||||
0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x22, 0x2a, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x53, 0x65, 0x72,
|
0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x22, 0x2a, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x53, 0x65, 0x72,
|
||||||
0x76, 0x65, 0x72, 0x41, 0x70, 0x70, 0x49, 0x64, 0x52, 0x73, 0x70, 0x12, 0x15, 0x0a, 0x06, 0x61,
|
0x76, 0x65, 0x72, 0x41, 0x70, 0x70, 0x49, 0x64, 0x52, 0x73, 0x70, 0x12, 0x15, 0x0a, 0x06, 0x61,
|
||||||
0x70, 0x70, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x61, 0x70, 0x70,
|
0x70, 0x70, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x61, 0x70, 0x70,
|
||||||
0x49, 0x64, 0x22, 0x34, 0x0a, 0x11, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x53, 0x65,
|
0x49, 0x64, 0x22, 0x78, 0x0a, 0x11, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x53, 0x65,
|
||||||
0x72, 0x76, 0x65, 0x72, 0x52, 0x65, 0x71, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x65,
|
0x72, 0x76, 0x65, 0x72, 0x52, 0x65, 0x71, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x65,
|
||||||
0x72, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x65,
|
0x72, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x65,
|
||||||
0x72, 0x76, 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x22, 0x2a, 0x0a, 0x11, 0x52, 0x65, 0x67, 0x69,
|
0x72, 0x76, 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x12, 0x42, 0x0a, 0x10, 0x67, 0x61, 0x74, 0x65,
|
||||||
0x73, 0x74, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x73, 0x70, 0x12, 0x15, 0x0a,
|
0x5f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x02, 0x20, 0x01,
|
||||||
0x06, 0x61, 0x70, 0x70, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x61,
|
0x28, 0x0b, 0x32, 0x18, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x47, 0x61,
|
||||||
0x70, 0x70, 0x49, 0x64, 0x22, 0x20, 0x0a, 0x0a, 0x52, 0x65, 0x67, 0x69, 0x6f, 0x6e, 0x45, 0x63,
|
0x74, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x52, 0x0e, 0x67, 0x61,
|
||||||
0x32, 0x62, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c,
|
0x74, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x22, 0x3f, 0x0a, 0x11,
|
||||||
0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x32, 0xe3, 0x01, 0x0a, 0x09, 0x44, 0x69, 0x73, 0x63, 0x6f,
|
0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x73,
|
||||||
0x76, 0x65, 0x72, 0x79, 0x12, 0x4c, 0x0a, 0x0e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72,
|
0x70, 0x12, 0x15, 0x0a, 0x06, 0x61, 0x70, 0x70, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||||
0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x1b, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70,
|
0x09, 0x52, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x12, 0x13, 0x0a, 0x05, 0x67, 0x73, 0x5f, 0x69,
|
||||||
0x69, 0x2e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72,
|
0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x67, 0x73, 0x49, 0x64, 0x22, 0x49, 0x0a,
|
||||||
0x52, 0x65, 0x71, 0x1a, 0x1b, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x52,
|
0x0f, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x65, 0x71,
|
||||||
0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x73, 0x70,
|
0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18,
|
||||||
0x22, 0x00, 0x12, 0x4c, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41,
|
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x54, 0x79, 0x70,
|
||||||
0x70, 0x70, 0x49, 0x64, 0x12, 0x1b, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e,
|
0x65, 0x12, 0x15, 0x0a, 0x06, 0x61, 0x70, 0x70, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28,
|
||||||
0x47, 0x65, 0x74, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x70, 0x70, 0x49, 0x64, 0x52, 0x65,
|
0x09, 0x52, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x22, 0x4c, 0x0a, 0x12, 0x4b, 0x65, 0x65, 0x70,
|
||||||
0x71, 0x1a, 0x1b, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x47, 0x65, 0x74,
|
0x61, 0x6c, 0x69, 0x76, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x65, 0x71, 0x12, 0x1f,
|
||||||
0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x70, 0x70, 0x49, 0x64, 0x52, 0x73, 0x70, 0x22, 0x00,
|
0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20,
|
||||||
0x12, 0x3a, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x52, 0x65, 0x67, 0x69, 0x6f, 0x6e, 0x45, 0x63, 0x32,
|
0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x12,
|
||||||
0x62, 0x12, 0x11, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4e, 0x75, 0x6c,
|
0x15, 0x0a, 0x06, 0x61, 0x70, 0x70, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||||
0x6c, 0x4d, 0x73, 0x67, 0x1a, 0x14, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e,
|
0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x22, 0x20, 0x0a, 0x0a, 0x52, 0x65, 0x67, 0x69, 0x6f, 0x6e,
|
||||||
0x52, 0x65, 0x67, 0x69, 0x6f, 0x6e, 0x45, 0x63, 0x32, 0x62, 0x22, 0x00, 0x42, 0x13, 0x5a, 0x11,
|
0x45, 0x63, 0x32, 0x62, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01,
|
||||||
0x68, 0x6b, 0x34, 0x65, 0x2f, 0x6e, 0x6f, 0x64, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x3b, 0x61, 0x70,
|
0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x3d, 0x0a, 0x0e, 0x47, 0x61, 0x74, 0x65,
|
||||||
0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x12, 0x17, 0x0a, 0x07, 0x69, 0x70,
|
||||||
|
0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x69, 0x70, 0x41,
|
||||||
|
0x64, 0x64, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28,
|
||||||
|
0x0d, 0x52, 0x04, 0x70, 0x6f, 0x72, 0x74, 0x32, 0xad, 0x03, 0x0a, 0x09, 0x44, 0x69, 0x73, 0x63,
|
||||||
|
0x6f, 0x76, 0x65, 0x72, 0x79, 0x12, 0x4c, 0x0a, 0x0e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65,
|
||||||
|
0x72, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x1b, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61,
|
||||||
|
0x70, 0x69, 0x2e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x65,
|
||||||
|
0x72, 0x52, 0x65, 0x71, 0x1a, 0x1b, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e,
|
||||||
|
0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x73,
|
||||||
|
0x70, 0x22, 0x00, 0x12, 0x3e, 0x0a, 0x0c, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x53, 0x65, 0x72,
|
||||||
|
0x76, 0x65, 0x72, 0x12, 0x19, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x43,
|
||||||
|
0x61, 0x6e, 0x63, 0x65, 0x6c, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x65, 0x71, 0x1a, 0x11,
|
||||||
|
0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4e, 0x75, 0x6c, 0x6c, 0x4d, 0x73,
|
||||||
|
0x67, 0x22, 0x00, 0x12, 0x44, 0x0a, 0x0f, 0x4b, 0x65, 0x65, 0x70, 0x61, 0x6c, 0x69, 0x76, 0x65,
|
||||||
|
0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x1c, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70,
|
||||||
|
0x69, 0x2e, 0x4b, 0x65, 0x65, 0x70, 0x61, 0x6c, 0x69, 0x76, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65,
|
||||||
|
0x72, 0x52, 0x65, 0x71, 0x1a, 0x11, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e,
|
||||||
|
0x4e, 0x75, 0x6c, 0x6c, 0x4d, 0x73, 0x67, 0x22, 0x00, 0x12, 0x4c, 0x0a, 0x0e, 0x47, 0x65, 0x74,
|
||||||
|
0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x70, 0x70, 0x49, 0x64, 0x12, 0x1b, 0x2e, 0x6e, 0x6f,
|
||||||
|
0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72,
|
||||||
|
0x41, 0x70, 0x70, 0x49, 0x64, 0x52, 0x65, 0x71, 0x1a, 0x1b, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e,
|
||||||
|
0x61, 0x70, 0x69, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x70, 0x70,
|
||||||
|
0x49, 0x64, 0x52, 0x73, 0x70, 0x22, 0x00, 0x12, 0x3a, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x52, 0x65,
|
||||||
|
0x67, 0x69, 0x6f, 0x6e, 0x45, 0x63, 0x32, 0x62, 0x12, 0x11, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e,
|
||||||
|
0x61, 0x70, 0x69, 0x2e, 0x4e, 0x75, 0x6c, 0x6c, 0x4d, 0x73, 0x67, 0x1a, 0x14, 0x2e, 0x6e, 0x6f,
|
||||||
|
0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x52, 0x65, 0x67, 0x69, 0x6f, 0x6e, 0x45, 0x63, 0x32,
|
||||||
|
0x62, 0x22, 0x00, 0x12, 0x42, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x47, 0x61, 0x74, 0x65, 0x53, 0x65,
|
||||||
|
0x72, 0x76, 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x12, 0x11, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e,
|
||||||
|
0x61, 0x70, 0x69, 0x2e, 0x4e, 0x75, 0x6c, 0x6c, 0x4d, 0x73, 0x67, 0x1a, 0x18, 0x2e, 0x6e, 0x6f,
|
||||||
|
0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x47, 0x61, 0x74, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65,
|
||||||
|
0x72, 0x41, 0x64, 0x64, 0x72, 0x22, 0x00, 0x42, 0x13, 0x5a, 0x11, 0x68, 0x6b, 0x34, 0x65, 0x2f,
|
||||||
|
0x6e, 0x6f, 0x64, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x3b, 0x61, 0x70, 0x69, 0x62, 0x06, 0x70, 0x72,
|
||||||
|
0x6f, 0x74, 0x6f, 0x33,
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -343,27 +556,37 @@ func file_api_proto_rawDescGZIP() []byte {
|
|||||||
return file_api_proto_rawDescData
|
return file_api_proto_rawDescData
|
||||||
}
|
}
|
||||||
|
|
||||||
var file_api_proto_msgTypes = make([]protoimpl.MessageInfo, 6)
|
var file_api_proto_msgTypes = make([]protoimpl.MessageInfo, 9)
|
||||||
var file_api_proto_goTypes = []interface{}{
|
var file_api_proto_goTypes = []interface{}{
|
||||||
(*NullMsg)(nil), // 0: node.api.NullMsg
|
(*NullMsg)(nil), // 0: node.api.NullMsg
|
||||||
(*GetServerAppIdReq)(nil), // 1: node.api.GetServerAppIdReq
|
(*GetServerAppIdReq)(nil), // 1: node.api.GetServerAppIdReq
|
||||||
(*GetServerAppIdRsp)(nil), // 2: node.api.GetServerAppIdRsp
|
(*GetServerAppIdRsp)(nil), // 2: node.api.GetServerAppIdRsp
|
||||||
(*RegisterServerReq)(nil), // 3: node.api.RegisterServerReq
|
(*RegisterServerReq)(nil), // 3: node.api.RegisterServerReq
|
||||||
(*RegisterServerRsp)(nil), // 4: node.api.RegisterServerRsp
|
(*RegisterServerRsp)(nil), // 4: node.api.RegisterServerRsp
|
||||||
(*RegionEc2B)(nil), // 5: node.api.RegionEc2b
|
(*CancelServerReq)(nil), // 5: node.api.CancelServerReq
|
||||||
|
(*KeepaliveServerReq)(nil), // 6: node.api.KeepaliveServerReq
|
||||||
|
(*RegionEc2B)(nil), // 7: node.api.RegionEc2b
|
||||||
|
(*GateServerAddr)(nil), // 8: node.api.GateServerAddr
|
||||||
}
|
}
|
||||||
var file_api_proto_depIdxs = []int32{
|
var file_api_proto_depIdxs = []int32{
|
||||||
3, // 0: node.api.Discovery.RegisterServer:input_type -> node.api.RegisterServerReq
|
8, // 0: node.api.RegisterServerReq.gate_server_addr:type_name -> node.api.GateServerAddr
|
||||||
1, // 1: node.api.Discovery.GetServerAppId:input_type -> node.api.GetServerAppIdReq
|
3, // 1: node.api.Discovery.RegisterServer:input_type -> node.api.RegisterServerReq
|
||||||
0, // 2: node.api.Discovery.GetRegionEc2b:input_type -> node.api.NullMsg
|
5, // 2: node.api.Discovery.CancelServer:input_type -> node.api.CancelServerReq
|
||||||
4, // 3: node.api.Discovery.RegisterServer:output_type -> node.api.RegisterServerRsp
|
6, // 3: node.api.Discovery.KeepaliveServer:input_type -> node.api.KeepaliveServerReq
|
||||||
2, // 4: node.api.Discovery.GetServerAppId:output_type -> node.api.GetServerAppIdRsp
|
1, // 4: node.api.Discovery.GetServerAppId:input_type -> node.api.GetServerAppIdReq
|
||||||
5, // 5: node.api.Discovery.GetRegionEc2b:output_type -> node.api.RegionEc2b
|
0, // 5: node.api.Discovery.GetRegionEc2b:input_type -> node.api.NullMsg
|
||||||
3, // [3:6] is the sub-list for method output_type
|
0, // 6: node.api.Discovery.GetGateServerAddr:input_type -> node.api.NullMsg
|
||||||
0, // [0:3] is the sub-list for method input_type
|
4, // 7: node.api.Discovery.RegisterServer:output_type -> node.api.RegisterServerRsp
|
||||||
0, // [0:0] is the sub-list for extension type_name
|
0, // 8: node.api.Discovery.CancelServer:output_type -> node.api.NullMsg
|
||||||
0, // [0:0] is the sub-list for extension extendee
|
0, // 9: node.api.Discovery.KeepaliveServer:output_type -> node.api.NullMsg
|
||||||
0, // [0:0] is the sub-list for field type_name
|
2, // 10: node.api.Discovery.GetServerAppId:output_type -> node.api.GetServerAppIdRsp
|
||||||
|
7, // 11: node.api.Discovery.GetRegionEc2b:output_type -> node.api.RegionEc2b
|
||||||
|
8, // 12: node.api.Discovery.GetGateServerAddr:output_type -> node.api.GateServerAddr
|
||||||
|
7, // [7:13] is the sub-list for method output_type
|
||||||
|
1, // [1:7] is the sub-list for method input_type
|
||||||
|
1, // [1:1] is the sub-list for extension type_name
|
||||||
|
1, // [1:1] is the sub-list for extension extendee
|
||||||
|
0, // [0:1] is the sub-list for field type_name
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { file_api_proto_init() }
|
func init() { file_api_proto_init() }
|
||||||
@@ -433,6 +656,30 @@ func file_api_proto_init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
file_api_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
|
file_api_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
|
||||||
|
switch v := v.(*CancelServerReq); i {
|
||||||
|
case 0:
|
||||||
|
return &v.state
|
||||||
|
case 1:
|
||||||
|
return &v.sizeCache
|
||||||
|
case 2:
|
||||||
|
return &v.unknownFields
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file_api_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {
|
||||||
|
switch v := v.(*KeepaliveServerReq); i {
|
||||||
|
case 0:
|
||||||
|
return &v.state
|
||||||
|
case 1:
|
||||||
|
return &v.sizeCache
|
||||||
|
case 2:
|
||||||
|
return &v.unknownFields
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file_api_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} {
|
||||||
switch v := v.(*RegionEc2B); i {
|
switch v := v.(*RegionEc2B); i {
|
||||||
case 0:
|
case 0:
|
||||||
return &v.state
|
return &v.state
|
||||||
@@ -444,6 +691,18 @@ func file_api_proto_init() {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
file_api_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} {
|
||||||
|
switch v := v.(*GateServerAddr); i {
|
||||||
|
case 0:
|
||||||
|
return &v.state
|
||||||
|
case 1:
|
||||||
|
return &v.sizeCache
|
||||||
|
case 2:
|
||||||
|
return &v.unknownFields
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
type x struct{}
|
type x struct{}
|
||||||
out := protoimpl.TypeBuilder{
|
out := protoimpl.TypeBuilder{
|
||||||
@@ -451,7 +710,7 @@ func file_api_proto_init() {
|
|||||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||||
RawDescriptor: file_api_proto_rawDesc,
|
RawDescriptor: file_api_proto_rawDesc,
|
||||||
NumEnums: 0,
|
NumEnums: 0,
|
||||||
NumMessages: 6,
|
NumMessages: 9,
|
||||||
NumExtensions: 0,
|
NumExtensions: 0,
|
||||||
NumServices: 1,
|
NumServices: 1,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -5,9 +5,18 @@ option go_package = "hk4e/node/api;api";
|
|||||||
|
|
||||||
// 节点服务器注册发现服务
|
// 节点服务器注册发现服务
|
||||||
service Discovery {
|
service Discovery {
|
||||||
rpc RegisterServer (RegisterServerReq) returns (RegisterServerRsp) {} // 服务器启动注册获取appid
|
// 服务器启动注册获取appid
|
||||||
rpc GetServerAppId (GetServerAppIdReq) returns (GetServerAppIdRsp) {} // 随机获取某服务器的appid
|
rpc RegisterServer (RegisterServerReq) returns (RegisterServerRsp) {}
|
||||||
rpc GetRegionEc2b (NullMsg) returns (RegionEc2b) {} // 获取区服密钥信息
|
// 服务器关闭取消注册
|
||||||
|
rpc CancelServer (CancelServerReq) returns (NullMsg) {}
|
||||||
|
// 服务器在线心跳保持
|
||||||
|
rpc KeepaliveServer (KeepaliveServerReq) returns (NullMsg) {}
|
||||||
|
// 获取负载最小的服务器的appid
|
||||||
|
rpc GetServerAppId (GetServerAppIdReq) returns (GetServerAppIdRsp) {}
|
||||||
|
// 获取区服密钥信息
|
||||||
|
rpc GetRegionEc2b (NullMsg) returns (RegionEc2b) {}
|
||||||
|
// 获取负载最小的网关服务器的地址和端口
|
||||||
|
rpc GetGateServerAddr (NullMsg) returns (GateServerAddr) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
message NullMsg {
|
message NullMsg {
|
||||||
@@ -23,12 +32,29 @@ message GetServerAppIdRsp {
|
|||||||
|
|
||||||
message RegisterServerReq {
|
message RegisterServerReq {
|
||||||
string server_type = 1;
|
string server_type = 1;
|
||||||
|
GateServerAddr gate_server_addr = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message RegisterServerRsp {
|
message RegisterServerRsp {
|
||||||
string app_id = 1;
|
string app_id = 1;
|
||||||
|
uint32 gs_id = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message CancelServerReq {
|
||||||
|
string server_type = 1;
|
||||||
|
string app_id = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message KeepaliveServerReq {
|
||||||
|
string server_type = 1;
|
||||||
|
string app_id = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message RegionEc2b {
|
message RegionEc2b {
|
||||||
bytes data = 1;
|
bytes data = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message GateServerAddr {
|
||||||
|
string ip_addr = 1;
|
||||||
|
uint32 port = 2;
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync/atomic"
|
||||||
|
|
||||||
"hk4e/common/config"
|
|
||||||
"hk4e/common/region"
|
"hk4e/common/region"
|
||||||
"hk4e/node/api"
|
"hk4e/node/api"
|
||||||
"hk4e/pkg/logger"
|
"hk4e/pkg/logger"
|
||||||
@@ -15,9 +16,25 @@ import (
|
|||||||
|
|
||||||
var _ api.DiscoveryNATSRPCServer = (*DiscoveryService)(nil)
|
var _ api.DiscoveryNATSRPCServer = (*DiscoveryService)(nil)
|
||||||
|
|
||||||
|
type ServerInstanceSortList []*ServerInstance
|
||||||
|
|
||||||
|
func (s ServerInstanceSortList) Len() int {
|
||||||
|
return len(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s ServerInstanceSortList) Less(i, j int) bool {
|
||||||
|
return s[i].appId < s[j].appId
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s ServerInstanceSortList) Swap(i, j int) {
|
||||||
|
s[i], s[j] = s[j], s[i]
|
||||||
|
}
|
||||||
|
|
||||||
type ServerInstance struct {
|
type ServerInstance struct {
|
||||||
serverType string
|
serverType string
|
||||||
appId string
|
appId string
|
||||||
|
gateServerIpAddr string
|
||||||
|
gateServerPort uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
type DiscoveryService struct {
|
type DiscoveryService struct {
|
||||||
@@ -25,11 +42,12 @@ type DiscoveryService struct {
|
|||||||
// TODO 加锁
|
// TODO 加锁
|
||||||
serverInstanceMap map[string]map[string]*ServerInstance
|
serverInstanceMap map[string]map[string]*ServerInstance
|
||||||
serverAppIdMap map[string]bool
|
serverAppIdMap map[string]bool
|
||||||
|
gsIdCounter uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDiscoveryService() *DiscoveryService {
|
func NewDiscoveryService() *DiscoveryService {
|
||||||
r := new(DiscoveryService)
|
r := new(DiscoveryService)
|
||||||
_, _, r.regionEc2b = region.InitRegion(config.CONF.Hk4e.KcpAddr, config.CONF.Hk4e.KcpPort, nil)
|
r.regionEc2b = region.NewRegionEc2b()
|
||||||
logger.Info("region ec2b create ok, seed: %v", r.regionEc2b.Seed())
|
logger.Info("region ec2b create ok, seed: %v", r.regionEc2b.Seed())
|
||||||
r.serverInstanceMap = map[string]map[string]*ServerInstance{
|
r.serverInstanceMap = map[string]map[string]*ServerInstance{
|
||||||
api.GATE: make(map[string]*ServerInstance),
|
api.GATE: make(map[string]*ServerInstance),
|
||||||
@@ -38,9 +56,11 @@ func NewDiscoveryService() *DiscoveryService {
|
|||||||
api.PATHFINDING: make(map[string]*ServerInstance),
|
api.PATHFINDING: make(map[string]*ServerInstance),
|
||||||
}
|
}
|
||||||
r.serverAppIdMap = make(map[string]bool)
|
r.serverAppIdMap = make(map[string]bool)
|
||||||
|
r.gsIdCounter = 0
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RegisterServer 服务器启动注册获取appid
|
||||||
func (s *DiscoveryService) RegisterServer(ctx context.Context, req *api.RegisterServerReq) (*api.RegisterServerRsp, error) {
|
func (s *DiscoveryService) RegisterServer(ctx context.Context, req *api.RegisterServerReq) (*api.RegisterServerRsp, error) {
|
||||||
logger.Info("register new server, server type: %v", req.ServerType)
|
logger.Info("register new server, server type: %v", req.ServerType)
|
||||||
instMap, exist := s.serverInstanceMap[req.ServerType]
|
instMap, exist := s.serverInstanceMap[req.ServerType]
|
||||||
@@ -56,18 +76,59 @@ func (s *DiscoveryService) RegisterServer(ctx context.Context, req *api.Register
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
instMap[appId] = &ServerInstance{
|
inst := &ServerInstance{
|
||||||
serverType: req.ServerType,
|
serverType: req.ServerType,
|
||||||
appId: appId,
|
appId: appId,
|
||||||
}
|
}
|
||||||
|
if req.ServerType == api.GATE {
|
||||||
|
logger.Info("register new gate server, ip: %v, port: %v", req.GateServerAddr.IpAddr, req.GateServerAddr.Port)
|
||||||
|
inst.gateServerIpAddr = req.GateServerAddr.IpAddr
|
||||||
|
inst.gateServerPort = req.GateServerAddr.Port
|
||||||
|
}
|
||||||
|
instMap[appId] = inst
|
||||||
logger.Info("new server appid is: %v", appId)
|
logger.Info("new server appid is: %v", appId)
|
||||||
return &api.RegisterServerRsp{
|
rsp := &api.RegisterServerRsp{
|
||||||
AppId: appId,
|
AppId: appId,
|
||||||
}, nil
|
}
|
||||||
|
if req.ServerType == api.GS {
|
||||||
|
rsp.GsId = atomic.AddUint32(&s.gsIdCounter, 1)
|
||||||
|
}
|
||||||
|
return rsp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CancelServer 服务器关闭取消注册
|
||||||
|
func (s *DiscoveryService) CancelServer(ctx context.Context, req *api.CancelServerReq) (*api.NullMsg, error) {
|
||||||
|
logger.Info("server cancel, server type: %v, appid: %v", req.ServerType, req.AppId)
|
||||||
|
instMap, exist := s.serverInstanceMap[req.ServerType]
|
||||||
|
if !exist {
|
||||||
|
return nil, errors.New("server type not exist")
|
||||||
|
}
|
||||||
|
_, exist = instMap[req.AppId]
|
||||||
|
if !exist {
|
||||||
|
return nil, errors.New("server not exist")
|
||||||
|
}
|
||||||
|
delete(instMap, req.AppId)
|
||||||
|
return &api.NullMsg{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// KeepaliveServer 服务器在线心跳保持
|
||||||
|
func (s *DiscoveryService) KeepaliveServer(ctx context.Context, req *api.KeepaliveServerReq) (*api.NullMsg, error) {
|
||||||
|
instMap, exist := s.serverInstanceMap[req.ServerType]
|
||||||
|
if !exist {
|
||||||
|
return nil, errors.New("server type not exist")
|
||||||
|
}
|
||||||
|
inst, exist := instMap[req.AppId]
|
||||||
|
if !exist {
|
||||||
|
return nil, errors.New("server not exist")
|
||||||
|
}
|
||||||
|
// TODO
|
||||||
|
_ = inst
|
||||||
|
return &api.NullMsg{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetServerAppId 获取负载最小的服务器的appid
|
||||||
func (s *DiscoveryService) GetServerAppId(ctx context.Context, req *api.GetServerAppIdReq) (*api.GetServerAppIdRsp, error) {
|
func (s *DiscoveryService) GetServerAppId(ctx context.Context, req *api.GetServerAppIdReq) (*api.GetServerAppIdRsp, error) {
|
||||||
logger.Info("get server instance, server type: %v", req.ServerType)
|
logger.Debug("get server instance, server type: %v", req.ServerType)
|
||||||
instMap, exist := s.serverInstanceMap[req.ServerType]
|
instMap, exist := s.serverInstanceMap[req.ServerType]
|
||||||
if !exist {
|
if !exist {
|
||||||
return nil, errors.New("server type not exist")
|
return nil, errors.New("server type not exist")
|
||||||
@@ -75,20 +136,46 @@ func (s *DiscoveryService) GetServerAppId(ctx context.Context, req *api.GetServe
|
|||||||
if len(instMap) == 0 {
|
if len(instMap) == 0 {
|
||||||
return nil, errors.New("no server found")
|
return nil, errors.New("no server found")
|
||||||
}
|
}
|
||||||
var inst *ServerInstance = nil
|
inst := s.getRandomServerInstance(instMap)
|
||||||
for _, v := range instMap {
|
logger.Debug("get server appid is: %v", inst.appId)
|
||||||
inst = v
|
|
||||||
break
|
|
||||||
}
|
|
||||||
logger.Info("get server appid is: %v", inst.appId)
|
|
||||||
return &api.GetServerAppIdRsp{
|
return &api.GetServerAppIdRsp{
|
||||||
AppId: inst.appId,
|
AppId: inst.appId,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetRegionEc2B 获取区服密钥信息
|
||||||
func (s *DiscoveryService) GetRegionEc2B(ctx context.Context, req *api.NullMsg) (*api.RegionEc2B, error) {
|
func (s *DiscoveryService) GetRegionEc2B(ctx context.Context, req *api.NullMsg) (*api.RegionEc2B, error) {
|
||||||
logger.Info("get region ec2b ok")
|
logger.Info("get region ec2b ok")
|
||||||
return &api.RegionEc2B{
|
return &api.RegionEc2B{
|
||||||
Data: s.regionEc2b.Bytes(),
|
Data: s.regionEc2b.Bytes(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetGateServerAddr 获取负载最小的网关服务器的地址和端口
|
||||||
|
func (s *DiscoveryService) GetGateServerAddr(ctx context.Context, req *api.NullMsg) (*api.GateServerAddr, error) {
|
||||||
|
logger.Debug("get gate server addr")
|
||||||
|
instMap, exist := s.serverInstanceMap[api.GATE]
|
||||||
|
if !exist {
|
||||||
|
return nil, errors.New("gate server not exist")
|
||||||
|
}
|
||||||
|
if len(instMap) == 0 {
|
||||||
|
return nil, errors.New("no gate server found")
|
||||||
|
}
|
||||||
|
inst := s.getRandomServerInstance(instMap)
|
||||||
|
logger.Debug("get gate server addr is, ip: %v, port: %v", inst.gateServerIpAddr, inst.gateServerPort)
|
||||||
|
return &api.GateServerAddr{
|
||||||
|
IpAddr: inst.gateServerIpAddr,
|
||||||
|
Port: inst.gateServerPort,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *DiscoveryService) getRandomServerInstance(instMap map[string]*ServerInstance) *ServerInstance {
|
||||||
|
instList := make(ServerInstanceSortList, 0)
|
||||||
|
for _, v := range instMap {
|
||||||
|
instList = append(instList, v)
|
||||||
|
}
|
||||||
|
sort.Stable(instList)
|
||||||
|
index := random.GetRandomInt32(0, int32(len(instList)-1))
|
||||||
|
inst := instList[index]
|
||||||
|
return inst
|
||||||
|
}
|
||||||
|
|||||||
@@ -35,6 +35,12 @@ func Run(ctx context.Context, configFile string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
APPID = rsp.GetAppId()
|
APPID = rsp.GetAppId()
|
||||||
|
defer func() {
|
||||||
|
_, _ = client.Discovery.CancelServer(context.TODO(), &api.CancelServerReq{
|
||||||
|
ServerType: api.PATHFINDING,
|
||||||
|
AppId: APPID,
|
||||||
|
})
|
||||||
|
}()
|
||||||
|
|
||||||
logger.InitLogger("pathfinding_" + APPID)
|
logger.InitLogger("pathfinding_" + APPID)
|
||||||
logger.Warn("pathfinding start, appid: %v", APPID)
|
logger.Warn("pathfinding start, appid: %v", APPID)
|
||||||
|
|||||||
Reference in New Issue
Block a user