Example #1
0
        public void InitUpload(string file)
        {
            Hash h = new Hash();
            string name = h.SHA256(Util.RandomString(40, _Random));
            File.Copy(file, "local/" + _Address + "/" + name);

            Upload(name, 1);
        }
Example #2
0
        public void Upload(string name, int level)
        {
            Hash h = new Hash();
            //string path = "local/" + _Address + "/" + name;
            string key = Util.RandomString(40, _Random);
            string newname = h.SHA256(name);

            if (level < 8)
            {
                int nodes = (int)Math.Floor(8 / (double)level);
                EFile f = new EFile("local/" + _Address + "/" + name);
                f.Encrypt("local/" + _Address + "/" + newname, key);
                File.Delete("local/" + _Address + "/" + name);
                StreamWriter sw = new StreamWriter("local/" + _Address + "/" + name + "_key_" + level);
                sw.WriteLine(key);
                sw.Close();

                for (int i = 0; i < nodes; i++)
                {
                    int n = _Random.Next(0, _MaxAddressSize);
                    Node node = _Internet.GetNode(_AddressBook[n]);
                    try
                    {
                        File.Copy("local/" + _Address + "/" + newname, "local/" + node.Address + "/" + newname);
                        node.Upload(newname, level + 1);
                    }
                    catch { i--; } //Check if Node has that level. If not, move to next

                }

                File.Delete("local/" + _Address + "/" + newname);
            }
        }