示例#1
0
        public MetashareSession Start()
        {
            Metainfo metainfo;

            byte[] bytes = Bytes.Random(20000);

            using (FileSandbox temp = new FileSandbox(new EmptyFileLocator()))
            {
                MetainfoBuilder builder = new MetainfoBuilder(temp.Directory);
                string          path    = temp.CreateFile("debian-8.5.0-amd64-CD-1.iso");

                File.WriteAllBytes(path, bytes);
                builder.AddFile(path);

                metainfo = builder.ToMetainfo(out bytes);
            }

            FileSandbox sandbox     = new FileSandbox(new EmptyFileLocator());
            string      destination = Path.Combine(sandbox.Directory, metainfo.Hash.ToString());

            File.WriteAllBytes(destination + ".metainfo", bytes);

            CoordinatorService glue =
                new CoordinatorBuilder()
                .WithHash(metainfo.Hash)
                .WithMemory(new MemoryBuilder().Build())
                .WithPlugin(new MetadataPlugin(new MetadataHooks()))
                .Build();

            MetafileService metafile =
                new MetafileBuilder()
                .WithHash(metainfo.Hash)
                .WithDestination(destination + ".metainfo")
                .WithFiles(files)
                .WithPipeline(pipeline)
                .Build();

            MetashareService service =
                new MetashareBuilder()
                .WithHash(metainfo.Hash)
                .WithPipeline(pipeline)
                .WithGlue(glue)
                .WithMetafile(metafile)
                .Build();

            TaskCompletionSource <bool> onVerified = new TaskCompletionSource <bool>();

            metafile.Hooks.OnMetafileVerified += _ => onVerified.SetResult(true);

            metafile.Start();
            metafile.Verify();
            onVerified.Task.Wait(5000);

            return(new MetashareSession(service));
        }
示例#2
0
        private void StartMetaShare()
        {
            MetashareHooks hooks = new MetashareHooks
            {
            };

            MetaShare =
                new MetashareBuilder()
                .WithHash(Hash)
                .WithGlue(Coordinator)
                .WithPipeline(Pipeline)
                .WithMetafile(MetaStore)
                .Build(hooks);

            MetaShare.Start();
        }