mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-08-24 10:36:49 +08:00
Refactor log (#3446)
* Refactor log * Add new log methods * Fix logger test * Change all logging code * Clean up pathObj * Rebase to latest main * Remove invoking method name after the dot
This commit is contained in:
@@ -4,9 +4,11 @@
|
||||
package tcp
|
||||
|
||||
import (
|
||||
"context"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/transport/internet/stat"
|
||||
)
|
||||
@@ -16,11 +18,11 @@ const SO_ORIGINAL_DST = 80
|
||||
func GetOriginalDestination(conn stat.Connection) (net.Destination, error) {
|
||||
sysrawconn, f := conn.(syscall.Conn)
|
||||
if !f {
|
||||
return net.Destination{}, newError("unable to get syscall.Conn")
|
||||
return net.Destination{}, errors.New("unable to get syscall.Conn")
|
||||
}
|
||||
rawConn, err := sysrawconn.SyscallConn()
|
||||
if err != nil {
|
||||
return net.Destination{}, newError("failed to get sys fd").Base(err)
|
||||
return net.Destination{}, errors.New("failed to get sys fd").Base(err)
|
||||
}
|
||||
var dest net.Destination
|
||||
err = rawConn.Control(func(fd uintptr) {
|
||||
@@ -30,7 +32,7 @@ func GetOriginalDestination(conn stat.Connection) (net.Destination, error) {
|
||||
}
|
||||
addr, err := syscall.GetsockoptIPv6MTUInfo(int(fd), level, SO_ORIGINAL_DST)
|
||||
if err != nil {
|
||||
newError("failed to call getsockopt").Base(err).WriteToLog()
|
||||
errors.LogInfoInner(context.Background(), err, "failed to call getsockopt")
|
||||
return
|
||||
}
|
||||
ip := (*[4]byte)(unsafe.Pointer(&addr.Addr.Flowinfo))[:4]
|
||||
@@ -41,10 +43,10 @@ func GetOriginalDestination(conn stat.Connection) (net.Destination, error) {
|
||||
dest = net.TCPDestination(net.IPAddress(ip), net.PortFromBytes(port))
|
||||
})
|
||||
if err != nil {
|
||||
return net.Destination{}, newError("failed to control connection").Base(err)
|
||||
return net.Destination{}, errors.New("failed to control connection").Base(err)
|
||||
}
|
||||
if !dest.IsValid() {
|
||||
return net.Destination{}, newError("failed to call getsockopt")
|
||||
return net.Destination{}, errors.New("failed to call getsockopt")
|
||||
}
|
||||
return dest, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user