优化全局数据存储方式,以节点 id 为 key 保存相关数据;修复节点下线监听未关闭问题
This commit is contained in:
@@ -4,14 +4,18 @@ import (
|
||||
"proxy-server/gateway/core"
|
||||
)
|
||||
|
||||
type Stoppable interface {
|
||||
Stop()
|
||||
}
|
||||
|
||||
var (
|
||||
Id int32
|
||||
Name string
|
||||
PlatformSecret string // 平台密钥,验证接收的请求是否属于平台
|
||||
|
||||
Edges = core.SyncMap[int32, uint16]{} // 节点 ID -> 转发端口
|
||||
Assigns = core.SyncMap[uint16, int32]{} // 转发端口 -> 节点 ID
|
||||
Permits = core.SyncMap[uint16, *core.Permit]{} // 转发端口 -> 权限配置
|
||||
Assigns = core.SyncMap[uint16, int32]{} // 转发端口 -> 节点 ID
|
||||
Edges = core.SyncMap[int32, uint16]{} // 节点 ID -> 转发端口
|
||||
Permits = core.SyncMap[int32, *core.Permit]{} // 转发端口 -> 权限配置
|
||||
)
|
||||
|
||||
func AddEdge(id int32, port uint16) {
|
||||
@@ -22,9 +26,19 @@ func AddEdge(id int32, port uint16) {
|
||||
func DelEdge(port uint16) {
|
||||
id, _ := Assigns.LoadAndDelete(port)
|
||||
Edges.Delete(id)
|
||||
Permits.Delete(port)
|
||||
Permits.Delete(id)
|
||||
}
|
||||
|
||||
func PermitEdge(port uint16, permit *core.Permit) {
|
||||
Permits.Store(port, permit)
|
||||
func LoadPermit(port uint16) *core.Permit {
|
||||
id, ok := Assigns.Load(port)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
permit, ok := Permits.Load(id)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
return permit
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user