Skip to content

Commit

Permalink
Merge pull request #667 from AElfProject/simple-version-check
Browse files Browse the repository at this point in the history
Add simple version check at connection.
  • Loading branch information
rosona authored Dec 6, 2018
2 parents a727ae1 + 328345a commit 805735a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions AElf.Common/GlobalConfig.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
using System.Reflection;

namespace AElf.Common
{
// ReSharper disable InconsistentNaming
public static class GlobalConfig
{
// current release version
public static int ProtocolVersion = 1;

public static int AddressLength = 18;
public const ulong GenesisBlockHeight = 1;
public static readonly string GenesisSmartContractZeroAssemblyName = "AElf.Contracts.Genesis";
Expand Down
2 changes: 2 additions & 0 deletions AElf.Network.Tests/NetworkTestHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using AElf.Common;
using AElf.Cryptography.ECDSA;
using AElf.Network.Data;
using Google.Protobuf;
Expand All @@ -20,6 +21,7 @@ public static (ECKeyPair, Handshake) CreateKeyPairAndHandshake(int port)
{
NodeInfo = nodeInfo,
PublicKey = ByteString.CopyFrom(key.GetEncodedPublicKey()),
Version = GlobalConfig.ProtocolVersion,
R = ByteString.CopyFrom(sig.R),
S = ByteString.CopyFrom(sig.S),
};
Expand Down
1 change: 1 addition & 0 deletions AElf.Network/Data/Protobuf/Definitions/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ message Handshake {
NodeData NodeInfo = 1;
bytes PublicKey = 2;
int32 Height = 3;
int32 Version = 4;
// sig NodeData
bytes R = 9;
bytes S = 10;
Expand Down
10 changes: 9 additions & 1 deletion AElf.Network/Peers/Peer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public AuthFinishedArgs()
public enum RejectReason
{
AuthTimeout,
AuthWrongVersion,
AuthInvalidHandshakeMsg,
AuthInvalidKey,
AuthInvalidSig
Expand Down Expand Up @@ -276,8 +277,9 @@ private void StartAuthentification()
NodeInfo = nodeInfo,
PublicKey = ByteString.CopyFrom(_nodeKey.GetEncodedPublicKey()),
Height = CurrentHeight,
Version = GlobalConfig.ProtocolVersion,
R = ByteString.CopyFrom(sig.R),
S = ByteString.CopyFrom(sig.S),
S = ByteString.CopyFrom(sig.S)
};

byte[] packet = nd.ToByteArray();
Expand Down Expand Up @@ -359,6 +361,12 @@ internal void AuthentifyWith(Handshake handshakeMsg)

try
{
if (handshakeMsg.Version != GlobalConfig.ProtocolVersion)
{
FireInvalidAuth(RejectReason.AuthWrongVersion);
return;
}

DistantNodeKeyPair = ECKeyPair.FromPublicKey(handshakeMsg.PublicKey.ToByteArray());

if (DistantNodeKeyPair == null)
Expand Down
2 changes: 1 addition & 1 deletion deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ DOCKER_USERNAME=$2
DOCKER_PASSWORD=$3

# AElf node
dotnet publish -c Release -o ~/aelf/
dotnet publish /p:Version=$TAG -c Release -o ~/aelf/

docker build -t aelf/node:$TAG ~/aelf/.
docker tag aelf/node:$TAG aelf/node:latest
Expand Down

0 comments on commit 805735a

Please sign in to comment.