准备测试环境代码

This commit is contained in:
2025-02-25 18:08:57 +08:00
parent 884faae5ba
commit b50dc3d91c
6 changed files with 568 additions and 223 deletions

View File

@@ -163,14 +163,14 @@ func (s *Service) processCtrlConn(controller net.Conn) {
},
})
if err != nil {
slog.Error("代理服务创建失败", err)
slog.Error("代理服务创建失败", "err", err)
return
}
go func() {
err := proxy.Run()
if err != nil {
slog.Error("代理服务建立失败", err)
slog.Error("代理服务建立失败", "err", err)
return
}
}()
@@ -181,13 +181,13 @@ func (s *Service) processCtrlConn(controller net.Conn) {
tag := user.Tag()
_, err := controller.Write([]byte{byte(len(tag))})
if err != nil {
slog.Error("write error", err)
slog.Error("write error", "err", err)
return
}
_, err = controller.Write([]byte(tag))
slog.Info("已通知客户端建立数据通道")
if err != nil {
slog.Error("write error", err)
slog.Error("write error", "err", err)
return
}
s.connMap[tag] = user
@@ -201,7 +201,7 @@ func (s *Service) startDataTun(ctx context.Context, errCh chan error) {
// 监听端口
lData, err := net.Listen("tcp", ":"+strconv.Itoa(int(dataPort)))
if err != nil {
slog.Error("listen error", err)
slog.Error("listen error", "err", err)
return
}
defer utils.Close(lData)
@@ -255,12 +255,12 @@ func (s *Service) processDataConn(client net.Conn) {
// 读取 tag
tagLen, err := utils.ReadByte(client)
if err != nil {
slog.Error("read error", err)
slog.Error("read error", "err", err)
return
}
tagBuf, err := utils.ReadBuffer(client, int(tagLen))
if err != nil {
slog.Error("read error", err)
slog.Error("read error", "err", err)
return
}
tag := string(tagBuf)
@@ -280,12 +280,12 @@ func (s *Service) processDataConn(client net.Conn) {
// 写入目标地址
_, err = client.Write([]byte{byte(len(data.Dest))})
if err != nil {
slog.Error("写入目标地址失败", err)
slog.Error("写入目标地址失败", "err", err)
return
}
_, err = client.Write([]byte(data.Dest))
if err != nil {
slog.Error("写入目标地址失败", err)
slog.Error("写入目标地址失败", "err", err)
return
}
@@ -295,14 +295,14 @@ func (s *Service) processDataConn(client net.Conn) {
go func() {
_, err := io.Copy(client, user)
if err != nil {
slog.Error("processDataConn error c2u", err)
slog.Error("processDataConn error c2u", "err", err)
}
errCh <- err
}()
go func() {
_, err := io.Copy(user, client)
if err != nil {
slog.Error("processDataConn error u2c", err)
slog.Error("processDataConn error u2c", "err", err)
}
errCh <- err
}()
@@ -366,7 +366,8 @@ func (a *NoAuthAuthenticator) Authenticate(ctx context.Context, reader io.Reader
}
// 检查权限是否过期
timeout := uint(channel.Expiration.Sub(time.Now()).Seconds())
timeout := channel.Expiration.Sub(time.Now()).Seconds()
slog.Info("用户剩余时间", "timeout", timeout)
if timeout <= 0 {
return nil, errors.New("noAuth 权限已过期")
}
@@ -374,7 +375,7 @@ func (a *NoAuthAuthenticator) Authenticate(ctx context.Context, reader io.Reader
return &socks5.AuthContext{
Method: socks5.NoAuth,
Timeout: timeout,
Timeout: uint(timeout),
Payload: nil,
}, nil
}
@@ -443,7 +444,8 @@ func (a *UserPassAuthenticator) Authenticate(ctx context.Context, reader io.Read
}
// 检查权限是否过期
timeout := uint(channel.Expiration.Sub(time.Now()).Seconds())
timeout := channel.Expiration.Sub(time.Now()).Seconds()
slog.Info("用户剩余时间", "timeout", timeout)
if timeout <= 0 {
return nil, errors.New("权限已过期")
}
@@ -484,13 +486,13 @@ func (a *UserPassAuthenticator) Authenticate(ctx context.Context, reader io.Read
// 响应认证成功
_, err = writer.Write([]byte{socks5.AuthVersion, socks5.AuthSuccess})
if err != nil {
slog.Error("响应认证失败", err)
slog.Error("响应认证失败", "err", err)
return nil, err
}
return &socks5.AuthContext{
Method: socks5.UserPassAuth,
Timeout: 300, // todo
Timeout: uint(timeout),
Payload: nil,
}, nil
}