public static void Fill(Node position, int range, SuperNode supernode) { var openQueue = new Utils.PriorityQueue <VisitedNode>(); var pathNodeMap = new Dictionary <Node, VisitedNode>(); pathNodeMap[position] = new VisitedNode(position, null, 0); openQueue.Enqueue(pathNodeMap[position], 0); while (!openQueue.IsEmpty()) { var current = openQueue.Dequeue(); current.GridNode.ConnectSuperNode(current.Prev != null ? current.Prev.GridNode : null, supernode, current.GScore); foreach (var neighbour in current.GridNode.GetNeighbours()) { if (!neighbour.To.SuperNodes.ContainsKey(supernode) && neighbour.Length + current.GScore <= range) { var newNode = new VisitedNode(neighbour.To, current, neighbour.Length); if (pathNodeMap.ContainsKey(neighbour.To)) { if (openQueue.Update(pathNodeMap[neighbour.To], pathNodeMap[neighbour.To].GScore, newNode, newNode.GScore)) { pathNodeMap[neighbour.To] = newNode; } } else { openQueue.Enqueue(newNode, newNode.GScore); pathNodeMap[neighbour.To] = newNode; } } } } }
public void RegisterExport(SuperNode node) { if (!string.IsNullOrEmpty(node.id)) { exports[node.id] = node; } }
private void PrintDisplayTree(SuperNode node, int current_depth) { string tab = ""; for (int i = 0; i < current_depth; i++) { tab = tab + " "; } tab = tab + "-->"; //TODO: GET RECT TRANSFORM POSITIONS if (node.name == null) { Debug.Log(tab + node.GetType() + " " + node.GetComponent <RectTransform>().position); } else { Debug.Log(tab + node.gameObject.name + " " + node.GetComponent <RectTransform>().position); } if (node is SuperContainer) { SuperContainer container = node as SuperContainer; Transform transform = container.GetComponent <Transform>(); foreach (Transform child in transform) { PrintDisplayTree(child.GetComponent <SuperNode>(), current_depth + 1); } } }
internal static void UpdateNode(SuperNode snode, long chatId) { try { if (GetNode(ip: snode.IP, user: chatId)?.IP == null) { return; } var context = new SuperNodeDataContext(); var node = context.SuperNodes .Where(predicate: e => e.OwnedByUser == snode.OwnedByUser) .Single(predicate: e => e.IP == snode.IP); node.LastTest = snode.LastTest; node.WentOffLine = snode.WentOffLine; context.SubmitChanges(); } catch (Exception ex) { Console.WriteLine("update node " + ex.Message); } }
public static SuperNode CreateWithChildren(int count, IEntityFactory f, Func <IEntityFactory, INode> createFunc) { SuperNode sn = new SuperNode(f); for (int i = 0; i < count; i++) { sn.Nodes.Add(createFunc(f)); } return(sn); }
internal static SupernodeResponseData.Supernodes AddNode(long chatId, SupernodeResponseData.Supernodes nodes) { var list = new SupernodeResponseData.Supernodes() { data = new List <SupernodeResponseData.Nodes>() }; var context = new SuperNodeDataContext(); try { foreach (var node in nodes.data) { var n = GetNode(ip: node.ip, user: chatId); if (n?.IP != null && n?.OwnedByUser == chatId) { continue; } ; var snode = new SuperNode() { OwnedByUser = chatId, IP = node.ip, LastTest = 0, DepositAddress = node.payoutAddress, SNodeID = node.id, Alias = node.alias }; context.SuperNodes.InsertOnSubmit(entity: snode); list.data.Add(item: node); } context.SubmitChanges(); } catch (Exception e) { Console.WriteLine("add node " + e.StackTrace); } return(list); }
public void RecursivelyCollectSuperNodes(Transform transform, List <SuperNode> working) { if (transform.childCount == 0) { return; } foreach (Transform child in transform) { RecursivelyCollectSuperNodes(child, working); SuperNode node = child.gameObject.GetComponent <SuperNode>(); if (node != null) { working.Add(node); } } }
private async Task Nofity(SuperNode node, string msg) { try { var reqAction = new SendMessage(chatId: (long)node.OwnedByUser, text: msg); await bot.MakeRequestAsync(request : reqAction); } catch (Exception e) { if (e.Message.Contains("blocked")) { AccountUtils.DeleteAccountsByUser(node.OwnedByUser); NodeUtils.DeleteUserNodes(node.OwnedByUser); UserUtils.DeleteUser(node.OwnedByUser); } } }
public static void FillNeigbours(SuperNode superNode, int gridSize) { var nodesToFill = superNode.GetNeighbours().Select(n => n.To).ToArray(); var openQueue = new Utils.PriorityQueue <VisitedNode>(); var pathNodeMap = new Dictionary <Node, VisitedNode>(); foreach (var childNode in superNode.ChildNodes) { if (childNode.SuperNodes[superNode].Length > gridSize * 0.8) { pathNodeMap[childNode] = new VisitedNode(childNode, null, childNode.SuperNodes[superNode].Length); openQueue.Enqueue(pathNodeMap[childNode], pathNodeMap[childNode].GScore); } } while (!openQueue.IsEmpty()) { var current = openQueue.Dequeue(); if (!current.GridNode.SuperNodes.ContainsKey(superNode)) { current.GridNode.ConnectSuperNode(current.Prev != null ? (current.Prev.GridNode ?? superNode) : superNode, superNode, current.GScore); } foreach (var neighbour in current.GridNode.GetNeighbours()) { if (!neighbour.To.SuperNodes.ContainsKey(superNode) && neighbour.To.SuperNodes.Any(k => k.Value.Length <= gridSize && nodesToFill.Contains(k.Key))) { var newNode = new VisitedNode(neighbour.To, current, neighbour.Length); if (pathNodeMap.ContainsKey(neighbour.To)) { if (openQueue.Update(pathNodeMap[neighbour.To], pathNodeMap[neighbour.To].GScore, newNode, newNode.GScore)) { pathNodeMap[neighbour.To] = newNode; } } else { openQueue.Enqueue(newNode, newNode.GScore); pathNodeMap[neighbour.To] = newNode; } } } } }
private static void Main(string[] args) { var superNode = new SuperNode(); superNode.Start(); Console.WriteLine("SuperNode started.. Enter to send to tiny node"); Console.ReadLine(); //superNode.Send("tinynode", new SimpleMessage // { // Message = "My very simple message" // }); superNode.Publish("tinynode", new SimpleMessage { Message = "My very simple message" }); Console.ReadLine(); }
internal async Task ScanTests(SuperNode n) { try { var testTypes = new List <string>() { "node version test", "chain height test", "chain part test", "responsiveness test", "bandwidth test", "computing power test", "ping test", "node balance test" }; var superClient = new SupernodeClient(); superClient.BeginGetTestResults(ar => { try { if (ar.Content.data[0].round != n.LastTest) { var bitArray = new BitArray(new[] { ar.Content.data[0].testResult }); var passed = new bool[32]; bitArray.CopyTo(passed, 0); var passedBits = ToBitInts(bitArray); if (passedBits.Contains(0)) { var msg = "Node: " + n.Alias + "\nWith IP: " + n.IP + " \nfailed tests on " + "\nDate: " + ar.Content.data[0].dateAndTime.Substring(startIndex: 0, length: 10) + "\nTime: " + ar.Content.data[0].dateAndTime.Substring(startIndex: 11, length: 8) + "\n"; for (var index = 0; index < 8; index++) { var pass = passedBits[index]; if (pass == 0) { msg += pass == 0 ? testTypes[index] + ": failed\n" : testTypes[index] + ": passed\n"; } } try { msg += "https://supernodes.nem.io/details/" + n.SNodeID + "\n"; n.LastTest = ar.Content.data[0].round; NodeUtils.UpdateNode(snode: n, chatId: n.OwnedByUser); Console.WriteLine(msg); Nofity(node: n, msg: msg); } catch (Exception e) { Console.WriteLine("node scanner line 199: " + e.StackTrace); if (e.Message.Contains("blocked")) { UserUtils.DeleteUser(n.OwnedByUser); } } } } } catch (Exception ex) { Console.WriteLine("node scanner line 214: " + ex.Message); } }, new SupernodeStructures.TestResultRequestData { alias = n.Alias, numRounds = 1, roundFrom = -1 }); } catch (Exception e) { Console.WriteLine("node scanner line 225" + e.StackTrace); } }
public SuperNodeConnection(Node to, SuperNode superNode, float length) : base(to, length) { SuperNode = superNode; }
public ControlReference(string name, SuperNode control) { this.name = name; this.control = control; }
internal void GetSummary(string text, Chat chat) { int days; switch (text) { case "/dailySummary": days = 1; break; case "/sevenDaySummary": days = 7; break; case "/thirtyOneDaySummary": days = 31; break; default: try { days = int.Parse(s: Regex.Replace(input: text.Substring(startIndex: text.LastIndexOf(value: ':') + 1), pattern: @"[\s]+", replacement: string.Empty)); break; } catch (Exception) { var reqAction = new SendMessage(chatId: chat.Id, text: "Please insert the number of days for which you want a summary. eg. \"/customSummary: 4\""); var Bot = new TelegramBot(accessToken: ConfigurationManager.AppSettings[name: "accessKey"]); Bot.MakeRequestAsync(request: reqAction); return; } } var acc = AccountUtils.GetAccountByUser(chatId: chat.Id); var nodes = NodeUtils.GetAllNodes(); foreach (var address in acc) { SuperNode nodeAlias = null; try { nodeAlias = nodes.Single(predicate: x => x.DepositAddress == address.EncodedAddress); } catch (Exception) { } var txsummaries = SummaryUtils.GetTxSummary(account: address.EncodedAddress, days: days, chatId: chat.Id); var txIn = txsummaries.Count(predicate: e => address.EncodedAddress == e.Recipient); var txOut = txsummaries.Count(predicate: e => address.EncodedAddress != e.Recipient); var txValueIn = txsummaries.Where(predicate: x => txsummaries.Any(predicate: y => y.AmountIn > 0)).ToList() .Select(selector: e => e.AmountIn) .Sum() / 1000000; var txValueOut = txsummaries.Where(predicate: x => txsummaries.Any(predicate: y => y.AmountIn > 0)).ToList() .Select(selector: e => e.AmountOut) .Sum() / 1000000; var snPayout = txsummaries.Where(predicate: x => txsummaries.Any(predicate: y => y.AmountIn > 0)).ToList() .Select(selector: e => e.AmountIn) .Where( predicate: x => txsummaries.Any( predicate: y => y.Sender == AddressEncoding.ToEncoded(network: 0x68, publicKey: new PublicKey( key: "d96366cdd47325e816ff86039a6477ef42772a455023ccddae4a0bd5d27b8d23")))) .Sum() / 1000000; var accountBalanceDifference = txValueIn - txValueOut; var totalTxs = txIn + txOut; var hbsummaries = SummaryUtils.GetHBSummary(account: address.EncodedAddress, days: days, chatId: chat.Id); var totalFees = hbsummaries.Where(predicate: x => hbsummaries.Any(predicate: y => y.FeesEarned > 0)).ToList() .Select(selector: e => e.FeesEarned) .Sum() / 1000000; var totalBlocks = hbsummaries.Count(predicate: e => address.EncodedAddress == e.MonitoredAccount); var reqAction = new SendMessage(chatId: chat.Id, text: "Summary for account: \n" + StringUtils.GetResultsWithHyphen(address.EncodedAddress) + "\n" + (nodeAlias != null ? ("Deposit address for node: " + nodeAlias.Alias + "\n") : "") + "Transactions in: " + txIn + "\n" + "Transactions out: " + txOut + "\n" + "Total transactions: " + totalTxs + "\n" + "Transactions value in: " + txValueIn + " XEM\n" + "Transactions value out: " + txValueOut + " XEM\n" + "Transactions value total: " + (txValueIn - txValueOut) + " XEM\n" + "Total supernode payout: " + snPayout + " XEM\n" + "Harvested blocks: " + totalBlocks + "\n" + "Total harvested fees: " + totalFees + " XEM\n" + "Change in balance: " + (accountBalanceDifference + totalFees) + " XEM\n" + "Final balance: " + aClient.EndGetAccountInfo(aClient.BeginGetAccountInfoFromAddress(address.EncodedAddress)) .Account.Balance / 1000000 + "\n" + "http://explorer.ournem.com/#/s_account?account=" + address.EncodedAddress ); var Bot = new TelegramBot(accessToken: ConfigurationManager.AppSettings[name: "accessKey"]); Bot.MakeRequestAsync(request: reqAction); } }