Skip to content
This repository has been archived by the owner on Sep 3, 2018. It is now read-only.

Commit

Permalink
-improved peerseed list (related to various confis)
Browse files Browse the repository at this point in the history
-speedups!
-removed fixed parameters for versionin
-cleanup of network api!
  • Loading branch information
kristjank committed May 7, 2017
1 parent addd1ed commit cc6553b
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 329 deletions.
7 changes: 5 additions & 2 deletions ark-net/Controller/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions ark-net/Core/Crypto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
89 changes: 5 additions & 84 deletions ark-net/Core/NetworkApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,108 +10,29 @@ public sealed class NetworkApi
private static readonly Lazy<NetworkApi> lazy =
new Lazy<NetworkApi>(() => new NetworkApi());

private static readonly Random random = new Random();

//private static volatile NetworkApi instance;
private static readonly Random random = new Random();
private readonly List<PeerApi> peers = new List<PeerApi>();

private readonly List<string> peerseed = new List<string>
{
"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<PeerApi>();
WarmUp();
}

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;
public string Version { get; set; } = ArkNetApi.Instance.NetworkSettings.Version;
public int BroadcastMax { get; set; } = ArkNetApi.Instance.NetworkSettings.MaxNumOfBroadcasts;
public PeerApi ActivePeer { get; set; }

public dynamic GetHeaders(bool retJson = false)
{
var data = new Dictionary<string, dynamic> {["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();
Expand Down
8 changes: 4 additions & 4 deletions ark-net/Core/PeerApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions ark-net/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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("")]

Expand All @@ -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")]
161 changes: 0 additions & 161 deletions ark-net/Properties/Settings.Designer.cs

This file was deleted.

Loading

0 comments on commit cc6553b

Please sign in to comment.