优化全局数据存储方式,以节点 id 为 key 保存相关数据;修复节点下线监听未关闭问题
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"proxy-server/gateway/core"
|
||||
@@ -14,25 +15,33 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func (s *Service) listenUser(port uint16, ctrl io.Writer) error {
|
||||
func (s *Service) listenUser(ctx context.Context, port uint16, ctrl io.Writer) error {
|
||||
dspt, err := dispatcher.New(port, time.Duration(env.AppUserTimeout)*time.Second)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer dspt.Close()
|
||||
defer dspt.Stop()
|
||||
|
||||
var errCh = make(chan error)
|
||||
go func() {
|
||||
err := dspt.Run()
|
||||
if err != nil {
|
||||
slog.Error("代理服务运行失败", "err", err)
|
||||
// slog.Error("代理服务运行失败", "err", err)
|
||||
err = fmt.Errorf("协议嗅探服务运行失败: %w", err)
|
||||
}
|
||||
errCh <- err
|
||||
}()
|
||||
|
||||
// 处理连接
|
||||
for {
|
||||
select {
|
||||
case <-s.ctx.Done():
|
||||
case <-ctx.Done():
|
||||
return nil
|
||||
case err := <-errCh:
|
||||
if err != nil {
|
||||
err = fmt.Errorf("监听转发端口失败: %w", err)
|
||||
}
|
||||
return err
|
||||
case user := <-dspt.Conn:
|
||||
metrics.TimerAuth.Store(user.Conn, time.Now())
|
||||
s.userConnWg.Add(1)
|
||||
|
||||
Reference in New Issue
Block a user