From fdfb757999aee3077310cda51b54801b291c964d Mon Sep 17 00:00:00 2001 From: Christopher Schuchardt Date: Fri, 29 Nov 2024 22:56:20 -0500 Subject: [PATCH] Revert "[Remove] obsolete `WsServer` (#3582)" This reverts commit 849b2c8d63e53a1311b529e3764067f55d285404. --- .../Network/P2P/Capabilities/NodeCapability.cs | 4 +++- .../P2P/Capabilities/NodeCapabilityType.cs | 8 ++++++++ .../P2P/Capabilities/ServerCapability.cs | 6 ++++-- .../P2P/Capabilities/UT_ServerCapability.cs | 18 ++++++++++++++++-- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/Neo/Network/P2P/Capabilities/NodeCapability.cs b/src/Neo/Network/P2P/Capabilities/NodeCapability.cs index 737f2873be..c47f238a4f 100644 --- a/src/Neo/Network/P2P/Capabilities/NodeCapability.cs +++ b/src/Neo/Network/P2P/Capabilities/NodeCapability.cs @@ -56,7 +56,9 @@ public static NodeCapability DeserializeFrom(ref MemoryReader reader) NodeCapabilityType type = (NodeCapabilityType)reader.ReadByte(); NodeCapability capability = type switch { - NodeCapabilityType.TcpServer => new ServerCapability(type), +#pragma warning disable CS0612 // Type or member is obsolete + NodeCapabilityType.TcpServer or NodeCapabilityType.WsServer => new ServerCapability(type), +#pragma warning restore CS0612 // Type or member is obsolete NodeCapabilityType.FullNode => new FullNodeCapability(), _ => throw new FormatException(), }; diff --git a/src/Neo/Network/P2P/Capabilities/NodeCapabilityType.cs b/src/Neo/Network/P2P/Capabilities/NodeCapabilityType.cs index 68305380e9..419d086fa9 100644 --- a/src/Neo/Network/P2P/Capabilities/NodeCapabilityType.cs +++ b/src/Neo/Network/P2P/Capabilities/NodeCapabilityType.cs @@ -9,6 +9,8 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. +using System; + namespace Neo.Network.P2P.Capabilities { /// @@ -23,6 +25,12 @@ public enum NodeCapabilityType : byte /// TcpServer = 0x01, + /// + /// Indicates that the node is listening on a WebSocket port. + /// + [Obsolete] + WsServer = 0x02, + #endregion #region Others diff --git a/src/Neo/Network/P2P/Capabilities/ServerCapability.cs b/src/Neo/Network/P2P/Capabilities/ServerCapability.cs index 820c4eff6d..e8c2d110df 100644 --- a/src/Neo/Network/P2P/Capabilities/ServerCapability.cs +++ b/src/Neo/Network/P2P/Capabilities/ServerCapability.cs @@ -32,11 +32,13 @@ public class ServerCapability : NodeCapability /// /// Initializes a new instance of the class. /// - /// The type of the . It must be + /// The type of the . It must be or /// The port that the node is listening on. public ServerCapability(NodeCapabilityType type, ushort port = 0) : base(type) { - if (type != NodeCapabilityType.TcpServer) +#pragma warning disable CS0612 // Type or member is obsolete + if (type != NodeCapabilityType.TcpServer && type != NodeCapabilityType.WsServer) +#pragma warning restore CS0612 // Type or member is obsolete { throw new ArgumentException(nameof(type)); } diff --git a/tests/Neo.UnitTests/Network/P2P/Capabilities/UT_ServerCapability.cs b/tests/Neo.UnitTests/Network/P2P/Capabilities/UT_ServerCapability.cs index b35d92f4e3..cb538771dc 100644 --- a/tests/Neo.UnitTests/Network/P2P/Capabilities/UT_ServerCapability.cs +++ b/tests/Neo.UnitTests/Network/P2P/Capabilities/UT_ServerCapability.cs @@ -26,12 +26,18 @@ public void Size_Get() { var test = new ServerCapability(NodeCapabilityType.TcpServer) { Port = 1 }; test.Size.Should().Be(3); + +#pragma warning disable CS0612 // Type or member is obsolete + test = new ServerCapability(NodeCapabilityType.WsServer) { Port = 2 }; +#pragma warning restore CS0612 // Type or member is obsolete + test.Size.Should().Be(3); } [TestMethod] public void DeserializeAndSerialize() { - var test = new ServerCapability(NodeCapabilityType.TcpServer) { Port = 2 }; +#pragma warning disable CS0612 // Type or member is obsolete + var test = new ServerCapability(NodeCapabilityType.WsServer) { Port = 2 }; var buffer = test.ToArray(); var br = new MemoryReader(buffer); @@ -40,13 +46,21 @@ public void DeserializeAndSerialize() Assert.AreEqual(test.Port, clone.Port); Assert.AreEqual(test.Type, clone.Type); - clone = new ServerCapability(NodeCapabilityType.TcpServer, 123); + clone = new ServerCapability(NodeCapabilityType.WsServer, 123); +#pragma warning restore CS0612 // Type or member is obsolete br = new MemoryReader(buffer); ((ISerializable)clone).Deserialize(ref br); Assert.AreEqual(test.Port, clone.Port); Assert.AreEqual(test.Type, clone.Type); + clone = new ServerCapability(NodeCapabilityType.TcpServer, 123); + + Assert.ThrowsException(() => + { + var br2 = new MemoryReader(buffer); + ((ISerializable)clone).Deserialize(ref br2); + }); Assert.ThrowsException(() => { _ = new ServerCapability(NodeCapabilityType.FullNode);