Exemplo n.º 1
0
        /// <summary>
        ///   Main entry point.
        /// </summary>
        public static void Main(string[] args)
        {
            try
            {
                IpfsEngine = new IpfsEngine(passphrase.ToCharArray());
                IpfsEngine.StartAsync().Wait();

                BuildWebHost(args)
                .RunAsync(cancel.Token)
                .Wait();
            }
            catch (TaskCanceledException)
            {
                // eat it
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message); // TODO: better error handling
            }

            if (IpfsEngine != null)
            {
                IpfsEngine.StopAsync().Wait();
            }
        }
Exemplo n.º 2
0
        public PubSub(string passphrase)
        {
            var engine = new IpfsEngine(passphrase.ToCharArray());

            engine.StartAsync().Wait();
            coreApi = engine;
        }
Exemplo n.º 3
0
        public async Task UpgradeAsync(IpfsEngine ipfs, CancellationToken cancel = default(CancellationToken))
        {
            var path   = Path.Combine(ipfs.Options.Repository.Folder, "pins");
            var folder = new DirectoryInfo(path);

            if (!folder.Exists)
            {
                return;
            }

            var store = new FileStore <Cid, Pin1>
            {
                Folder    = path,
                NameToKey = (cid) => cid.Hash.ToBase32(),
                KeyToName = (key) => new MultiHash(key.FromBase32())
            };

            var files = folder.EnumerateFiles()
                        .Where(fi => fi.Length == 0);

            foreach (var fi in files)
            {
                try
                {
                    var cid = Cid.Decode(fi.Name);
                    await store.PutAsync(cid, new Pin1 { Id = cid }, cancel).ConfigureAwait(false);

                    File.Delete(fi.FullName);
                }
                catch
                {
                }
            }
        }
Exemplo n.º 4
0
    async static Task <Stream> ReturnText(string hash)
    {
        Batteries.Init();

        var ipfs = new IpfsEngine("".ToCharArray());
        var data = await ipfs.FileSystem.ReadFileAsync(hash);

        return(data);
    }
Exemplo n.º 5
0
        protected override async Task <int> OnExecute(CommandLineApplication app)
        {
            // TODO: Add option --pass
            string passphrase = "this is not a secure pass phrase";
            var    ipfs       = new IpfsEngine(passphrase.ToCharArray());

            await ipfs.MigrationManager.MirgrateToVersionAsync(Version);

            return(0);
        }
Exemplo n.º 6
0
        private void Dispose(bool disposing)
        {
            if (!disposing)
            {
                return;
            }

            _ipfs?.Dispose();
            _ipfs = null;
        }
Exemplo n.º 7
0
        /// <summary>
        ///   Creates a new instance of the <see cref="MigrationManager"/> class
        ///   for the specifed <see cref="IpfsEngine"/>.
        /// </summary>
        public MigrationManager(IpfsEngine ipfs)
        {
            this.ipfs = ipfs;

            Migrations = typeof(MigrationManager).Assembly
                         .GetTypes()
                         .Where(x => typeof(IMigration).IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract)
                         .Select(x => (IMigration)Activator.CreateInstance(x))
                         .OrderBy(x => x.Version)
                         .ToList();
        }
 /// <summary>
 ///   Creates a new instance of the <see cref="MigrationManager"/> class
 ///   for the specifed <see cref="IpfsEngine"/>.
 /// </summary>
 public MigrationManager(IpfsEngine ipfs)
 {
     this.ipfs  = ipfs;
     Migrations = typeof(MigrationManager).Assembly
                  .GetTypes()
                  .Where(x => typeof(IMigration).IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract)
                  .Select(x => (IMigration)Activator.CreateInstance(x))
                  .OrderBy(x => x.Version)
                  .ToList();
     log.Debug("Checking and assigning default Migration1 to avoid exceptions if none other migrations found");
     Migrations = Migrations.DefaultIfEmpty(new MigrateTo1()).ToList();
 }
Exemplo n.º 9
0
    async static Task <Ipfs.Cid> AddObjectSaveHash(string hash)
    {
        Batteries.Init();

        using (var ie = new IpfsEngine("".ToCharArray()))
        {
            var newdata = await ie.FileSystem.AddFileAsync(hash)
                          .ConfigureAwait(false);

            return(newdata.Id);
        }
    }
        public IpfsAdapter(IPasswordManager passwordReader,
                           IFileSystem fileSystem,
                           ILogger logger,
                           string swarmKey = "07a8e9d0c43400927ab274b7fa443596b71e609bacae47bd958e5cd9f59d6ca3",
                           IEnumerable <MultiAddress> seedServers = null)
        {
            if (seedServers == null || seedServers.Count() == 0)
            {
                seedServers = new[]
                {
                    new MultiAddress("/ip4/165.22.209.154/tcp/4001/ipfs/18n3naE9kBZoVvgYMV6saMZdzVq4jUMZsJKddJPrwWjkcwtf23ZcGFW2xUCmSE29ABRs"),
                    new MultiAddress("/ip4/165.22.226.50/tcp/4001/ipfs/18n3naE9kBZoVvgYMV6saMZe2jBdLcqbqE6qLfApXJLPr855vycKygWXnRsMVXuW8o1E"),
                    new MultiAddress("/ip4/167.71.129.154/tcp/4001/ipfs/18n3naE9kBZoVvgYMV6saMZe79QPeKgXsvTvVTPV732TnSya3MqQ5YUMcGHZFxW1VAEC"),
                    new MultiAddress("/ip4/167.71.79.54/tcp/4001/ipfs/18n3naE9kBZoVvgYMV6saMZe4BowwZZyjRazPAMd5VhWBfvM88Qcyy3viWGQ8fzEhcvc"),
                    new MultiAddress("/ip4/167.71.79.77/tcp/4001/ipfs/18n3naE9kBZoVvgYMV6saMZe64FqVyvgWoLYBktgShFe6oEYeDWox8o2WhA8brQu5dBA"),
                    new MultiAddress("/ip4/165.22.175.71/tcp/4001/ipfs/18n3naE9kBZoVvgYMV6saMZdwHHKV44GJfKE9ecyRXHcXY4yNtEExgPSvvwsDtvZspZj"),
                    new MultiAddress("/ip4/165.22.234.49/tcp/4001/ipfs/18n3naE9kBZoVvgYMV6saMZdxSv6GpHsHAVYb51xvH3y4xvGVztM1h1GEsUjEzqc8Wh4"),
                    new MultiAddress("/ip4/167.71.134.31/tcp/4001/ipfs/18n3naE9kBZoVvgYMV6saMZe4SkF2tXtZbBMUSsmbosM5SAJaU3oxUAbReFDBaKeHqR3")
                };
            }

            _logger = logger;

            // The password is used to access the private keys.
            var password = passwordReader.RetrieveOrPromptAndAddPasswordToRegistry(PasswordRegistryTypes.IpfsPassword, "Please provide your IPFS password");

            _ipfs = new IpfsEngine(password);
            _ipfs.Options.KeyChain.DefaultKeyType = Constants.KeyChainDefaultKeyType;

            // The IPFS repository is inside the catalyst home folder.
            _ipfs.Options.Repository.Folder = Path.Combine(
                fileSystem.GetCatalystDataDir().FullName,
                Constants.DfsDataSubDir);

            // The seed nodes for the catalyst network.
            _ipfs.Options.Discovery.BootstrapPeers = seedServers;

            // Do not use the public IPFS network, use a private network
            // of catalyst only nodes.
            _ipfs.Options.Swarm.PrivateNetworkKey = new PreSharedKey
            {
                Value = swarmKey.ToHexBuffer()
            };

            _logger.Information("IPFS configured.");
        }
Exemplo n.º 11
0
        /// <summary>
        ///   The main entry point of the program.
        /// </summary>
        /// <param name="args">TODO</param>
        public static void Main(string[] args)
        {
            IpfsEngine = new IpfsEngine(passphrase.ToCharArray());
            IpfsEngine.Start();

            try
            {
                using (var gateway = new GatewayHost(IpfsEngine))
                {
                    Thread.Sleep(Timeout.Infinite);
                }
            }
            finally
            {
                IpfsEngine.Stop();
            }
        }
Exemplo n.º 12
0
        public IpfsAdapter(IPasswordManager passwordReader,
                           IFileSystem fileSystem,
                           ILogger logger,
                           string swarmKey = "07a8e9d0c43400927ab274b7fa443596b71e609bacae47bd958e5cd9f59d6ca3",
                           IEnumerable <MultiAddress> seedServers = null)
        {
            if (seedServers == null || seedServers.Count() == 0)
            {
                seedServers = new[]
                {
                    new MultiAddress("/ip4/46.101.132.61/tcp/4001/ipfs/18n3naE9kBZoVvgYMV6saMZdtAkDHgs8MDwwhtyLu8JpYitY4Nk8jmyGgQ4Gt3VKNson"),
                    new MultiAddress("/ip4/188.166.13.135/tcp/4001/ipfs/18n3naE9kBZoVvgYMV6saMZe2AAPTCoujCxhJHECaySDEsPrEz9W2u7uo6hAbJhYzhPg"),
                    new MultiAddress("/ip4/167.172.73.132/tcp/4001/ipfs/18n3naE9kBZoVvgYMV6saMZe1E9wXdykR6h3Q9EaQcQc6hdNAXyCTEzoGfcA2wQgCRyg")
                };
            }

            _logger = logger;

            // The password is used to access the private keys.
            var password = passwordReader.RetrieveOrPromptAndAddPasswordToRegistry(PasswordRegistryTypes.IpfsPassword, "Please provide your IPFS password");

            _ipfs = new IpfsEngine(password);
            _ipfs.Options.KeyChain.DefaultKeyType = Constants.KeyChainDefaultKeyType;

            // The IPFS repository is inside the catalyst home folder.
            _ipfs.Options.Repository.Folder = Path.Combine(
                fileSystem.GetCatalystDataDir().FullName,
                Constants.DfsDataSubDir);

            // The seed nodes for the catalyst network.
            _ipfs.Options.Discovery.BootstrapPeers = seedServers;

            // Do not use the public IPFS network, use a private network
            // of catalyst only nodes.
            _ipfs.Options.Swarm.PrivateNetworkKey = new PreSharedKey
            {
                Value = swarmKey.ToHexBuffer()
            };

            _logger.Information("IPFS configured.");
        }
Exemplo n.º 13
0
 public StatsApi(IpfsEngine ipfs)
 {
     this.ipfs = ipfs;
 }
Exemplo n.º 14
0
 public ObjectApi(IpfsEngine ipfs)
 {
     this.ipfs = ipfs;
 }
Exemplo n.º 15
0
 public SwarmApi(IpfsEngine ipfs)
 {
     this.ipfs = ipfs;
 }
Exemplo n.º 16
0
 public NameApi(IpfsEngine ipfs)
 {
     this.ipfs = ipfs;
 }
Exemplo n.º 17
0
 public PinApi(IpfsEngine ipfs)
 {
     this.ipfs = ipfs;
 }
Exemplo n.º 18
0
 public ConfigApi(IpfsEngine ipfs)
 {
     this.ipfs = ipfs;
 }
Exemplo n.º 19
0
 public GenericApi(IpfsEngine ipfs)
 {
     this.ipfs = ipfs;
 }
Exemplo n.º 20
0
 public KeyApi(IpfsEngine ipfs)
 {
     this.ipfs = ipfs;
 }
Exemplo n.º 21
0
 public BootstrapApi(IpfsEngine ipfs)
 {
     this.ipfs = ipfs;
 }
Exemplo n.º 22
0
 public BlockApi(IpfsEngine ipfs)
 {
     this.ipfs = ipfs;
 }
Exemplo n.º 23
0
 /// <summary>
 ///   Create a new instance of the <see cref="KeyChain"/> class.
 /// </summary>
 /// <param name="ipfs">
 ///   The IPFS Engine associated with the key chain.
 /// </param>
 public KeyChain(IpfsEngine ipfs)
 {
     this.ipfs = ipfs;
 }
Exemplo n.º 24
0
 public PubSubApi(IpfsEngine ipfs)
 {
     this.ipfs = ipfs;
 }
Exemplo n.º 25
0
 public FileSystemApi(IpfsEngine ipfs)
 {
     this.ipfs = ipfs;
 }
Exemplo n.º 26
0
 public BitswapApi(IpfsEngine ipfs)
 {
     this.ipfs = ipfs;
 }
Exemplo n.º 27
0
 public DagApi(IpfsEngine ipfs)
 {
     this.ipfs = ipfs;
 }
 public BlockRepositoryApi(IpfsEngine ipfs)
 {
     this.ipfs = ipfs;
 }