From cc6553b5d3117d1858246060740a40400d73e3aa Mon Sep 17 00:00:00 2001 From: chris Date: Sun, 7 May 2017 14:18:10 +0200 Subject: [PATCH] -improved peerseed list (related to various confis) -speedups! -removed fixed parameters for versionin -cleanup of network api! --- ark-net/Controller/AccountController.cs | 7 +- ark-net/Core/Crypto.cs | 4 +- ark-net/Core/NetworkApi.cs | 89 +--------- ark-net/Core/PeerApi.cs | 8 +- ark-net/Properties/AssemblyInfo.cs | 6 +- ark-net/Properties/Settings.Designer.cs | 161 ------------------ ark-net/Properties/Settings.settings | 51 ------ ark-net/Utils/ArkSettings.cs | 3 + ark-net/ark-net.csproj | 9 - ark-net/default.conf | 67 +++++++- .../Controller/AccountControllerTests.cs | 3 +- ark-netTests/Tests/NetworkTests.cs | 13 +- ark-netTests/Tests/TransactionCryptoTests.cs | 2 +- 13 files changed, 94 insertions(+), 329 deletions(-) delete mode 100644 ark-net/Properties/Settings.Designer.cs delete mode 100644 ark-net/Properties/Settings.settings diff --git a/ark-net/Controller/AccountController.cs b/ark-net/Controller/AccountController.cs index ee04418..b3ecfda 100644 --- a/ark-net/Controller/AccountController.cs +++ b/ark-net/Controller/AccountController.cs @@ -12,8 +12,11 @@ public class AccountController public AccountController(string passphrase) { - _account = AccountService.GetByAddress(Crypto.GetAddress(Crypto.GetKeys(passphrase))); - _account.PublicKey = Crypto.GetKeys(passphrase).PubKey.ToString(); + _account = new ArkAccount() + { + Address = Crypto.GetAddress(Crypto.GetKeys(passphrase), ArkNetApi.Instance.NetworkSettings.BytePrefix), + PublicKey = Crypto.GetKeys(passphrase).PubKey.ToString() + }; } public ArkAccount GetArkAccount() diff --git a/ark-net/Core/Crypto.cs b/ark-net/Core/Crypto.cs index aba1a69..90334b9 100644 --- a/ark-net/Core/Crypto.cs +++ b/ark-net/Core/Crypto.cs @@ -68,13 +68,13 @@ public static Key GetKeys(string passphrase) return new Key(sha256h); } - public static string GetAddress(Key keys, byte version = 0x17) + public static string GetAddress(Key keys, byte version) { //keys.S return GetAddress(keys.PubKey.ToBytes(), version); } - public static string GetAddress(byte[] publicKey, byte version = 0x17) + public static string GetAddress(byte[] publicKey, byte version) { var keyHash = Ripemd160.ComputeHash(publicKey, 0, publicKey.Length); var address = new BCAVersionedChecksummedBytes(version, keyHash); diff --git a/ark-net/Core/NetworkApi.cs b/ark-net/Core/NetworkApi.cs index 0cddeb0..2f26d4c 100644 --- a/ark-net/Core/NetworkApi.cs +++ b/ark-net/Core/NetworkApi.cs @@ -10,62 +10,9 @@ public sealed class NetworkApi private static readonly Lazy lazy = new Lazy(() => new NetworkApi()); - private static readonly Random random = new Random(); - - //private static volatile NetworkApi instance; + private static readonly Random random = new Random(); private readonly List peers = new List(); - - private readonly List peerseed = new List - { - "5.39.9.240:4001", - "5.39.9.241:4001", - "5.39.9.242:4001", - "5.39.9.243:4001", - "5.39.9.244:4001", - "5.39.9.250:4001", - "5.39.9.251:4001", - "5.39.9.252:4001", - "5.39.9.253:4001", - "5.39.9.254:4001", - "5.39.9.255:4001", - "5.39.53.48:4001", - "5.39.53.49:4001", - "5.39.53.50:4001", - "5.39.53.51:4001", - "5.39.53.52:4001", - "5.39.53.53:4001", - "5.39.53.54:4001", - "5.39.53.55:4001", - "37.59.129.160:4001", - "37.59.129.161:4001", - "37.59.129.162:4001", - "37.59.129.163:4001", - "37.59.129.164:4001", - "37.59.129.165:4001", - "37.59.129.166:4001", - "37.59.129.167:4001", - "37.59.129.168:4001", - "37.59.129.169:4001", - "37.59.129.170:4001", - "37.59.129.171:4001", - "37.59.129.172:4001", - "37.59.129.173:4001", - "37.59.129.174:4001", - "37.59.129.175:4001", - "193.70.72.80:4001", - "193.70.72.81:4001", - "193.70.72.82:4001", - "193.70.72.83:4001", - "193.70.72.84:4001", - "193.70.72.85:4001", - "193.70.72.86:4001", - "193.70.72.87:4001", - "193.70.72.88:4001", - "193.70.72.89:4001", - "193.70.72.90:4001" - }; - - + private NetworkApi() { peers = new List(); @@ -73,25 +20,8 @@ private NetworkApi() } public static NetworkApi Instance => lazy.Value; - - /*public static NetworkApi Instance - { - get - { - if (instance == null) - { - instance = new NetworkApi(); - instance.WarmUp(); - } - - return instance; - } - }*/ - - public string Nethash { get; set; } = - ArkNetApi.Instance.NetworkSettings - .NetHash; //"6e84d08bd299ed97c212c886c98a57e36545c8f5d645ca7eeae63a8bd62d8988"; - + + public string Nethash { get; set; } = ArkNetApi.Instance.NetworkSettings.NetHash; public string Name { get; set; } = ArkNetApi.Instance.NetworkSettings.Name; public int Port { get; set; } = ArkNetApi.Instance.NetworkSettings.Port; public byte Prefix { get; set; } = ArkNetApi.Instance.NetworkSettings.BytePrefix; @@ -99,19 +29,10 @@ private NetworkApi() public int BroadcastMax { get; set; } = ArkNetApi.Instance.NetworkSettings.MaxNumOfBroadcasts; public PeerApi ActivePeer { get; set; } - public dynamic GetHeaders(bool retJson = false) - { - var data = new Dictionary {["nethash"] = Nethash, ["version"] = Version, ["port"] = Port}; - - if (retJson) - return JsonConvert.SerializeObject(data); - return data; - } - private bool WarmUp() { if (peers.Count > 0) return false; - foreach (var item in peerseed) + foreach (var item in ArkNetApi.Instance.NetworkSettings.PeerSeedList) peers.Add(new PeerApi(item)); ActivePeer = GetRandomPeer(); diff --git a/ark-net/Core/PeerApi.cs b/ark-net/Core/PeerApi.cs index efcfa6b..7b7ef45 100644 --- a/ark-net/Core/PeerApi.cs +++ b/ark-net/Core/PeerApi.cs @@ -3,7 +3,7 @@ using System.Net; using System.Net.Http; using System.Net.Http.Headers; -using ArkNet.Properties; +using JsonConfig; using Newtonsoft.Json.Linq; namespace ArkNet.Core @@ -43,13 +43,13 @@ public PeerApi(string peerData) private static void OpenServicePoint(Uri uri) { ServicePointManager.CheckCertificateRevocationList = true; - ServicePointManager.DefaultConnectionLimit = Settings.Default.DefaultConnectionLimit; + ServicePointManager.DefaultConnectionLimit = Config.Default.ArkPeer.DefaultConnectionLimit; var sp = ServicePointManager.FindServicePoint(uri); sp.UseNagleAlgorithm = true; sp.Expect100Continue = true; - sp.ConnectionLimit = Settings.Default.ConnectionLimit; - sp.ConnectionLeaseTimeout = Settings.Default.ConnectionLeaseTimeOut; + sp.ConnectionLimit = Config.Default.ArkPeer.ConnectionLimit; + sp.ConnectionLeaseTimeout = Config.Default.ArkPeer.ConnectionLeaseTimeOut; } private void Init(string ip, int port, string protocol) diff --git a/ark-net/Properties/AssemblyInfo.cs b/ark-net/Properties/AssemblyInfo.cs index 1a894e0..0cef34a 100644 --- a/ark-net/Properties/AssemblyInfo.cs +++ b/ark-net/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("ARK.io")] [assembly: AssemblyProduct("Ark.NET")] -[assembly: AssemblyCopyright("Copyright © 2017, ARK, Kristjan Košič")] +[assembly: AssemblyCopyright("Copyright © 2017, ARK, Kristjan Košič - chris")] [assembly: AssemblyTrademark("ARK")] [assembly: AssemblyCulture("")] @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.7.6.0")] -[assembly: AssemblyFileVersion("0.7.6.0")] +[assembly: AssemblyVersion("0.7.7.0")] +[assembly: AssemblyFileVersion("0.7.7.0")] diff --git a/ark-net/Properties/Settings.Designer.cs b/ark-net/Properties/Settings.Designer.cs deleted file mode 100644 index bebb206..0000000 --- a/ark-net/Properties/Settings.Designer.cs +++ /dev/null @@ -1,161 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace ArkNet.Properties { - - - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.1.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { - - private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default { - get { - return defaultInstance; - } - } - - [global::System.Configuration.ApplicationScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("mainnet")] - public string MainNetName { - get { - return ((string)(this["MainNetName"])); - } - } - - [global::System.Configuration.ApplicationScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("4001")] - public int MainNetPort { - get { - return ((int)(this["MainNetPort"])); - } - } - - [global::System.Configuration.ApplicationScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("23")] - public byte MainNetBytePrefix { - get { - return ((byte)(this["MainNetBytePrefix"])); - } - } - - [global::System.Configuration.ApplicationScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("testnet")] - public string TestNetName { - get { - return ((string)(this["TestNetName"])); - } - } - - [global::System.Configuration.ApplicationScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("4000")] - public int TestNetPort { - get { - return ((int)(this["TestNetPort"])); - } - } - - [global::System.Configuration.ApplicationScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("24")] - public byte TestNetBytePrefix { - get { - return ((byte)(this["TestNetBytePrefix"])); - } - } - - [global::System.Configuration.ApplicationScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("10000")] - public int ConnectionLimit { - get { - return ((int)(this["ConnectionLimit"])); - } - } - - [global::System.Configuration.ApplicationScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("30000")] - public int ConnectionLeaseTimeOut { - get { - return ((int)(this["ConnectionLeaseTimeOut"])); - } - } - - [global::System.Configuration.ApplicationScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("10000")] - public int DefaultConnectionLimit { - get { - return ((int)(this["DefaultConnectionLimit"])); - } - } - - [global::System.Configuration.ApplicationScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("6e84d08bd299ed97c212c886c98a57e36545c8f5d645ca7eeae63a8bd62d8988")] - public string NetHash { - get { - return ((string)(this["NetHash"])); - } - } - - [global::System.Configuration.ApplicationScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("5")] - public int MaxNumOfBroadcasts { - get { - return ((int)(this["MaxNumOfBroadcasts"])); - } - } - - [global::System.Configuration.ApplicationScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("1.0")] - public string MainNetVer { - get { - return ((string)(this["MainNetVer"])); - } - } - - [global::System.Configuration.ApplicationScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("6e84d08bd299ed97c212c886c98a57e36545c8f5d645ca7eeae63a8bd62d8988")] - public string MainNetHash { - get { - return ((string)(this["MainNetHash"])); - } - } - - [global::System.Configuration.ApplicationScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("6e84d08bd299ed97c212c886c98a57e36545c8f5d645ca7eeae63a8bd62d8988")] - public string TestNetHash { - get { - return ((string)(this["TestNetHash"])); - } - } - - [global::System.Configuration.ApplicationScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("1.0")] - public string TestNetVer { - get { - return ((string)(this["TestNetVer"])); - } - } - } -} diff --git a/ark-net/Properties/Settings.settings b/ark-net/Properties/Settings.settings deleted file mode 100644 index 116e9e8..0000000 --- a/ark-net/Properties/Settings.settings +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - mainnet - - - 4001 - - - 23 - - - testnet - - - 4000 - - - 24 - - - 10000 - - - 30000 - - - 10000 - - - 6e84d08bd299ed97c212c886c98a57e36545c8f5d645ca7eeae63a8bd62d8988 - - - 5 - - - 1.0 - - - 6e84d08bd299ed97c212c886c98a57e36545c8f5d645ca7eeae63a8bd62d8988 - - - 6e84d08bd299ed97c212c886c98a57e36545c8f5d645ca7eeae63a8bd62d8988 - - - 1.0 - - - \ No newline at end of file diff --git a/ark-net/Utils/ArkSettings.cs b/ark-net/Utils/ArkSettings.cs index fd06550..6b5a97a 100644 --- a/ark-net/Utils/ArkSettings.cs +++ b/ark-net/Utils/ArkSettings.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; namespace ArkNet.Utils { @@ -11,6 +12,7 @@ public class ArkNetworkSettings public string NetHash { get; set; } public int MaxNumOfBroadcasts { get; set; } public Fees Fee { get; set; } + public IList PeerSeedList { get; set; } public ArkNetworkSettings(dynamic activeNet) { @@ -26,6 +28,7 @@ public ArkNetworkSettings(dynamic activeNet) this.Fee.Delegate = activeNet.Fees.Delegate; this.Fee.SecondSignature = activeNet.Fees.SecondSignature; this.Fee.MultiSignature = activeNet.Fees.MultiSignature; + this.PeerSeedList = activeNet.Peers; } } diff --git a/ark-net/ark-net.csproj b/ark-net/ark-net.csproj index ce50cda..1e7f63e 100644 --- a/ark-net/ark-net.csproj +++ b/ark-net/ark-net.csproj @@ -112,11 +112,6 @@ - - True - True - Settings.settings - @@ -141,10 +136,6 @@ Always - - SettingsSingleFileGenerator - Settings.Designer.cs - diff --git a/ark-net/default.conf b/ark-net/default.conf index 96f52d5..dde528d 100644 --- a/ark-net/default.conf +++ b/ark-net/default.conf @@ -20,8 +20,55 @@ Vote: 100000000, Delegate: 2500000000, SecondSignature: 500000000, - MultiSignature: 500000000 - } + MultiSignature: 500000000, + DistributedApp: 2500000000 + }, + Peers : ["5.39.9.240:4001", + "5.39.9.241:4001", + "5.39.9.242:4001", + "5.39.9.243:4001", + "5.39.9.244:4001", + "5.39.9.250:4001", + "5.39.9.251:4001", + "5.39.9.252:4001", + "5.39.9.253:4001", + "5.39.9.254:4001", + "5.39.9.255:4001", + "5.39.53.48:4001", + "5.39.53.49:4001", + "5.39.53.50:4001", + "5.39.53.51:4001", + "5.39.53.52:4001", + "5.39.53.53:4001", + "5.39.53.54:4001", + "5.39.53.55:4001", + "37.59.129.160:4001", + "37.59.129.161:4001", + "37.59.129.162:4001", + "37.59.129.163:4001", + "37.59.129.164:4001", + "37.59.129.165:4001", + "37.59.129.166:4001", + "37.59.129.167:4001", + "37.59.129.168:4001", + "37.59.129.169:4001", + "37.59.129.170:4001", + "37.59.129.171:4001", + "37.59.129.172:4001", + "37.59.129.173:4001", + "37.59.129.174:4001", + "37.59.129.175:4001", + "193.70.72.80:4001", + "193.70.72.81:4001", + "193.70.72.82:4001", + "193.70.72.83:4001", + "193.70.72.84:4001", + "193.70.72.85:4001", + "193.70.72.86:4001", + "193.70.72.87:4001", + "193.70.72.88:4001", + "193.70.72.89:4001", + "193.70.72.90:4001"] }, TestNet: @@ -30,7 +77,7 @@ Port: 4000, BytePrefix: 24, Version: "1.0.0.", - NetHash: "6e84d08bd299ed97c212c886c98a57e36545c8f5d645ca7eeae63a8bd62d8988", + NetHash: "4befbd4cd1f2f10cbe69ac0b494b5ce070595ed23ee7abd386867c4edcdaf3bd", MaxNumOfBroadcasts: 5, Fees: { @@ -38,8 +85,10 @@ Vote: 100000000, Delegate: 2500000000, SecondSignature: 500000000, - MultiSignature: 500000000 - } + MultiSignature: 500000000, + DistributedApp: 2500000000 + }, + Peers: ["188.165.177.41:4000"] }, DevNet: @@ -48,7 +97,7 @@ Port: 3999, BytePrefix: 25, Version: "1.0.0.", - NetHash: "6e84d08bd299ed97c212c886c98a57e36545c8f5d645ca7eeae63a8bd62d8988", + NetHash: "4befbd4cd1f2f10cbe69ac0b494b5ce070595ed23ee7abd386867c4edcdaf3bd", MaxNumOfBroadcasts: 5, Fees: { @@ -56,7 +105,9 @@ Vote: 100000000, Delegate: 2500000000, SecondSignature: 500000000, - MultiSignature: 500000000 - } + MultiSignature: 500000000, + DistributedApp: 2500000000 + }, + Peers: ["188.165.177.41:4000"] } } \ No newline at end of file diff --git a/ark-netTests/Controller/AccountControllerTests.cs b/ark-netTests/Controller/AccountControllerTests.cs index b158ca5..683293e 100644 --- a/ark-netTests/Controller/AccountControllerTests.cs +++ b/ark-netTests/Controller/AccountControllerTests.cs @@ -44,7 +44,8 @@ public void SendMultisignArkTest() public void CreateAccountTest() { var accCtnrl = new AccountController("this is a top secret passphrase"); - + + Assert.AreEqual(accCtnrl.GetArkAccount().Address, "AGeYmgbg2LgGxRW2vNNJvQ88PknEJsYizC"); Assert.AreEqual(accCtnrl.GetArkAccount().PublicKey, "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192"); diff --git a/ark-netTests/Tests/NetworkTests.cs b/ark-netTests/Tests/NetworkTests.cs index 353559b..bb1cdc2 100644 --- a/ark-netTests/Tests/NetworkTests.cs +++ b/ark-netTests/Tests/NetworkTests.cs @@ -1,20 +1,27 @@ using System.IO; +using ArkNet; using ArkNet.Core; using ArkNet.Service; using ArkNet.Utils; +using ArkNet.Utils.Enum; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace ArkNetTest.Tests { - [TestClass] + [TestClass] public class NetworkTests { - /* TEST MAIN WALLET + /* TEST MAIN WALLET Adress: "AQLUKKKyKq5wZX7rCh4HJ4YFQ8bpTpPJgK" pass: ski rose knock live elder parade dose device fetch betray loan holiday */ + [TestInitialize] + public void Init() + { + ArkNetApi.Instance.Start(NetworkType.MainNet); + } - [TestMethod] + [TestMethod] public void PostTransactionNoBalanceTest() { var tx = TransactionApi.CreateTransaction("AXoXnFi4z1Z6aFvjEYkDVCtBGW2PaRiM25", diff --git a/ark-netTests/Tests/TransactionCryptoTests.cs b/ark-netTests/Tests/TransactionCryptoTests.cs index 39d5d85..ff4a483 100644 --- a/ark-netTests/Tests/TransactionCryptoTests.cs +++ b/ark-netTests/Tests/TransactionCryptoTests.cs @@ -30,7 +30,7 @@ public void GetKeysTest() [TestMethod] public void GetAddressTest() { - var a1 = Crypto.GetAddress(Crypto.GetKeys("this is a top secret passphrase")); + var a1 = Crypto.GetAddress(Crypto.GetKeys("this is a top secret passphrase"),ArkNetApi.Instance.NetworkSettings.BytePrefix); var a2 = "AGeYmgbg2LgGxRW2vNNJvQ88PknEJsYizC"; Assert.AreEqual(a2, a1);