重构连接监听与处理代码逻辑,连接信息存储于全局通过接口展示

This commit is contained in:
2025-05-19 09:41:41 +08:00
parent aa967fbd6a
commit 24351e1c56
8 changed files with 126 additions and 67 deletions

View File

@@ -3,22 +3,14 @@ package fwd
import (
"context"
"log/slog"
"proxy-server/gateway/core"
"proxy-server/gateway/app"
"proxy-server/gateway/env"
"proxy-server/utils"
"sync"
)
type Service struct {
ctx context.Context
cancel context.CancelFunc
userConnMap core.SyncMap[string, *core.Conn]
fwdLesWg utils.CountWaitGroup
ctrlConnWg utils.CountWaitGroup
dataConnWg utils.CountWaitGroup
userConnWg utils.CountWaitGroup
}
func New() *Service {
@@ -41,7 +33,7 @@ func (s *Service) Run() error {
wg.Add(1)
go func() {
defer wg.Done()
err := s.listenCtrl()
err := ListenCtrl(s.ctx)
if err != nil {
slog.Error("fwd 控制通道监听发生错误", "err", err)
errQuit <- struct{}{}
@@ -53,7 +45,7 @@ func (s *Service) Run() error {
wg.Add(1)
go func() {
defer wg.Done()
err := s.listenData()
err := ListenData(s.ctx)
if err != nil {
slog.Error("fwd 数据通道监听发生错误", "err", err)
errQuit <- struct{}{}
@@ -70,10 +62,10 @@ func (s *Service) Run() error {
}
wg.Wait()
s.fwdLesWg.Wait()
s.ctrlConnWg.Wait()
s.userConnWg.Wait()
s.dataConnWg.Wait()
app.FwdLesWg.Wait()
app.CtrlConnWg.Wait()
app.UserConnWg.Wait()
app.DataConnWg.Wait()
return nil
}