Repository navigation
[Add] Neo N3 P2P peer session: framing, handshake, connect, and keep-alive - #32
Merged
cschuchardt88 merged 11 commits intoJul 23, 2026
Merged
Conversation
Implement protocol-compatible wire framing (TryRead/Create), fix capability serialize/deserialize, and complete the peer session path: listen, outbound connect, Version/Verack handshake, Ping/Pong, and idle timeouts. Include coverage for messages, handshake, and loopback accept/connect.
Use OS-assigned port 0, BoundEndPoint, exclusive bind on Windows, and disconnect-safe WaitForHandshakeAsync so socket tests do not race under MethodLevel parallelization.
Member
Author
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds a Neo N3–compatible P2P session layer so this platform can speak the same TCP wire protocol as neo-project/neo
Network/P2P: message framing, node capabilities, Version/Verack handshake, listen + outbound connect, and Ping/Pong with idle timeouts.Also wires store/backup config defaults into the hosting environment provider and adds
RandomNumberFactoryas a public SDK utility (used for nonces and available to consumers).Motivation
Node hosting needs real peer connectivity. This PR lands the connection + handshake foundation (aligned with Neo’s
Message,RemoteNodehandshake, and capability layout) without implementing full chain sync yet.What’s included
1. Protocol framing (
ProtocolMessage)Wire layout matches Neo N3:
TryRead0if incomplete, byte count if complete, throws if payload >PayloadMaxSize(0x02000000)CreateToArray(allowCompression)2. Version & capabilities
VersionMessage— network, version, timestamp, nonce, user agent, capabilitiesDeserializeFrom+DeserializeWithoutType/SerializeWithoutType), matching NeoTcpServer(port),FullNode(start height),ArchivalNode,DisableCompressionGetSerializedSizenow sums sizes correctly (nolength × sum)3. Peer connection (
NodeConnection)Pipe→ frame parse loop (TryReadFrame)ConnectAsyncoutbound factoryWaitForHandshakeAsyncSendAsyncwith optional compressionHandshakeCompleted,MessageReceived(post-handshake),DisconnectedLocalBlockIndex/RemoteLastBlockIndexfor Ping/Pong height4. Handshake (
NodeHandshake)Pure state machine (testable without I/O):
Rejects: wrong command order, network mismatch, self-nonce, handshake messages after Ready.
5. Listener (
NodeServerListener)ReuseAddress, default backlog 128DisconnectedConnectAsyncfor outbound dial using this node’s identity6. Keep-alive (Neo-style)
PingPing(same nonce, local height)PingMessagepayload:LastBlockIndex,Timestamp,Nonce7. Hosting / config
BlockchainStoreNamesconfig keysRandomNumberFactorypublic SDK surface8. Tests
UT_ProtocolMessageUT_NodeCapabilityMessageUT_VersionMessageProtocolMessageUT_NodeHandshakeUT_NodeConnectionUT_NodeConnectionConnect/UT_NodeServerListenerUT_PingMessageTestUtilitiesGetFreeTcpPort,WaitForAsyncCommits
Out of scope (follow-ups)
GetAddr/Addr, seed list)GetHeaders,Headers,Inv,GetData,Block,Tx, …)Test plan
dotnet test tests/Neo.Core.Tests/Neo.Core.Tests.csproj --filter "FullyQualifiedName~Net"Compatibility notes
Versionis known (or peer disables compression), sends uncompressed frames