Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vagrant lab #16

Draft
wants to merge 26 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c407c75
feat: add all dependency
Vagrant-Zero Sep 28, 2023
67c1f3d
feat: add discovery and endport calculate
Vagrant-Zero Sep 30, 2023
f7602a2
feat: ipconf dispatch server
Vagrant-Zero Sep 30, 2023
f217ea3
gateway epoll server
Vagrant-Zero Oct 6, 2023
c81d6d1
improve gateway epoll server
Vagrant-Zero Oct 6, 2023
32cb764
fix: 修复etcd watch可能漏数据问
Vagrant-Zero Oct 21, 2023
3a664b5
fix: add prpc client and prpc server
Vagrant-Zero Oct 21, 2023
aae8cc7
fix: etcd dependency
Vagrant-Zero Oct 29, 2023
4eaee12
feat: add gateway proto
Vagrant-Zero Oct 29, 2023
65d6e84
fix: rpc server interceptors
Vagrant-Zero Oct 29, 2023
19d0801
fix: add state server
Vagrant-Zero Nov 5, 2023
42f279e
add zap logger
Vagrant-Zero Nov 12, 2023
f837837
add zap logger
Vagrant-Zero Nov 12, 2023
0ebb2c3
add timingWheel
Vagrant-Zero Dec 31, 2023
fab2d2d
add connection available
Vagrant-Zero Jan 1, 2024
ad72717
fix config
Vagrant-Zero Jan 1, 2024
1d967bf
feat: update readme and net
Vagrant-Zero Jan 9, 2024
39ef3d2
feat: add server msg fsm
Vagrant-Zero Feb 9, 2024
a013b2c
feat: improve msg reliability
Vagrant-Zero Feb 28, 2024
cf1592e
feat: state decentralized
Vagrant-Zero May 2, 2024
a765d45
feat: [state decentralize]fix redis lua bug and decrease slot number
Vagrant-Zero May 2, 2024
c6b10ec
feat: add dockerfile & docker-compose & start.sh
Vagrant-Zero Jun 2, 2024
8291b4b
feat: add build Makefile
Vagrant-Zero Jun 2, 2024
9594ad1
feat: add build Makefile
Vagrant-Zero Jun 2, 2024
258fb54
feat: add docker-compose.yaml
Vagrant-Zero Jun 2, 2024
0dcf1fe
feat: add log
Vagrant-Zero Jun 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 使用官方的 Go 镜像作为基础镜像
FROM golang:1.20 AS builder

# 设置工作目录
WORKDIR /app

# 拷贝 Go 项目代码到容器中
COPY . .

# 为 Linux 构建 plato 可执行文件
# 为了在mac上能够执行,指定了 GOOS=linux GOARCH=amd64
# 其他linux环境编译时不需要添加该命令,直接 go build -o plato . 即可
RUN GOOS=linux GOARCH=amd64 go build -o plato .


# 创建最终的生产环境镜像
FROM alpine:latest

# 设置工作目录
WORKDIR /app

# 拷贝构建好的可执行文件到生产镜像中
COPY --from=builder /app/plato .

# 赋予 plato-gateway 和 plato-state 可执行权限
RUN #chmod +x ./plato-gateway && chmod +x ./plato-state
RUN chmod +x ./plato

# 拷贝项目的配置文件到容器中
COPY ./plato.yaml .

# 声明 gateway 服务运行时监听的端口
EXPOSE 8900
EXPOSE 8901

# 声明 state 服务运行时监听的端口
EXPOSE 8902

# 启动应用程序
#CMD ["./plato gateway"]
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
all:build

build:
@echo "go build plato begin"
go build -o plato .
@echo "go build plato success"
45 changes: 41 additions & 4 deletions chat.log
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
me: hello
logic: hello
me: 你好! plato
logic: 你好! plato
me-clientID:0: 123
logic: 123
me-clientID:0: 345566
me-clientID:1: sadklasjdl
logic: sadklasjdl
me-clientID:2: sdksajdlsa
logic: sdksajdlsa
me-clientID:3: djsalkjdlsa
logic: djsalkjdlsa
me-clientID:4: dhaskljdlks
logic: dhaskljdlks
me-clientID:5: dhjakshdks
logic: dhjakshdks
me-clientID:6: dhjksahdks
logic: dhjksahdks
me-clientID:7: 123daksjdklas
logic: 123daksjdklas
me-clientID:8: dmaklsdklsa
logic: dmaklsdklsa
me-clientID:9: dmksamdlsa
logic: dmksamdlsa
me-clientID:10: dals;dk;asd
logic: dals;dk;asd
me-clientID:11: dhaskjhdkasdk
logic: dhaskjhdkasdk
me-clientID:12: sdklajdklsad
logic: sdklajdklsad
me-clientID:13: djaslkdlsa
logic: djaslkdlsa
me-clientID:14: asdkljsaljdslajd
logic: asdkljsaljdslajd
me-clientID:15: djskahdkhsakd
logic: djskahdkhsakd
me-clientID:16: dklasjdklsajkld
logic: dklasjdklsajkld
me-clientID:17: djklsajdlsajdl
logic: djklsajdlsajdl
me-clientID:18: djaksljdlasdjl
logic: djaksljdlasdjl
me-clientID:19: djaslkjdlas
logic: djaslkjdlas

32 changes: 23 additions & 9 deletions client/cui.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package client

import (
"fmt"
"github.com/hardcore-os/plato/common/sdk"
"io/ioutil"
"log"
"math/rand"
"net"
"time"

"github.com/gookit/color"
"github.com/hardcore-os/plato/client/sdk"
"github.com/rocket049/gocui"
)

Expand Down Expand Up @@ -59,16 +60,19 @@ func viewPrint(g *gocui.Gui, name, msg string, newline bool) {
g.Update(out.Show)
}

//doRecv work in goroutine
// doRecv work in goroutine
func doRecv(g *gocui.Gui) {
recvChannel := chat.Recv()
for msg := range recvChannel {
switch msg.Type {
case sdk.MsgTypeText:
viewPrint(g, msg.Name, msg.Content, false)
if msg != nil {
switch msg.Type {
case sdk.MsgTypeText:
viewPrint(g, msg.Name, msg.Content, false)
case sdk.MsgTypeAck:
//TODO 默认不处理
}
}
}
g.Close()
}

func quit(g *gocui.Gui, v *gocui.View) error {
Expand All @@ -91,7 +95,8 @@ func doSay(g *gocui.Gui, cv *gocui.View) {
ToUserID: "222222",
Content: string(p)}
// 先把自己说的话显示到消息流中
viewPrint(g, "me", msg.Content, false)
idKey := fmt.Sprintf("%d", chat.GetCurClientID())
viewPrint(g, "me-clientID:"+idKey, msg.Content, false)
chat.Send(msg)
}
v.Autoscroll = true
Expand Down Expand Up @@ -168,7 +173,7 @@ func viewHead(g *gocui.Gui, x0, y0, x1, y1 int) error {
}
v.Wrap = false
v.Overwrite = true
msg := "开始聊天了!"
msg := "Plato: IM系统聊天对话框"
setHeadText(g, msg)
}
return nil
Expand Down Expand Up @@ -223,7 +228,7 @@ func pasteDown(g *gocui.Gui, cv *gocui.View) error {

func RunMain() {
// step1 创建caht的核心对象
chat = sdk.NewChat("127.0.0.1:8080", "logic", "12312321", "2131")
chat = sdk.NewChat(net.ParseIP("0.0.0.0"), 8900, "logic", "12312321", "2131")
// step2 创建 GUI 图层对象并进行参与与回调函数的配置
g, err := gocui.NewGui(gocui.OutputNormal)
if err != nil {
Expand Down Expand Up @@ -256,6 +261,15 @@ func RunMain() {
if err := g.SetKeybinding("main", gocui.KeyArrowUp, gocui.ModNone, pasteUP); err != nil {
log.Panicln(err)
}

// emit disconnection
//go func() {
// time.Sleep(10 * time.Second)
// // reconnection
// chat.ReConn()
// go doRecv(g)
//}()

// 启动消费函数
go doRecv(g)
if err := g.MainLoop(); err != nil {
Expand Down
43 changes: 0 additions & 43 deletions client/sdk/api.go

This file was deleted.

1 change: 0 additions & 1 deletion client/sdk/logic.go

This file was deleted.

27 changes: 0 additions & 27 deletions client/sdk/net.go

This file was deleted.

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

import (
"github.com/hardcore-os/plato/gateway"
"github.com/spf13/cobra"
)

func init() {
rootCmd.AddCommand(gatewayCmd)
}

var gatewayCmd = &cobra.Command{
Use: "gateway",
Run: GatewayHandle,
}

func GatewayHandle(cmd *cobra.Command, args []string) {
gateway.RunMain(ConfigPath)
}
19 changes: 19 additions & 0 deletions cmd/ipconf.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cmd

import (
"github.com/hardcore-os/plato/ipconf"
"github.com/spf13/cobra"
)

func init() {
rootCmd.AddCommand(ipConfCmd)
}

var ipConfCmd = &cobra.Command{
Use: "ipconf",
Run: IpConfHandle,
}

func IpConfHandle(cmd *cobra.Command, args []string) {
ipconf.RunMain(ConfigPath)
}
20 changes: 20 additions & 0 deletions cmd/perf.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cmd

import (
"github.com/hardcore-os/plato/perf"
"github.com/spf13/cobra"
)

func init() {
rootCmd.AddCommand(perfCmd)
perfCmd.PersistentFlags().Int32Var(&perf.TcpConnNum, "tcp_conn_num", 10000, "tcp 连接的数量,默认10000")
}

var perfCmd = &cobra.Command{
Use: "perf",
Run: PerfHandle,
}

func PerfHandle(cmd *cobra.Command, args []string) {
perf.RunMain()
}
10 changes: 10 additions & 0 deletions cmd/plato.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,18 @@ import (
"github.com/spf13/cobra"
)

var (
ConfigPath string
)

func init() {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringVar(
&ConfigPath,
"config",
"./plato.yaml",
"config file (default is ./plato.yaml)",
)
}

var rootCmd = &cobra.Command{
Expand Down
19 changes: 19 additions & 0 deletions cmd/state.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cmd

import (
"github.com/hardcore-os/plato/state"
"github.com/spf13/cobra"
)

func init() {
rootCmd.AddCommand(stateCmd)
}

var stateCmd = &cobra.Command{
Use: "state",
Run: StateHandle,
}

func StateHandle(cmd *cobra.Command, args []string) {
state.RunMain(ConfigPath)
}
10 changes: 10 additions & 0 deletions common/cache/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package cache

import "time"

const (
MaxClientIDKey = "max_client_id_{%d}_%d" // slot_connID
LastMsgKey = "last_msg_{%d}_%d" // slot_connID
LoginSlotSetKey = "login_slot_set_{%d}" // 通过 hash tag保证在cluster模式上 key都在一个shard上 // slot
TTL7D = 7 * 24 * time.Hour
)
Loading