This repository has been archived by the owner on Jun 23, 2022. It is now read-only.
/
main.go
69 lines (55 loc) · 1.6 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"github.com/davyxu/cellmesh/demo/basefx"
"github.com/davyxu/cellmesh/demo/basefx/model"
_ "github.com/davyxu/cellmesh/demo/proto" // 进入协议
_ "github.com/davyxu/cellmesh/demo/svc/agent/backend"
"github.com/davyxu/cellmesh/demo/svc/agent/frontend"
"github.com/davyxu/cellmesh/demo/svc/agent/heartbeat"
"github.com/davyxu/cellmesh/demo/svc/agent/model"
"github.com/davyxu/cellmesh/demo/svc/agent/routerule"
"github.com/davyxu/cellmesh/demo/svc/hub/api"
"github.com/davyxu/cellmesh/demo/svc/hub/status"
"github.com/davyxu/cellmesh/service"
_ "github.com/davyxu/cellnet/peer/gorillaws"
"github.com/davyxu/golog"
"time"
)
var log = golog.New("main")
func main() {
basefx.Init("agent")
routerule.Download()
heartbeat.StartCheck()
model.AgentSvcID = service.GetLocalSvcID()
// 要连接的服务列表
basefx.CreateCommnicateConnector(fxmodel.ServiceParameter{
SvcName: "game",
MaxConnCount: -1,
NetProcName: "agent.backend",
})
switch *fxmodel.FlagCommunicateType {
case "tcp":
frontend.Start(model.FrontendParameter{
SvcName: "agent",
ListenAddr: ":0",
NetPeerType: "tcp.Acceptor",
NetProcName: "tcp.frontend",
})
case "ws":
frontend.Start(model.FrontendParameter{
SvcName: "agent",
ListenAddr: ":0",
NetPeerType: "gorillaws.Acceptor",
NetProcName: "ws.frontend",
})
}
hubapi.ConnectToHub(func() {
// 发送网关连接数量
hubstatus.StartSendStatus("agent_status", time.Second*3, func() int {
return model.FrontendSessionManager.SessionCount()
})
})
basefx.StartLoop(nil)
frontend.Stop()
basefx.Exit()
}