-
Notifications
You must be signed in to change notification settings - Fork 1k
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
VersionPayload optimization #755
Merged
Merged
Changes from 58 commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
f884a17
Udp support
shargon b8b814e
Fix unbind
shargon f7a4958
typo
shargon c5de11a
Merge branch 'master' into udp-server
vncoelho 0170488
Unify GetPeers
shargon d59271a
Merge remote-tracking branch 'shargon/udp-server' into udp-server
shargon 1192b3f
Clean Peer
shargon e284c37
Fix clean
shargon fe42fcd
Refactor VersionPayload
shargon 5904954
Merge branch 'master' into udp-server
shargon b466f9d
Fix
shargon a1972c4
Merge remote-tracking branch 'shargon/udp-server' into udp-server
shargon 3a54118
Unit test
shargon 54a3087
Clean code
shargon 2c4fc41
Clean line
shargon ee2c9f0
Fix ut
shargon 77a0b1c
Simplify VersionPayload capabilities
shargon 2215a55
Refactor VersionPayload capabilities
shargon ace3153
rename NodeConfig to ChannelsStartConfig
shargon 72b82cf
Clean code
shargon 2e8d558
Clean code
shargon be1b889
UPnP for Udp port
shargon 765d6cf
Merge remote-tracking branch 'shargon/udp-server' into udp-server
shargon 9485a03
Fx for ListennerTcpPort
shargon 6d80ec1
Combine NodeCapabilities with ChannelType
shargon d0c1d7a
Merge branch 'master' into udp-server
erikzhang 56d8d64
Summarize ServerCapability and remove reflection
shargon f238e46
Move Capabilities
shargon e9c9097
OnStart with ChannelsStartConfig
shargon c9447b6
Remove EndPointConfig
shargon 1a86ae7
Move udp logic to ProtocolHandler
shargon 766f589
Rename
shargon fd12eaf
Merge branch 'master' into udp-server
shargon c53f574
Remove Services and StartHeight from VersionPayload
shargon bb76f79
Merge remote-tracking branch 'shargon/udp-server' into udp-server
shargon f8ebcc0
Merge branch 'master' into udp-server
shargon fee3f86
Remove AcceptRelay
shargon 311cd31
Clean code
shargon b55d75e
Parse message in LocalNode
shargon c8fc819
Merge branch 'master' into udp-server
shargon 279babe
Merge branch 'master' into udp-server
shargon 35489a8
Merge branch 'master' into udp-server
shargon 32db242
Merge branch 'master' into udp-server
shargon 64f6c4e
Prevent PeekChar
shargon 10694fe
Fix Serialize
shargon 957d52e
Merge branch 'master' into udp-server
shargon d8eaf7d
Clean code
shargon 6762a8e
Merge remote-tracking branch 'shargon/udp-server' into udp-server
shargon 485693e
Move `ChannelsStartConfig` into `Neo.Network.P2P`
erikzhang c425700
Merge branch 'master' into udp-server
shargon 68cb16c
Optimize capabilities
erikzhang 499fb92
Rename
erikzhang cefc6ae
Update NodeCapabilityType.cs
shargon e0fb9b8
Optimize `RemoteNode`
erikzhang 373cf31
Remove udp
shargon 6f97f55
format
erikzhang 2e214cc
Remove port from `NetworkAddressWithTime`
erikzhang 5830fc6
Merge branch 'master' into remove-udp
shargon cd75d0d
rename
erikzhang 0b5521e
Merge branch 'master' into remove-udp
erikzhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System.IO; | ||
|
||
namespace Neo.Network.P2P.Capabilities | ||
{ | ||
public class FullNodeCapability : NodeCapability | ||
{ | ||
public uint StartHeight; | ||
|
||
public override int Size => | ||
base.Size + // Type | ||
sizeof(uint); // Start Height | ||
|
||
/// <summary> | ||
/// Constructor | ||
/// </summary> | ||
/// <param name="startHeight">Start Height</param> | ||
public FullNodeCapability(uint startHeight = 0) : base(NodeCapabilityType.FullNode) | ||
{ | ||
StartHeight = startHeight; | ||
} | ||
|
||
protected override void DeserializeWithoutType(BinaryReader reader) | ||
{ | ||
StartHeight = reader.ReadUInt32(); | ||
} | ||
|
||
protected override void SerializeWithoutType(BinaryWriter writer) | ||
{ | ||
writer.Write(StartHeight); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using Neo.IO; | ||
using System; | ||
using System.IO; | ||
|
||
namespace Neo.Network.P2P.Capabilities | ||
{ | ||
public abstract class NodeCapability : ISerializable | ||
{ | ||
/// <summary> | ||
/// Type | ||
/// </summary> | ||
public readonly NodeCapabilityType Type; | ||
|
||
public virtual int Size => sizeof(NodeCapabilityType); // Type | ||
|
||
/// <summary> | ||
/// Constructor | ||
/// </summary> | ||
/// <param name="type">Type</param> | ||
protected NodeCapability(NodeCapabilityType type) | ||
{ | ||
this.Type = type; | ||
} | ||
|
||
void ISerializable.Deserialize(BinaryReader reader) | ||
{ | ||
if (reader.ReadByte() != (byte)Type) | ||
{ | ||
throw new FormatException(); | ||
} | ||
|
||
DeserializeWithoutType(reader); | ||
} | ||
|
||
public static NodeCapability DeserializeFrom(BinaryReader reader) | ||
{ | ||
NodeCapability capability; | ||
NodeCapabilityType type = (NodeCapabilityType)reader.ReadByte(); | ||
switch (type) | ||
{ | ||
case NodeCapabilityType.TcpServer: | ||
case NodeCapabilityType.WsServer: | ||
capability = new ServerCapability(type); | ||
break; | ||
case NodeCapabilityType.FullNode: | ||
capability = new FullNodeCapability(); | ||
break; | ||
default: | ||
throw new FormatException(); | ||
} | ||
capability.DeserializeWithoutType(reader); | ||
return capability; | ||
} | ||
|
||
protected abstract void DeserializeWithoutType(BinaryReader reader); | ||
|
||
void ISerializable.Serialize(BinaryWriter writer) | ||
{ | ||
writer.Write((byte)Type); | ||
SerializeWithoutType(writer); | ||
} | ||
|
||
protected abstract void SerializeWithoutType(BinaryWriter writer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace Neo.Network.P2P.Capabilities | ||
{ | ||
public enum NodeCapabilityType : byte | ||
{ | ||
//Servers | ||
TcpServer = 0x01, | ||
WsServer = 0x02, | ||
|
||
//Others | ||
FullNode = 0x10 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.IO; | ||
|
||
namespace Neo.Network.P2P.Capabilities | ||
{ | ||
public class ServerCapability : NodeCapability | ||
{ | ||
public ushort Port; | ||
|
||
public override int Size => | ||
base.Size + // Type | ||
sizeof(ushort); // Port | ||
|
||
/// <summary> | ||
/// Constructor | ||
/// </summary> | ||
/// <param name="type">Channel</param> | ||
/// <param name="port">Port</param> | ||
public ServerCapability(NodeCapabilityType type, ushort port = 0) : base(type) | ||
{ | ||
if (type != NodeCapabilityType.TcpServer && type != NodeCapabilityType.WsServer) | ||
{ | ||
throw new ArgumentException(nameof(type)); | ||
} | ||
|
||
Port = port; | ||
} | ||
|
||
protected override void DeserializeWithoutType(BinaryReader reader) | ||
{ | ||
Port = reader.ReadUInt16(); | ||
} | ||
|
||
protected override void SerializeWithoutType(BinaryWriter writer) | ||
{ | ||
writer.Write(Port); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System.Net; | ||
|
||
namespace Neo.Network.P2P | ||
{ | ||
public class ChannelsStartConfig | ||
erikzhang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
/// <summary> | ||
/// Tcp configuration | ||
/// </summary> | ||
public IPEndPoint Tcp { get; set; } | ||
|
||
/// <summary> | ||
/// Web socket configuration | ||
/// </summary> | ||
public IPEndPoint WebSocket { get; set; } | ||
|
||
/// <summary> | ||
/// Minimum desired connections | ||
/// </summary> | ||
public int MinDesiredConnections { get; set; } = Peer.DefaultMinDesiredConnections; | ||
|
||
/// <summary> | ||
/// Max allowed connections | ||
/// </summary> | ||
public int MaxConnections { get; set; } = Peer.DefaultMaxConnections; | ||
|
||
/// <summary> | ||
/// Max allowed connections per address | ||
/// </summary> | ||
public int MaxConnectionsPerAddress { get; set; } = 3; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This full node capability only with start height is quite strange.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FullNodeCapability
means the node has full blockchain data and accept relay.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are a relay node, why you should provide a 0 or this information?