Skip to content

Commit

Permalink
Merge branch 'master' into coreclr
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Zhang committed Oct 11, 2016
2 parents 3142b66 + b3bf45f commit 6dee267
Show file tree
Hide file tree
Showing 20 changed files with 1,058 additions and 60 deletions.
21 changes: 1 addition & 20 deletions AntSharesCore/Core/Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,7 @@ public abstract class Blockchain : IDisposable
/// <summary>
/// 后备记账人列表
/// </summary>
public static readonly ECPoint[] StandbyMiners =
{
#if TESTNET
ECPoint.DecodePoint("0327da12b5c40200e9f65569476bbff2218da4f32548ff43b6387ec1416a231ee8".HexToBytes(), ECCurve.Secp256r1),
ECPoint.DecodePoint("026ce35b29147ad09e4afe4ec4a7319095f08198fa8babbe3c56e970b143528d22".HexToBytes(), ECCurve.Secp256r1),
ECPoint.DecodePoint("0209e7fd41dfb5c2f8dc72eb30358ac100ea8c72da18847befe06eade68cebfcb9".HexToBytes(), ECCurve.Secp256r1),
ECPoint.DecodePoint("039dafd8571a641058ccc832c5e2111ea39b09c0bde36050914384f7a48bce9bf9".HexToBytes(), ECCurve.Secp256r1),
ECPoint.DecodePoint("038dddc06ce687677a53d54f096d2591ba2302068cf123c1f2d75c2dddc5425579".HexToBytes(), ECCurve.Secp256r1),
ECPoint.DecodePoint("02d02b1873a0863cd042cc717da31cea0d7cf9db32b74d4c72c01b0011503e2e22".HexToBytes(), ECCurve.Secp256r1),
ECPoint.DecodePoint("034ff5ceeac41acf22cd5ed2da17a6df4dd8358fcb2bfb1a43208ad0feaab2746b".HexToBytes(), ECCurve.Secp256r1),
#else
ECPoint.DecodePoint("03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c".HexToBytes(), ECCurve.Secp256r1),
ECPoint.DecodePoint("02df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e895093".HexToBytes(), ECCurve.Secp256r1),
ECPoint.DecodePoint("03b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a".HexToBytes(), ECCurve.Secp256r1),
ECPoint.DecodePoint("02ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba554".HexToBytes(), ECCurve.Secp256r1),
ECPoint.DecodePoint("024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d".HexToBytes(), ECCurve.Secp256r1),
ECPoint.DecodePoint("02aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e".HexToBytes(), ECCurve.Secp256r1),
ECPoint.DecodePoint("02486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a70".HexToBytes(), ECCurve.Secp256r1),
#endif
};
public static readonly ECPoint[] StandbyMiners = Settings.Default.StandbyMiners.OfType<string>().Select(p => ECPoint.DecodePoint(p.HexToBytes(), ECCurve.Secp256r1)).ToArray();

/// <summary>
/// 小蚁股
Expand Down
33 changes: 15 additions & 18 deletions AntSharesCore/Network/LocalNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,6 @@ public class LocalNode : IDisposable
private const int CONNECTED_MAX = 10;
private const int PENDING_MAX = CONNECTED_MAX;
private const int UNCONNECTED_MAX = 1000;
#if TESTNET
public const int DEFAULT_PORT = 20333;
#else
public const int DEFAULT_PORT = 10333;
#endif

private static readonly string[] SeedList =
{
"seed1.antshares.org",
"seed2.antshares.org",
"seed3.antshares.org",
"seed4.antshares.org",
"seed5.antshares.org"
};

private static readonly Dictionary<UInt256, Transaction> MemoryPool = new Dictionary<UInt256, Transaction>();
internal static readonly HashSet<UInt256> KnownHashes = new HashSet<UInt256>();
Expand Down Expand Up @@ -159,7 +145,7 @@ private static void Blockchain_PersistCompleted(object sender, Block block)
}
}

public async Task ConnectToPeerAsync(string hostNameOrAddress)
public async Task ConnectToPeerAsync(string hostNameOrAddress, int port)
{
IPAddress ipAddress;
if (IPAddress.TryParse(hostNameOrAddress, out ipAddress))
Expand All @@ -180,7 +166,7 @@ public async Task ConnectToPeerAsync(string hostNameOrAddress)
ipAddress = entry.AddressList.FirstOrDefault(p => p.AddressFamily == AddressFamily.InterNetwork || p.IsIPv6Teredo)?.MapToIPv6();
if (ipAddress == null) return;
}
await ConnectToPeerAsync(new IPEndPoint(ipAddress, DEFAULT_PORT));
await ConnectToPeerAsync(new IPEndPoint(ipAddress, port));
}

public async Task ConnectToPeerAsync(IPEndPoint remoteEndpoint)
Expand Down Expand Up @@ -237,7 +223,7 @@ private void ConnectToPeersLoop()
}
else
{
tasks = SeedList.Select(p => ConnectToPeerAsync(p)).ToArray();
tasks = Settings.Default.SeedList.OfType<string>().Select(p => p.Split(':')).Select(p => ConnectToPeerAsync(p[0], int.Parse(p[1]))).ToArray();
}
Task.WaitAll(tasks);
}
Expand Down Expand Up @@ -301,6 +287,17 @@ public RemoteNode[] GetRemoteNodes()
}
}

public static Transaction GetTransaction(UInt256 hash)
{
lock (MemoryPool)
{
Transaction tx;
if (!MemoryPool.TryGetValue(hash, out tx))
return null;
return tx;
}
}

private static bool IsIntranetAddress(IPAddress address)
{
byte[] data = address.MapToIPv4().GetAddressBytes();
Expand Down Expand Up @@ -432,7 +429,7 @@ public static void SaveState(Stream stream)
}
}

public async void Start(int port = DEFAULT_PORT)
public async void Start(int port)
{
if (Interlocked.Exchange(ref started, 1) == 0)
{
Expand Down
6 changes: 1 addition & 5 deletions AntSharesCore/Network/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ namespace AntShares.Network
{
internal class Message : ISerializable
{
#if TESTNET
public const uint Magic = 0x74746e41;
#else
public const uint Magic = 0x00746e41;
#endif
public static readonly uint Magic = Settings.Default.Magic;
public string Command;
public uint Checksum;
public byte[] Payload;
Expand Down
2 changes: 2 additions & 0 deletions AntSharesCore/Network/Payloads/VersionPayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ void ISerializable.Deserialize(BinaryReader reader)
Nonce = reader.ReadUInt32();
UserAgent = reader.ReadVarString();
StartHeight = reader.ReadUInt32();
Relay = reader.ReadBoolean();
}

void ISerializable.Serialize(BinaryWriter writer)
Expand All @@ -51,6 +52,7 @@ void ISerializable.Serialize(BinaryWriter writer)
writer.Write(Nonce);
writer.WriteVarString(UserAgent);
writer.Write(StartHeight);
writer.Write(Relay);
}
}
}
2 changes: 2 additions & 0 deletions AntSharesCore/Network/RemoteNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ private void OnGetDataMessageReceived(InvPayload payload)
switch (payload.Type)
{
case InventoryType.TX:
if (inventory == null)
inventory = LocalNode.GetTransaction(hash);
if (inventory == null && Blockchain.Default != null)
inventory = Blockchain.Default.GetTransaction(hash);
if (inventory != null)
Expand Down
27 changes: 27 additions & 0 deletions AntSharesCore/Settings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.Extensions.Configuration;
using System.Linq;

namespace AntShares
{
internal class Settings
{
public uint Magic { get; private set; }
public byte CoinVersion { get; private set; }
public string[] StandbyMiners { get; private set; }
public string[] SeedList { get; private set; }

public static Settings Default { get; private set; }

static Settings()
{
IConfigurationSection section = new ConfigurationBuilder().AddJsonFile("protocol.json").Build().GetSection("ProtocolConfiguration");
Default = new Settings
{
Magic = uint.Parse(section.GetSection("Magic").Value),
CoinVersion = byte.Parse(section.GetSection("CoinVersion").Value),
StandbyMiners = section.GetSection("StandbyMiners").GetChildren().Select(p => p.Value).ToArray(),
SeedList = section.GetSection("SeedList").GetChildren().Select(p => p.Value).ToArray()
};
}
}
}
2 changes: 1 addition & 1 deletion AntSharesCore/Wallets/Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public abstract class Wallet : IDisposable
{
public event EventHandler BalanceChanged;

public const byte CoinVersion = 0x17;
public static readonly byte CoinVersion = Settings.Default.CoinVersion;

private readonly string path;
private readonly byte[] iv;
Expand Down
6 changes: 5 additions & 1 deletion AntSharesCore/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
"copyright": "? AntShares Project 2015 Released under the MIT license",
"title": "AntShares",
"version": "1.0-coreclr",
"buildOptions": { "allowUnsafe": true },
"buildOptions": {
"allowUnsafe": true,
"copyToOutput": "protocol.json"
},

"dependencies": {
"Microsoft.EntityFrameworkCore.Sqlite": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"System.Net.Sockets": "4.1.0",
"System.Security.SecureString": "4.0.0",
"System.Text.Encodings.Web": "4.0.0"
Expand Down

0 comments on commit 6dee267

Please sign in to comment.