Xray-core: Reduce error log usage for performance (#6796)

https://github.com/XTLS/Xray-core/pull/6796#issuecomment-5807809588
This commit is contained in:
风扇滑翔翼 authored and RPRX committed 2026-09-25 17:59:49 +00:00
1 parent a642a190ed
commit 61cad5ec8b
60 files changed
+210 -272

No files matched your search

+1 -1
View File
@@ -27,7 +27,7 @@ var strategy = [11][3]byte{
func RegisterProtocolConfigCreator(name string, creator ConfigCreator) error {
if _, found := globalTransportConfigCreatorCache[name]; found {
return errors.New("protocol ", name, " is already registered").AtError()
return errors.New("protocol ", name, " is already registered")
}
globalTransportConfigCreatorCache[name] = creator
return nil
+6 -6
View File
@@ -38,7 +38,7 @@ var transportDialerCache = make(map[string]dialFunc)
// RegisterTransportDialer registers a Dialer with given name.
func RegisterTransportDialer(protocol string, dialer dialFunc) error {
if _, found := transportDialerCache[protocol]; found {
return errors.New(protocol, " dialer already registered").AtError()
return errors.New(protocol, " dialer already registered")
}
transportDialerCache[protocol] = dialer
return nil
@@ -58,7 +58,7 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *MemoryStrea
protocol := streamSettings.ProtocolName
dialer := transportDialerCache[protocol]
if dialer == nil {
return nil, errors.New(protocol, " dialer not registered").AtError()
return nil, errors.New(protocol, " dialer not registered")
}
return dialer(ctx, dest, streamSettings)
}
@@ -66,7 +66,7 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *MemoryStrea
if dest.Network == net.Network_UDP {
udpDialer := transportDialerCache["udp"]
if udpDialer == nil {
return nil, errors.New("UDP dialer not registered").AtError()
return nil, errors.New("UDP dialer not registered")
}
return udpDialer(ctx, dest, streamSettings)
}
@@ -86,7 +86,7 @@ var (
func LookupForIP(domain string, strategy DomainStrategy, localAddr net.Address) ([]net.IP, error) {
if dnsClient == nil {
return nil, errors.New("DNS client not initialized").AtError()
return nil, errors.New("DNS client not initialized")
}
ips, _, err := dnsClient.LookupIP(domain, dns.IPOption{
@@ -269,11 +269,11 @@ func DialSystem(ctx context.Context, dest net.Destination, sockopt *SocketConfig
if len(sockopt.DialerProxy) > 0 {
if obm == nil {
return nil, errors.New("there is no outbound manager for dialerProxy").AtError()
return nil, errors.New("there is no outbound manager for dialerProxy")
}
h := obm.GetHandler(sockopt.DialerProxy)
if h == nil {
return nil, errors.New("there is no outbound handler for dialerProxy").AtError()
return nil, errors.New("there is no outbound handler for dialerProxy")
}
return redirect(ctx, dest, sockopt.DialerProxy, h), nil
}
+1 -1
View File
@@ -57,7 +57,7 @@ func DialKCP(ctx context.Context, dest net.Destination, streamSettings *internet
conn, err = internet.DialSystem(ctx, dest, streamSettings.SocketSettings)
}
if err != nil {
return nil, errors.New("failed to dial to dest: ", err).AtWarning().Base(err)
return nil, errors.New("failed to dial to dest: ", err).Base(err)
}
kcpSettings := streamSettings.ProtocolSettings.(*Config)
+2 -2
View File
@@ -132,7 +132,7 @@ func UClient(c net.Conn, config *Config, ctx context.Context, dest net.Destinati
uConn.ServerName = utlsConfig.ServerName
fingerprint := tls.GetFingerprint(config.Fingerprint)
if fingerprint == nil {
return nil, errors.New("REALITY: failed to get fingerprint").AtError()
return nil, errors.New("REALITY: failed to get fingerprint")
}
uConn.UConn = utls.UClient(c, utlsConfig, *fingerprint)
{
@@ -271,7 +271,7 @@ func UClient(c net.Conn, config *Config, ctx context.Context, dest net.Destinati
// Do not close the connection
}()
time.Sleep(time.Duration(crypto.RandBetween(config.SpiderY[8], config.SpiderY[9])) * time.Millisecond) // return
return nil, errors.New("REALITY: processed invalid connection").AtWarning()
return nil, errors.New("REALITY: processed invalid connection")
}
return uConn, nil
}
+2 -2
View File
@@ -288,14 +288,14 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig)
func setReuseAddr(fd uintptr) error {
if err := unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEADDR, 1); err != nil {
return errors.New("failed to set SO_REUSEADDR").Base(err).AtWarning()
return errors.New("failed to set SO_REUSEADDR").Base(err)
}
return nil
}
func setReusePort(fd uintptr) error {
if err := unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1); err != nil {
return errors.New("failed to set SO_REUSEPORT").Base(err).AtWarning()
return errors.New("failed to set SO_REUSEPORT").Base(err)
}
return nil
}
+2 -2
View File
@@ -224,7 +224,7 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig)
func setReuseAddr(fd uintptr) error {
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1); err != nil {
return errors.New("failed to set SO_REUSEADDR").Base(err).AtWarning()
return errors.New("failed to set SO_REUSEADDR").Base(err)
}
return nil
}
@@ -232,7 +232,7 @@ func setReuseAddr(fd uintptr) error {
func setReusePort(fd uintptr) error {
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, soReUsePortLB, 1); err != nil {
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, soReUsePort, 1); err != nil {
return errors.New("failed to set SO_REUSEPORT").Base(err).AtWarning()
return errors.New("failed to set SO_REUSEPORT").Base(err)
}
}
return nil
+2 -2
View File
@@ -234,14 +234,14 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig)
func setReuseAddr(fd uintptr) error {
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1); err != nil {
return errors.New("failed to set SO_REUSEADDR").Base(err).AtWarning()
return errors.New("failed to set SO_REUSEADDR").Base(err)
}
return nil
}
func setReusePort(fd uintptr) error {
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, unix.SO_REUSEPORT, 1); err != nil {
return errors.New("failed to set SO_REUSEPORT").Base(err).AtWarning()
return errors.New("failed to set SO_REUSEPORT").Base(err)
}
return nil
}
+4 -4
View File
@@ -83,14 +83,14 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
}
if err != nil {
if isFromMitmVerify {
return nil, errors.New("MITM freedom RAW TLS: failed to verify Domain Fronting certificate from " + mitmServerName).Base(err).AtWarning()
return nil, errors.New("MITM freedom RAW TLS: failed to verify Domain Fronting certificate from " + mitmServerName).Base(err)
}
return nil, err
}
negotiatedProtocol := conn.(tls.Interface).NegotiatedProtocol()
if isFromMitmAlpn && !mitmAlpn11 && negotiatedProtocol != "h2" {
conn.Close()
return nil, errors.New("MITM freedom RAW TLS: unexpected Negotiated Protocol (" + negotiatedProtocol + ") with " + mitmServerName).AtWarning()
return nil, errors.New("MITM freedom RAW TLS: unexpected Negotiated Protocol (" + negotiatedProtocol + ") with " + mitmServerName)
}
} else if config := reality.ConfigFromStreamSettings(streamSettings); config != nil {
if conn, err = reality.UClient(conn, config, ctx, dest); err != nil {
@@ -102,11 +102,11 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
if tcpSettings.HeaderSettings != nil {
headerConfig, err := tcpSettings.HeaderSettings.GetInstance()
if err != nil {
return nil, errors.New("failed to get header settings").Base(err).AtError()
return nil, errors.New("failed to get header settings").Base(err)
}
auth, err := internet.CreateConnectionAuthenticator(headerConfig)
if err != nil {
return nil, errors.New("failed to create header authenticator").Base(err).AtError()
return nil, errors.New("failed to create header authenticator").Base(err)
}
conn = auth.Client(conn)
}
+2 -2
View File
@@ -74,11 +74,11 @@ func ListenTCP(ctx context.Context, address net.Address, port net.Port, streamSe
if tcpSettings.HeaderSettings != nil {
headerConfig, err := tcpSettings.HeaderSettings.GetInstance()
if err != nil {
return nil, errors.New("invalid header settings").Base(err).AtError()
return nil, errors.New("invalid header settings").Base(err)
}
auth, err := internet.CreateConnectionAuthenticator(headerConfig)
if err != nil {
return nil, errors.New("invalid header settings.").Base(err).AtError()
return nil, errors.New("invalid header settings.").Base(err)
}
l.authConfig = auth
}
+3 -3
View File
@@ -12,7 +12,7 @@ var transportListenerCache = make(map[string]ListenFunc)
func RegisterTransportListener(protocol string, listener ListenFunc) error {
if _, found := transportListenerCache[protocol]; found {
return errors.New(protocol, " listener already registered.").AtError()
return errors.New(protocol, " listener already registered.")
}
transportListenerCache[protocol] = listener
return nil
@@ -40,7 +40,7 @@ func ListenUnix(ctx context.Context, address net.Address, settings *MemoryStream
protocol := settings.ProtocolName
listenFunc := transportListenerCache[protocol]
if listenFunc == nil {
return nil, errors.New(protocol, " unix listener not registered.").AtError()
return nil, errors.New(protocol, " unix listener not registered.")
}
listener, err := listenFunc(ctx, address, net.Port(0), settings, handler)
if err != nil {
@@ -72,7 +72,7 @@ func ListenTCP(ctx context.Context, address net.Address, port net.Port, settings
protocol := settings.ProtocolName
listenFunc := transportListenerCache[protocol]
if listenFunc == nil {
return nil, errors.New(protocol, " listener not registered.").AtError()
return nil, errors.New(protocol, " listener not registered.")
}
listener, err := listenFunc(ctx, address, port, settings, handler)
if err != nil {
+1 -1
View File
@@ -39,7 +39,7 @@ func (c *Config) loadSelfCertPool() (*x509.CertPool, error) {
root := x509.NewCertPool()
for _, cert := range c.Certificate {
if !root.AppendCertsFromPEM(cert.Certificate) {
return nil, errors.New("failed to append cert").AtWarning()
return nil, errors.New("failed to append cert")
}
}
return root, nil
+2 -2
View File
@@ -44,11 +44,11 @@ func (c *Config) getCertPool() (*x509.CertPool, error) {
pool, err := x509.SystemCertPool()
if err != nil {
return nil, errors.New("system root").AtWarning().Base(err)
return nil, errors.New("system root").Base(err)
}
for _, cert := range c.Certificate {
if !pool.AppendCertsFromPEM(cert.Certificate) {
return nil, errors.New("append cert to root").AtWarning().Base(err)
return nil, errors.New("append cert to root").Base(err)
}
}
return pool, nil