0
mirror of https://github.com/XTLS/Xray-core.git synced 2025-06-14 04:19:36 +03: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:
yuhan6665
2024-06-29 14:32:57 -04:00
committed by GitHub
parent 8320732743
commit 079d0bd8a9
291 changed files with 1837 additions and 2368 deletions

View File

@ -5,6 +5,8 @@ import (
"net"
"syscall"
"unsafe"
"github.com/xtls/xray-core/common/errors"
)
const (
@ -29,7 +31,7 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf
if config.Interface != "" {
inf, err := net.InterfaceByName(config.Interface)
if err != nil {
return newError("failed to find the interface").Base(err)
return errors.New("failed to find the interface").Base(err)
}
isV4 := (network == "tcp4")
if isV4 {
@ -37,11 +39,11 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf
binary.BigEndian.PutUint32(bytes[:], uint32(inf.Index))
idx := *(*uint32)(unsafe.Pointer(&bytes[0]))
if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.IPPROTO_IP, IP_UNICAST_IF, int(idx)); err != nil {
return newError("failed to set IP_UNICAST_IF").Base(err)
return errors.New("failed to set IP_UNICAST_IF").Base(err)
}
} else {
if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.IPPROTO_IPV6, IPV6_UNICAST_IF, inf.Index); err != nil {
return newError("failed to set IPV6_UNICAST_IF").Base(err)
return errors.New("failed to set IPV6_UNICAST_IF").Base(err)
}
}
}
@ -52,16 +54,16 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf
}
if config.TcpKeepAliveIdle > 0 {
if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.SOL_SOCKET, syscall.SO_KEEPALIVE, 1); err != nil {
return newError("failed to set SO_KEEPALIVE", err)
return errors.New("failed to set SO_KEEPALIVE", err)
}
} else if config.TcpKeepAliveIdle < 0 {
if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.SOL_SOCKET, syscall.SO_KEEPALIVE, 0); err != nil {
return newError("failed to unset SO_KEEPALIVE", err)
return errors.New("failed to unset SO_KEEPALIVE", err)
}
}
if config.TcpNoDelay {
if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.IPPROTO_TCP, syscall.TCP_NODELAY, 1); err != nil {
return newError("failed to set TCP_NODELAY", err)
return errors.New("failed to set TCP_NODELAY", err)
}
}
}
@ -76,11 +78,11 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig)
}
if config.TcpKeepAliveIdle > 0 {
if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.SOL_SOCKET, syscall.SO_KEEPALIVE, 1); err != nil {
return newError("failed to set SO_KEEPALIVE", err)
return errors.New("failed to set SO_KEEPALIVE", err)
}
} else if config.TcpKeepAliveIdle < 0 {
if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.SOL_SOCKET, syscall.SO_KEEPALIVE, 0); err != nil {
return newError("failed to unset SO_KEEPALIVE", err)
return errors.New("failed to unset SO_KEEPALIVE", err)
}
}
}