Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "[Remove] obsolete WsServer" #3603

Merged
merged 2 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Neo/Network/P2P/Capabilities/NodeCapability.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
Expand Down
8 changes: 8 additions & 0 deletions src/Neo/Network/P2P/Capabilities/NodeCapabilityType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/// <summary>
Expand All @@ -23,6 +25,12 @@ 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: 4 additions & 2 deletions src/Neo/Network/P2P/Capabilities/ServerCapability.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ 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"/></param>
/// <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="port">The port that the node is listening on.</param>
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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<FormatException>(() =>
{
var br2 = new MemoryReader(buffer);
((ISerializable)clone).Deserialize(ref br2);
});
Assert.ThrowsException<ArgumentException>(() =>
{
_ = new ServerCapability(NodeCapabilityType.FullNode);
Expand Down
Loading