Skip to content

Commit

Permalink
[Remove] obsolete WsServer (#3582)
Browse files Browse the repository at this point in the history
* Remove WSServer obsolete

* Revert `global.json`

* Update ServerCapability.cs

---------

Co-authored-by: Shargon <shargon@gmail.com>
  • Loading branch information
cschuchardt88 and shargon authored Nov 18, 2024
1 parent 8d946b4 commit 849b2c8
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 31 deletions.
4 changes: 1 addition & 3 deletions src/Neo/Network/P2P/Capabilities/NodeCapability.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ public static NodeCapability DeserializeFrom(ref MemoryReader reader)
NodeCapabilityType type = (NodeCapabilityType)reader.ReadByte();
NodeCapability capability = type switch
{
#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.TcpServer => new ServerCapability(type),
NodeCapabilityType.FullNode => new FullNodeCapability(),
_ => throw new FormatException(),
};
Expand Down
8 changes: 0 additions & 8 deletions src/Neo/Network/P2P/Capabilities/NodeCapabilityType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using System;

namespace Neo.Network.P2P.Capabilities
{
/// <summary>
Expand All @@ -25,12 +23,6 @@ public enum NodeCapabilityType : byte
/// </summary>
TcpServer = 0x01,

/// <summary>
/// Indicates that the node is listening on a WebSocket port.
/// </summary>
[Obsolete]
WsServer = 0x02,

#endregion

#region Others
Expand Down
6 changes: 2 additions & 4 deletions src/Neo/Network/P2P/Capabilities/ServerCapability.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ public class ServerCapability : NodeCapability
/// <summary>
/// Initializes a new instance of the <see cref="ServerCapability"/> class.
/// </summary>
/// <param name="type">The type of the <see cref="ServerCapability"/>. It must be <see cref="NodeCapabilityType.TcpServer"/> or <see cref="NodeCapabilityType.WsServer"/></param>
/// <param name="type">The type of the <see cref="ServerCapability"/>. It must be <see cref="NodeCapabilityType.TcpServer"/></param>
/// <param name="port">The port that the node is listening on.</param>
public ServerCapability(NodeCapabilityType type, ushort port = 0) : base(type)
{
#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
if (type != NodeCapabilityType.TcpServer)
{
throw new ArgumentException(nameof(type));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,12 @@ 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()
{
#pragma warning disable CS0612 // Type or member is obsolete
var test = new ServerCapability(NodeCapabilityType.WsServer) { Port = 2 };
var test = new ServerCapability(NodeCapabilityType.TcpServer) { Port = 2 };
var buffer = test.ToArray();

var br = new MemoryReader(buffer);
Expand All @@ -45,21 +39,13 @@ public void DeserializeAndSerialize()
Assert.AreEqual(test.Port, clone.Port);
Assert.AreEqual(test.Type, clone.Type);

clone = new ServerCapability(NodeCapabilityType.WsServer, 123);
#pragma warning restore CS0612 // Type or member is obsolete
clone = new ServerCapability(NodeCapabilityType.TcpServer, 123);
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<FormatException>(() =>
{
var br2 = new MemoryReader(buffer);
((ISerializable)clone).Deserialize(ref br2);
});
Assert.ThrowsException<ArgumentException>(() =>
{
_ = new ServerCapability(NodeCapabilityType.FullNode);
Expand Down

0 comments on commit 849b2c8

Please sign in to comment.