Beispiel #1
0
        public static void Main(string[] args, KeyStorage keyStorage)
        {
            //Usage
            if (args.Length != 4)
            {
                throw new HelpException("Missing arguments");
            }
            string sourcePath     = args [1];
            string repoPath       = args [2];
            string receipientName = args [3];

            //Source
            if (Directory.Exists(sourcePath) == false)
            {
                throw new HelpException("Source directory not found: " + sourcePath);
            }

            //Repo
            Repo repo = Repo.Create(repoPath);

            //Sender and Recipient keys
            PrivateKey senderKey    = keyStorage.DefaultKey;
            PublicKey  recipientKey = keyStorage.GetPublic(receipientName);

            //Prepare Route message recording of ChunkID
            RouteRepo rr = new RouteRepo(repo);

            //Prepare Encryption
            EncryptedRepo er = new EncryptedRepo(rr, null);

            er.AddKey(recipientKey);

            Console.Write("Generating Tree...");

            //Send Tree
            ChunkHash tree = TreeChunk.GenerateChunk(sourcePath, er);

            //TreeMessage
            TreeMessage tm   = new TreeMessage(tree, Path.GetDirectoryName(sourcePath));
            Chunk       tmc  = Message.ToChunk(tm, senderKey);
            ChunkHash   tmch = er.WriteChunk(tmc);

            er.StoreMessage("file", tmch);

            //RouteMessage
            RouteMessage rm = rr.RouteMessage;

            rm.MessageChunkHash = tmch.bytes;
            rm.To = receipientName;

            //Store unencrypted RouteMessage
            Chunk rmChunk = Message.ToChunk(rm);

            repo.WriteChunk(rmChunk);
            repo.StoreMessage("route", rmChunk.ChunkHash);
            Console.WriteLine("RouteMessage Stored");
        }
Beispiel #2
0
        public static void Main(string[] args, KeyStorage keyStorage)
        {
            if (args.Length != 4)
            {
                throw new HelpException("Missing arguments");
            }

            //Storage
            Repo repo = Repo.Create(args [1]);

            repo = new EncryptedRepo(repo, keyStorage);

            //Find message
            Chunk chunk = null;

            if (args [2].Length == 64)
            {
                ChunkHash id = ChunkHash.FromHashBytes(Hash.FromString(args [2]).bytes);
                chunk = repo.ReadChunk(id);
            }
            else
            {
                ICollection <ChunkHash> messages = repo.GetMessageList("file");
                foreach (ChunkHash bh in messages)
                {
                    if (bh.ToString().StartsWith(args [2]))
                    {
                        chunk = repo.ReadChunk(bh);
                    }
                }
            }

            Message message = Message.FromChunk(chunk, keyStorage);

            if (message == null)
            {
                Console.Error.WriteLine("Message not found");
                return;
            }
            TreeMessage tm = message as TreeMessage;

            if (tm == null)
            {
                Console.Error.WriteLine("Not a TreeMessage: " + message.GetType().Name);
                return;
            }

            Console.WriteLine("Found TreeMessage " + tm.Name);
            string targetPath = Path.Combine(args [3], tm.Name);

            TreeChunk.Extract(repo, ChunkHash.FromHashBytes(tm.TreeChunkHash), targetPath);
        }
Beispiel #3
0
    void CreateChunks()
    {
        Texture2D atlas = new Texture2D(1024, 1024);

        Rect[] rects = atlas.PackTextures(textures, 2);

        for (int x = 0; x < gen.widthInChunk; x++)
        {
            for (int z = 0; z < gen.lengthInChunk; z++)
            {
                TreeChunk chunk = Instantiate(prefChunk);
                chunk.SizeChunk = gen.sizeChunk;
                chunk.TileWidth = 1;
                chunk.GetComponent <MeshRenderer>().material.SetTexture("_MainTex", atlas);
                chunk.transform.SetParent(this.transform);
                chunk.transform.position = new Vector3(x * gen.sizeChunk, 0, z * gen.sizeChunk);
                chunk.CreateMesh(x, z, ref gen, rects);
            }
        }
    }