From 66054dd225b9b99366998b17034c23014217d25e Mon Sep 17 00:00:00 2001 From: Evan Husted Date: Sun, 16 Feb 2025 00:45:50 -0600 Subject: [PATCH 1/3] UI: RPC: Remove git hash from RPC ryujinx logo hover information --- src/Ryujinx/DiscordIntegrationModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ryujinx/DiscordIntegrationModule.cs b/src/Ryujinx/DiscordIntegrationModule.cs index 075dc65da..8d232b4fb 100644 --- a/src/Ryujinx/DiscordIntegrationModule.cs +++ b/src/Ryujinx/DiscordIntegrationModule.cs @@ -24,7 +24,7 @@ namespace Ryujinx.Ava private static readonly string _description = ReleaseInformation.IsValid - ? $"{VersionString} {ReleaseInformation.ReleaseChannelOwner}/{ReleaseInformation.ReleaseChannelSourceRepo}@{ReleaseInformation.BuildGitHash}" + ? $"{VersionString} {ReleaseInformation.ReleaseChannelOwner}/{ReleaseInformation.ReleaseChannelSourceRepo}" : "dev build"; private const string ApplicationId = "1293250299716173864"; From 61975ca44d727d54d04facb18a8935a1f11832e6 Mon Sep 17 00:00:00 2001 From: Vudjun Date: Sun, 16 Feb 2025 07:03:44 +0000 Subject: [PATCH 2/3] Add logging in socket implementation (#661) Adds logging to most Socket calls to help with debugging network issues. Shouldn't affect any functionality. There's a small chance it could spam the log in some games. --- .../HOS/Services/Sockets/Bsd/IClient.cs | 13 ++- .../Sockets/Bsd/Impl/ManagedSocket.cs | 83 +++++++++++++++++-- .../Sockets/Bsd/Proxy/SocketHelpers.cs | 12 ++- 3 files changed, 101 insertions(+), 7 deletions(-) diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs index 8475424ce..b8deb2c45 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs @@ -34,6 +34,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd { if (errorCode != LinuxError.SUCCESS) { + if (errorCode != LinuxError.EWOULDBLOCK) + { + Logger.Warning?.Print(LogClass.ServiceBsd, $"Operation failed with error {errorCode}."); + } result = -1; } @@ -66,6 +70,8 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd BsdSocketType type = (BsdSocketType)context.RequestData.ReadInt32(); ProtocolType protocol = (ProtocolType)context.RequestData.ReadInt32(); + Logger.Info?.PrintMsg(LogClass.ServiceBsd, $"Creating socket with domain={domain}, type={type}, protocol={protocol}"); + BsdSocketCreationFlags creationFlags = (BsdSocketCreationFlags)((int)type >> (int)BsdSocketCreationFlags.FlagsShift); type &= BsdSocketType.TypeMask; @@ -111,6 +117,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd if (exempt) { + Logger.Info?.Print(LogClass.ServiceBsd, "Disconnecting exempt socket."); newBsdSocket.Disconnect(); } @@ -797,7 +804,11 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd { errno = socket.Listen(backlog); } - + else + { + Logger.Warning?.PrintMsg(LogClass.ServiceBsd, $"Invalid socket fd '{socketFd}'."); + } + return WriteBsdResult(context, 0, errno); } diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/ManagedSocket.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/ManagedSocket.cs index 981fe0a8f..3c367660a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/ManagedSocket.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/ManagedSocket.cs @@ -92,18 +92,30 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl { newSocket = new ManagedSocket(Socket.Accept()); + IPEndPoint remoteEndPoint = newSocket.RemoteEndPoint; + bool isPrivateIp = remoteEndPoint.Address.ToString().StartsWith("192.168."); + Logger.Info?.PrintMsg(LogClass.ServiceBsd, + isPrivateIp + ? $"Accepted connection from {ProtocolType}/{remoteEndPoint.Address}:{remoteEndPoint.Port}" + : $"Accepted connection from {ProtocolType}/***:{remoteEndPoint.Port}"); + return LinuxError.SUCCESS; } catch (SocketException exception) { newSocket = null; + if (exception.SocketErrorCode != SocketError.WouldBlock) + { + Logger.Warning?.Print(LogClass.ServiceBsd, $"Socket Exception: {exception}"); + } return WinSockHelper.ConvertError((WsaError)exception.ErrorCode); } } public LinuxError Bind(IPEndPoint localEndPoint) { + Logger.Info?.PrintMsg(LogClass.ServiceBsd, $"Socket binding to: {ProtocolType}/{localEndPoint.Port}"); try { Socket.Bind(localEndPoint); @@ -112,6 +124,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl } catch (SocketException exception) { + if (exception.SocketErrorCode != SocketError.WouldBlock) + { + Logger.Warning?.Print(LogClass.ServiceBsd, $"Socket Exception: {exception}"); + } return WinSockHelper.ConvertError((WsaError)exception.ErrorCode); } } @@ -123,6 +139,15 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl public LinuxError Connect(IPEndPoint remoteEndPoint) { + bool isLDNPrivateIP = remoteEndPoint.Address.ToString().StartsWith("192.168."); + if (isLDNPrivateIP) + { + Logger.Info?.PrintMsg(LogClass.ServiceBsd, $"Connecting to: {ProtocolType}/{remoteEndPoint.Address}:{remoteEndPoint.Port}"); + } + else + { + Logger.Info?.PrintMsg(LogClass.ServiceBsd, $"Connecting to: {ProtocolType}/***:{remoteEndPoint.Port}"); + } try { Socket.Connect(remoteEndPoint); @@ -137,6 +162,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl } else { + if (exception.SocketErrorCode != SocketError.WouldBlock) + { + Logger.Warning?.Print(LogClass.ServiceBsd, $"Socket Exception: {exception}"); + } return WinSockHelper.ConvertError((WsaError)exception.ErrorCode); } } @@ -144,11 +173,13 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl public void Disconnect() { + Logger.Info?.Print(LogClass.ServiceBsd, "Socket disconnecting"); Socket.Disconnect(true); } public void Dispose() { + Logger.Info?.Print(LogClass.ServiceBsd, "Socket closed"); Socket.Close(); Socket.Dispose(); } @@ -159,10 +190,16 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl { Socket.Listen(backlog); + Logger.Info?.PrintMsg(LogClass.ServiceBsd, $"Socket listening: {ProtocolType}/{(Socket.LocalEndPoint as IPEndPoint).Port}"); + return LinuxError.SUCCESS; } catch (SocketException exception) { + if (exception.SocketErrorCode != SocketError.WouldBlock) + { + Logger.Warning?.Print(LogClass.ServiceBsd, $"Socket Exception: {exception}"); + } return WinSockHelper.ConvertError((WsaError)exception.ErrorCode); } } @@ -182,11 +219,15 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl } catch (SocketException exception) { + if (exception.SocketErrorCode != SocketError.WouldBlock) + { + Logger.Warning?.Print(LogClass.ServiceBsd, $"Socket Exception: {exception}"); + } return WinSockHelper.ConvertError((WsaError)exception.ErrorCode); } } - bool hasEmittedBlockingWarning = false; + private bool _hasEmittedBlockingWarning; public LinuxError Receive(out int receiveSize, Span buffer, BsdSocketFlags flags) { @@ -202,10 +243,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl shouldBlockAfterOperation = true; } - if (Blocking && !hasEmittedBlockingWarning) + if (Blocking && !_hasEmittedBlockingWarning) { Logger.Warning?.PrintMsg(LogClass.ServiceBsd, "Blocking socket operations are not yet working properly. Expect network errors."); - hasEmittedBlockingWarning = true; + _hasEmittedBlockingWarning = true; } receiveSize = Socket.Receive(buffer, ConvertBsdSocketFlags(flags)); @@ -214,6 +255,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl } catch (SocketException exception) { + if (exception.SocketErrorCode != SocketError.WouldBlock) + { + Logger.Warning?.Print(LogClass.ServiceBsd, $"Socket Exception: {exception}"); + } receiveSize = -1; result = WinSockHelper.ConvertError((WsaError)exception.ErrorCode); @@ -245,10 +290,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl shouldBlockAfterOperation = true; } - if (Blocking && !hasEmittedBlockingWarning) + if (Blocking && !_hasEmittedBlockingWarning) { Logger.Warning?.PrintMsg(LogClass.ServiceBsd, "Blocking socket operations are not yet working properly. Expect network errors."); - hasEmittedBlockingWarning = true; + _hasEmittedBlockingWarning = true; } if (!Socket.IsBound) @@ -265,6 +310,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl } catch (SocketException exception) { + if (exception.SocketErrorCode != SocketError.WouldBlock) + { + Logger.Warning?.Print(LogClass.ServiceBsd, $"Socket Exception: {exception}"); + } receiveSize = -1; result = WinSockHelper.ConvertError((WsaError)exception.ErrorCode); @@ -288,6 +337,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl } catch (SocketException exception) { + if (exception.SocketErrorCode != SocketError.WouldBlock) + { + Logger.Warning?.Print(LogClass.ServiceBsd, $"Socket Exception: {exception}"); + } sendSize = -1; return WinSockHelper.ConvertError((WsaError)exception.ErrorCode); @@ -304,6 +357,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl } catch (SocketException exception) { + if (exception.SocketErrorCode != SocketError.WouldBlock) + { + Logger.Warning?.Print(LogClass.ServiceBsd, $"Socket Exception: {exception}"); + } sendSize = -1; return WinSockHelper.ConvertError((WsaError)exception.ErrorCode); @@ -341,6 +398,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl } catch (SocketException exception) { + if (exception.SocketErrorCode != SocketError.WouldBlock) + { + Logger.Warning?.Print(LogClass.ServiceBsd, $"Socket Exception: {exception}"); + } return WinSockHelper.ConvertError((WsaError)exception.ErrorCode); } } @@ -387,6 +448,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl } catch (SocketException exception) { + if (exception.SocketErrorCode != SocketError.WouldBlock) + { + Logger.Warning?.Print(LogClass.ServiceBsd, $"Socket Exception: {exception}"); + } return WinSockHelper.ConvertError((WsaError)exception.ErrorCode); } } @@ -519,6 +584,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl } catch (SocketException exception) { + if (exception.SocketErrorCode != SocketError.WouldBlock) + { + Logger.Warning?.Print(LogClass.ServiceBsd, $"Socket Exception: {exception}"); + } return WinSockHelper.ConvertError((WsaError)exception.ErrorCode); } } @@ -557,6 +626,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl } catch (SocketException exception) { + if (exception.SocketErrorCode != SocketError.WouldBlock) + { + Logger.Warning?.Print(LogClass.ServiceBsd, $"Socket Exception: {exception}"); + } return WinSockHelper.ConvertError((WsaError)exception.ErrorCode); } } diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Proxy/SocketHelpers.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Proxy/SocketHelpers.cs index 9f206176d..b442cf802 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Proxy/SocketHelpers.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Proxy/SocketHelpers.cs @@ -1,4 +1,6 @@ +using Ryujinx.Common.Logging; using Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Proxy; +using Ryujinx.HLE.HOS.Services.Sockets.Bsd.Types; using System; using System.Collections.Generic; using System.Linq; @@ -64,10 +66,18 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Proxy { if (_proxy.Supported(domain, type, protocol)) { + Logger.Info?.PrintMsg(LogClass.ServiceBsd, $"Socket is using LDN proxy"); return new LdnProxySocket(domain, type, protocol, _proxy); } + else + { + Logger.Warning?.PrintMsg(LogClass.ServiceBsd, $"LDN proxy does not support socket {domain}, {type}, {protocol}"); + } + } + else + { + Logger.Info?.PrintMsg(LogClass.ServiceBsd, $"Opening socket using host networking stack"); } - return new DefaultSocket(domain, type, protocol, lanInterfaceId); } } From bc07bc482d172744a143a5f060076ff8f400b757 Mon Sep 17 00:00:00 2001 From: Vudjun Date: Sun, 16 Feb 2025 08:26:37 +0000 Subject: [PATCH 3/3] Gracefully handle errors in socket creation (#662) In all other calls, exceptions are handled within the ManagedSocket class, this can't easily be done here as the exception is thrown from the constructor, so the exception is handled in ISocket and the correct error is passed to the application. This should fix #660 --- .../HOS/Services/Sockets/Bsd/IClient.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs index b8deb2c45..0a592d542 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs @@ -101,12 +101,21 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd } } - ISocket newBsdSocket = new ManagedSocket(netDomain, (SocketType)type, protocol, context.Device.Configuration.MultiplayerLanInterfaceId) - { - Blocking = !creationFlags.HasFlag(BsdSocketCreationFlags.NonBlocking), - }; - LinuxError errno = LinuxError.SUCCESS; + ISocket newBsdSocket; + + try + { + newBsdSocket = new ManagedSocket(netDomain, (SocketType)type, protocol, context.Device.Configuration.MultiplayerLanInterfaceId) + { + Blocking = !creationFlags.HasFlag(BsdSocketCreationFlags.NonBlocking), + }; + } + catch (SocketException exception) + { + LinuxError errNo = WinSockHelper.ConvertError((WsaError)exception.ErrorCode); + return WriteBsdResult(context, 0, errNo); + } int newSockFd = _context.RegisterFileDescriptor(newBsdSocket);