-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ping/pong for updating node height (#673)
- Loading branch information
Showing
3 changed files
with
82 additions
and
12 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Neo.IO; | ||
using System; | ||
using System.IO; | ||
|
||
namespace Neo.Network.P2P.Payloads | ||
{ | ||
public class PingPayload : ISerializable | ||
{ | ||
public uint LastBlockIndex; | ||
public uint Timestamp; | ||
public uint Nonce; | ||
|
||
public int Size => | ||
sizeof(uint) + //LastBlockIndex | ||
sizeof(uint) + //Timestamp | ||
sizeof(uint); //Nonce | ||
|
||
|
||
public static PingPayload Create(uint height) | ||
{ | ||
Random rand = new Random(); | ||
return new PingPayload | ||
{ | ||
LastBlockIndex = height, | ||
Timestamp = DateTime.UtcNow.ToTimestamp(), | ||
Nonce = (uint)rand.Next() | ||
}; | ||
} | ||
|
||
void ISerializable.Deserialize(BinaryReader reader) | ||
{ | ||
LastBlockIndex = reader.ReadUInt32(); | ||
Timestamp = reader.ReadUInt32(); | ||
Nonce = reader.ReadUInt32(); | ||
} | ||
|
||
void ISerializable.Serialize(BinaryWriter writer) | ||
{ | ||
writer.Write(LastBlockIndex); | ||
writer.Write(Timestamp); | ||
writer.Write(Nonce); | ||
} | ||
} | ||
} |
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