现在已注册的节点会检查并更新 host;修复一个导致断开的连接没有正常退出的问题
This commit is contained in:
@@ -107,7 +107,7 @@ func processCtrlConn(_ctx context.Context, conn net.Conn) (err error) {
|
||||
}
|
||||
|
||||
cmd, err := reader.ReadByte()
|
||||
if err := utils.WarpConnErr(err); err != nil {
|
||||
if ok, err := utils.WarpConnErr(err); !ok {
|
||||
errCh <- err
|
||||
return
|
||||
}
|
||||
@@ -169,12 +169,14 @@ func processCtrlConn(_ctx context.Context, conn net.Conn) (err error) {
|
||||
}
|
||||
|
||||
func onOpen(ctx context.Context, writer io.Writer, edgeId int32, addr net.Addr) (err error) {
|
||||
var port uint16
|
||||
tcpAddr, ok := addr.(*net.TCPAddr)
|
||||
if !ok {
|
||||
return fmt.Errorf("无效的地址类型: %T", addr)
|
||||
}
|
||||
|
||||
var port uint16
|
||||
edge, ok := app.Edges.Load(edgeId)
|
||||
if ok && edge.Port != nil {
|
||||
port = *edge.Port
|
||||
} else {
|
||||
if !ok || edge.Port == nil {
|
||||
// 分配端口
|
||||
app.LockPortAssign.Lock()
|
||||
|
||||
@@ -191,13 +193,16 @@ func onOpen(ctx context.Context, writer io.Writer, edgeId int32, addr net.Addr)
|
||||
return errors.New("没有可用的端口")
|
||||
}
|
||||
|
||||
if tcpAddr, ok := addr.(*net.TCPAddr); ok {
|
||||
app.NewEdge(edgeId, port, tcpAddr)
|
||||
} else {
|
||||
return fmt.Errorf("无效的地址类型: %T", addr)
|
||||
}
|
||||
app.NewEdge(edgeId, port, tcpAddr)
|
||||
|
||||
app.LockPortAssign.Unlock()
|
||||
} else {
|
||||
// 更新边缘节点地址
|
||||
port = *edge.Port
|
||||
err := app.TryUpdateEdge(edgeId, tcpAddr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("尝试更新边缘节点地址失败: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// 启动转发服务
|
||||
|
||||
Reference in New Issue
Block a user