コード例 #1
0
ファイル: Auth.cs プロジェクト: heliocentric/simplemesh
 public Auth(string keystring, Boolean active, Boolean primary)
 {
     this.Key = new Key(keystring);
     this.Active = active;
     this.Primary = primary;
     this.UUID = this.Key.UUID;
 }
コード例 #2
0
ファイル: Auth.cs プロジェクト: heliocentric/simplemesh
        public Auth(string keystring)
        {

            this.Key = new Key(keystring);
            this.Active = true;
            this.Primary = false;
            this.UUID = this.Key.UUID;
        }
コード例 #3
0
ファイル: Runner.cs プロジェクト: heliocentric/simplemesh
        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();

        }