public static void Start(string path, string configfile) { Runner.PingTime = 4373; Type t = Type.GetType("Mono.Runtime"); if (t != null) { Runner.Mono = true; } else { Runner.Mono = false; } SimpleMesh.Service.Runner.StorePath = path; SimpleMesh.Service.Runner.ConfigFile = configfile; SimpleMesh.Service.Runner.Network = new Trackfile(); SimpleMesh.Service.Runner.Read(); try { NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface adapter in adapters) { IPInterfaceProperties adapterProperties = adapter.GetIPProperties(); foreach (IPAddressInformation unicast in adapterProperties.UnicastAddresses) { if (unicast.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { string[] chunks = unicast.Address.ToString().Split('.'); if (chunks[0] != "169") { Info.Addresses.Add(unicast.Address); } } else { Info.Addresses.Add(unicast.Address); } } } } catch { } if (Info.Addresses.Count == 0) { try { System.Net.IPHostEntry myiphost = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()); foreach (System.Net.IPAddress myipadd in myiphost.AddressList) { Info.Addresses.Add(myipadd); } } catch { if (Runner.Mono == true) { Info.Addresses.Add(IPAddress.Any); Info.Addresses.Add(IPAddress.IPv6Any); } } } Info.Compile(); SimpleMesh.Service.Runner.Write(); SimpleMesh.Service.Runner.DebugMessage("Debug.Info.ConfigFile", SimpleMesh.Service.Runner.StorePath); SimpleMesh.Service.Runner.DebugMessage("Debug.Info.ConfigFile", SimpleMesh.Service.Runner.ConfigFile); string TrackfilePath = SimpleMesh.Service.Runner.StorePath + System.IO.Path.DirectorySeparatorChar + @"default.tkf"; Runner.DebugMessage("Debug.Info.Trackfile", "Trackfile Path: " + TrackfilePath); if (System.IO.File.Exists(TrackfilePath) == true) { SimpleMesh.Service.Runner.Network.Read(TrackfilePath); } else { Dictionary <string, string> Hints = SimpleMesh.Service.Runner.NetworkSpecCallback(); string type; string trackfilelocation; if (Hints.TryGetValue("trackfilelocation", out trackfilelocation) == false) { return; } if (Hints.TryGetValue("type", out type) == true) { switch (type) { case "create": string name; if (Hints.TryGetValue("name", out name) == true) { SimpleMesh.Service.Runner.Network.Name = name; } else { SimpleMesh.Service.Runner.Network.Name = "Undefined"; } string keylength; Key scratch = new Key(); if (Hints.TryGetValue("enrollkeylength", out keylength) == true) { scratch.Generate("RSA", keylength); } else { scratch.Generate("RSA"); } Auth temp = new Auth(); temp.UUID = new UUID(); temp.Key = scratch; SimpleMesh.Service.Runner.Network.Enrollment.Add(temp.UUID.ToString(), temp); break; case "enroll": Network.ReadOnce(trackfilelocation); break; } try { Network.WriteOnce(trackfilelocation); } catch { } } } SimpleMesh.Service.Runner.Network.Write(TrackfilePath); /* * string inputstring = "Test"; * byte[] ciphertext; * byte[] plaintext; * Network.Node.Key.Encrypt(true, UTF8Encoding.UTF8.GetBytes(inputstring), out ciphertext); * Network.Node.Key.Decrypt(true, ciphertext, out plaintext); * Console.WriteLine("output string = " + UTF8Encoding.UTF8.GetString(plaintext)); * Console.ReadLine(); */ Runner.Native = true; Network.Start(); }
public static void Start(string path, string configfile) { Runner.PingTime = 4373; Type t = Type.GetType("Mono.Runtime"); if (t != null) { Runner.Mono = true; } else { Runner.Mono = false; } SimpleMesh.Service.Runner.StorePath = path; SimpleMesh.Service.Runner.ConfigFile = configfile; SimpleMesh.Service.Runner.Network = new Trackfile(); SimpleMesh.Service.Runner.Read(); try { NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface adapter in adapters) { IPInterfaceProperties adapterProperties = adapter.GetIPProperties(); foreach (IPAddressInformation unicast in adapterProperties.UnicastAddresses) { if (unicast.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { string[] chunks = unicast.Address.ToString().Split('.'); if (chunks[0] != "169") { Info.Addresses.Add(unicast.Address); } } else { Info.Addresses.Add(unicast.Address); } } } } catch { } if (Info.Addresses.Count == 0) { try { System.Net.IPHostEntry myiphost = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()); foreach (System.Net.IPAddress myipadd in myiphost.AddressList) { Info.Addresses.Add(myipadd); } } catch { if (Runner.Mono == true) { Info.Addresses.Add(IPAddress.Any); Info.Addresses.Add(IPAddress.IPv6Any); } } } Info.Compile(); SimpleMesh.Service.Runner.Write(); SimpleMesh.Service.Runner.DebugMessage("Debug.Info.ConfigFile", SimpleMesh.Service.Runner.StorePath); SimpleMesh.Service.Runner.DebugMessage("Debug.Info.ConfigFile", SimpleMesh.Service.Runner.ConfigFile); string TrackfilePath = SimpleMesh.Service.Runner.StorePath + System.IO.Path.DirectorySeparatorChar + @"default.tkf"; Runner.DebugMessage("Debug.Info.Trackfile", "Trackfile Path: " + TrackfilePath); if (System.IO.File.Exists(TrackfilePath) == true) { SimpleMesh.Service.Runner.Network.Read(TrackfilePath); } else { Dictionary<string, string> Hints = SimpleMesh.Service.Runner.NetworkSpecCallback(); string type; string trackfilelocation; if (Hints.TryGetValue("trackfilelocation", out trackfilelocation) == false) { return; } if (Hints.TryGetValue("type", out type) == true) { switch (type) { case "create": string name; if (Hints.TryGetValue("name", out name) == true) { SimpleMesh.Service.Runner.Network.Name = name; } else { SimpleMesh.Service.Runner.Network.Name = "Undefined"; } string keylength; Key scratch = new Key(); if (Hints.TryGetValue("enrollkeylength", out keylength) == true) { scratch.Generate("RSA", keylength); } else { scratch.Generate("RSA"); } Auth temp = new Auth(); temp.UUID = new UUID(); temp.Key = scratch; SimpleMesh.Service.Runner.Network.Enrollment.Add(temp.UUID.ToString(), temp); break; case "enroll": Network.ReadOnce(trackfilelocation); break; } try { Network.WriteOnce(trackfilelocation); } catch { } } } SimpleMesh.Service.Runner.Network.Write(TrackfilePath); /* string inputstring = "Test"; byte[] ciphertext; byte[] plaintext; Network.Node.Key.Encrypt(true, UTF8Encoding.UTF8.GetBytes(inputstring), out ciphertext); Network.Node.Key.Decrypt(true, ciphertext, out plaintext); Console.WriteLine("output string = " + UTF8Encoding.UTF8.GetString(plaintext)); Console.ReadLine(); */ Runner.Native = true; Network.Start(); }
private int ReadFile(string filename) { string[] configfile; try { configfile = System.IO.File.ReadAllLines(filename); } catch { Runner.DebugMessage("Debug.Error.Trackfile", "File not found: " + filename.ToString()); return 1; } Boolean firstline = true; foreach (string line in configfile) { string LineType; if (line.Length != 0) { LineType = line.Substring(0, 1); } else { LineType = "EMPTY"; } if (firstline == true) { firstline = false; string[] chunks = line.Split('!'); if (LineType == "I") { this._versiontype = chunks[1]; this._createddate = chunks[2]; this._lastmodifieddate = chunks[3]; this._name = chunks[4]; this._nethash = chunks[5]; } } else { switch (this._versiontype) { case "1.1": string[] chunks = line.Split('!'); string UUID; string keystring; Node scratch; switch (chunks[0]) { case "#": break; case "EMPTY": break; case "N": UUID = chunks[1]; if (UUID != Node.UUID.ToString()) { scratch = this.NodeInit(UUID); scratch.Name = chunks[2]; } break; case "C": UUID = chunks[1]; if (UUID != Node.UUID.ToString()) { scratch = this.NodeInit(UUID); string connectorstring = line.Replace("C!" + chunks[1] + "!", ""); Connector scratchconnector = new Connector(connectorstring); scratchconnector.Type = Connector.ConnectorTypes.Connect; scratch.ConnectorList.Add(scratchconnector.Key(), scratchconnector); } break; case "A": UUID = chunks[1]; if (UUID != Node.UUID.ToString()) { scratch = this.NodeInit(UUID); keystring = line.Replace("A!" + chunks[1] + "!" + chunks[2] + "!" + chunks[3] + "!", ""); Auth auth = new Auth(keystring, BoolUnpack(chunks[3]), BoolUnpack(chunks[4])); scratch.AuthKeyList.Add(auth.UUID, auth); } break; case "E": UUID = chunks[1]; keystring = line.Replace("E!" + chunks[1] + "!" + chunks[2] + "!" + chunks[3] + "!", ""); this.Enrollment.Add(UUID, new Auth(keystring, BoolUnpack(chunks[2]), BoolUnpack(chunks[3]))); break; } break; } } } string message = "Enrollment Keys"; foreach (KeyValuePair<string, Auth> enrolled in this.Enrollment) { message += "\n\t" + enrolled.Value.Key.ToString(); } SimpleMesh.Service.Runner.DebugMessage("Debug.Info.Trackfile", message); foreach (KeyValuePair<string, Node> line in this.NodeList) { Node scratch = line.Value; message = "Name=\t" + scratch.Name; message += "\nUUID=\t" + scratch.UUID; message += "\nAuthentication:"; foreach (KeyValuePair<UUID, Auth> auth in scratch.AuthKeyList) { message += "\n\t" + auth.Value.Key.ToString(); } message += "\nConnectors:"; foreach (KeyValuePair<string, Connector> connector in scratch.ConnectorList) { message += "\n\t" + connector.Value.ToString(); } SimpleMesh.Service.Runner.DebugMessage("Debug.Info.Trackfile", message); } this._new = false; return 0; }