public async Task DirectControlCommand(string aim, string command, string root_private) { try { int port = server.Port; IPAddress address; IPEndPoint target; int timeout = 0; byte[] command_bytes = Encoding.UTF8.GetBytes(command); byte[] signature = MakeAdminSignature(command_bytes, root_private); byte[] operation = AddOperation(command, AdminClass.command_size, signature); operation = AddOperation("admin", UDPServer.operation_size, operation); if (aim == null) { List <string> black_list = new List <string>(0); List <string> list_to = await server.GetKnownList(); list_to = server.RemoveIPAddresses(list_to, black_list); foreach (var ip_address in list_to) { address = IPAddress.Parse(ip_address); target = new IPEndPoint(address, port); await server.Send(target, operation); timeout++; window.WriteLine("Updating..." + target.ToString()); if (timeout % 20 == 0) { await Task.Delay(100); } } } else { address = IPAddress.Parse(aim); target = new IPEndPoint(address, port); window.WriteLine("Updating..." + target.ToString()); await server.Send(target, operation); } } catch (Exception ex) { window.WriteLine("Exception in AdminClass.DirectUpdate"); window.WriteLine(ex.ToString()); } }
public async Task CheckForUpdate() { IPAddress address; IPEndPoint target; int port = Convert.ToInt32(server.Port); byte[] operation_bytes; List <string> black_list = new List <string>(0); List <string> list_to = await server.GetKnownList(); list_to = server.RemoveIPAddresses(list_to, black_list); operation_bytes = server.OperationToBytes("update|tell", UDPServer.operation_size); if (list_to.Count > 0) { int timeout = 0; foreach (var ip_address in list_to) { address = IPAddress.Parse(ip_address); target = new IPEndPoint(address, port); await server.Send(target, operation_bytes); timeout++; window.WriteLine("Updating..." + timeout); if (timeout % 20 == 0) { await Task.Delay(100); } } } }
public async Task GetLogic(IPEndPoint source, byte[] data) { try { TwoBytesArrays tran = new TwoBytesArrays(); tran = ByteArrayCut(data, Transactions.size_suboperation); string sub_operation = BytesToOperation(tran.part1); string[] sub = sub_operation.Split('|'); string name; string path; List <string> ip_list = new List <string>(0); Transaction transaction = new Transaction(); window.WriteLine("[45]: " + sub[0] + " from " + source.ToString()); window.WriteLine("[46]: " + sub_operation); if (sub[0] == "new") { transaction = ParseTMessage(tran.part2); window.WriteLine("[tr] Transaction got: "); int check = await CheckTransaction(transaction); window.WriteLine("[tr] Checking result: " + check); if ((check == 2) || (check == 1)) { name = cryptography.HashToString(cryptography.GetSHA256Hash(tran.part2)); path = filesystem.FSConfig.db_path + @"\" + name; int status = await filesystem.AddInfoToFileAsync(path, tran.part2, true); if (status != 3) { byte[] message = Encoding.UTF8.GetBytes(name); message = AddOperation("confirm", Transactions.size_suboperation, message); message = AddOperation("transaction", UDPServer.operation_size, message); await server.Send(source, message); if (debug) { window.WriteLine("Transaction (" + name + ") confirmed to " + source.ToString()); } } int sub_times = Convert.ToInt32(sub[1]) - 1; if (sub_times >= 1) { List <string> known_hosts = await server.GetKnownList(); List <string> black_list = new List <string>(0); black_list.Add(source.Address.ToString()); black_list.AddRange(server.myIpAddresses); known_hosts = server.RemoveIPAddresses(known_hosts, black_list); //await SendTransaction(tran.part2, sub_times, known_hosts); } } } if (sub[0] == "confirm") { name = Encoding.UTF8.GetString(tran.part2); if (debug) { window.WriteLine("Transaction (" + name + ") confirmed by " + source.ToString()); } } ip_list.Add(source.Address.ToString()); await server.AddToKnownList(ip_list); } catch (Exception ex) { window.WriteLine(ex.ToString()); } }