Shitama 代码分析「holder 启动」
别看了,全是胡扯,我之前没认真读代码
这是开头
因为按逻辑上,shitama 的运行顺序应该是 「holder 启动」、「shard 启动」、「client 启动」和 「链接建立」。我也就先按照这个来分析。
结构
目录结构
holder
├── lib
│ ├── clientInfo.go
│ ├── holder.go
│ ├── server.go
│ ├── shardInfo.go
│ └── tunnel.go
└── main.go
结构体结构
./lib/holder.go
type Holder struct {
logger *logrus.Logger
Tunnel *Tunnel
Server *Server
shards []ShardInfo
clients []ClientInfo
}
./lib/tunnel.go
type Tunnel struct {
OnConnected EventBus.Bus
OnDisconnected EventBus.Bus
OnRequestReceived EventBus.Bus
OnPublishReceived EventBus.Bus
OnPeerConnected EventBus.Bus
OnPeerDisconnected EventBus.Bus
parent *Holder
}
./lib/server.go
type Server struct {
parent *Holder
}
./lib/shardInfo.go
type ShardInfo struct {
common.ShardInfo
conn *kcp.UDPSession
session *yamux.Session
}
../common/shardInfo.go
type ShardInfo struct {
Addr string `json:"addr"`
IP string `json:"ip"`
EchoPort int `json:"echoPort"`
}
./lib/clientInfo.go
type ClientInfo struct {
common.ClientInfo
conn *kcp.UDPSession
session *yamux.Session
}
../common/clientInfo.go
type ClientInfo struct {
Addr string `json:"addr"`
}
holder 启动时函数调用顺序