优化数据分析和日志记录,重构连接管理,添加对空缓冲区的处理
This commit is contained in:
@@ -49,27 +49,6 @@ type AddrSpec struct {
|
||||
Port int
|
||||
}
|
||||
|
||||
func (a AddrSpec) Domain() []string {
|
||||
if a.FQDN != "" {
|
||||
return []string{a.FQDN}
|
||||
}
|
||||
|
||||
var domain []string
|
||||
|
||||
ch := make(chan struct{})
|
||||
defer close(ch)
|
||||
go func() {
|
||||
addr, err := net.LookupAddr(a.IP.String())
|
||||
if err == nil {
|
||||
domain = addr
|
||||
}
|
||||
ch <- struct{}{}
|
||||
}()
|
||||
<-ch
|
||||
|
||||
return domain
|
||||
}
|
||||
|
||||
func (a AddrSpec) String() string {
|
||||
if a.FQDN != "" {
|
||||
return fmt.Sprintf("%s (%s):%d", a.FQDN, a.IP, a.Port)
|
||||
@@ -258,7 +237,11 @@ func (s *Server) handleConnect(ctx context.Context, conn net.Conn, req *Request)
|
||||
if conn != nil {
|
||||
utils.Close(conn)
|
||||
}
|
||||
case s.Conn <- ProxyConn{conn, req.realDestAddr.Address()}:
|
||||
case s.Conn <- ProxyConn{
|
||||
req.Authentication.Payload.ID,
|
||||
conn,
|
||||
req.realDestAddr.Address(),
|
||||
}:
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -352,6 +335,7 @@ func SendSuccess(user net.Conn, target net.Conn) error {
|
||||
}
|
||||
|
||||
type ProxyConn struct {
|
||||
Uid uint
|
||||
// 用户连入的连接
|
||||
Conn net.Conn
|
||||
// 用户目标地址
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"os"
|
||||
"proxy-server/pkg/utils"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -191,18 +190,6 @@ func (s *Server) process(conn net.Conn) error {
|
||||
slog.Debug("连接请求处理完成")
|
||||
}
|
||||
|
||||
// 记录日志
|
||||
go func() {
|
||||
slog.Info(
|
||||
"用户访问记录",
|
||||
slog.Uint64("uid", uint64(authContext.Payload.ID)),
|
||||
slog.String("user", conn.RemoteAddr().String()),
|
||||
slog.Any("node", conn.LocalAddr().String()),
|
||||
slog.String("dest", request.DestAddr.Address()),
|
||||
slog.String("domain", strings.Join(request.DestAddr.Domain(), ",")),
|
||||
)
|
||||
}()
|
||||
|
||||
request.Authentication = authContext
|
||||
user, ok := conn.RemoteAddr().(*net.TCPAddr)
|
||||
if !ok {
|
||||
|
||||
Reference in New Issue
Block a user