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

return ping nonce in pong reply #677

Merged
merged 2 commits into from
Apr 2, 2019
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
7 changes: 6 additions & 1 deletion neo/Network/P2P/Payloads/PingPayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ public class PingPayload : ISerializable
public static PingPayload Create(uint height)
{
Random rand = new Random();
return Create(height, (uint)rand.Next());
}

public static PingPayload Create(uint height, uint nonce)
{
return new PingPayload
{
LastBlockIndex = height,
Timestamp = DateTime.UtcNow.ToTimestamp(),
Nonce = (uint)rand.Next()
Nonce = nonce
};
}

Expand Down
2 changes: 1 addition & 1 deletion neo/Network/P2P/ProtocolHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ private void OnMemPoolMessageReceived()
private void OnPingMessageReceived(PingPayload payload)
{
Context.Parent.Tell(payload);
Context.Parent.Tell(Message.Create("pong", PingPayload.Create(Blockchain.Singleton.Height)));
Context.Parent.Tell(Message.Create("pong", PingPayload.Create(Blockchain.Singleton.Height, payload.Nonce)));
}

private void OnPongMessageReceived(PingPayload payload)
Expand Down