Beispiel #1
0
        public void MigrarCid()
        {
            var conexao = Conexao.CreateSessionFactoryOracle();
            CidsIntegracao defs = new CidsIntegracao(conexao.OpenSession());

            var listaCidIntegracao = defs.All<CidMigracao>();

            Cids repositorioCid = new Cids(Conexao.CreateSessionFactory().OpenSession());

            List<Cid> listaCid = new List<Cid>();

            foreach (var cidIntegracao in listaCidIntegracao)
            {
                var cid = new Cid();
                cid.Code = cidIntegracao.CodigoCid;
                cid.Description = cidIntegracao.Descricao;

                listaCid.Add(cid);
            }

            repositorioCid.SalvarLista(listaCid);
        }
 public void Deconstruct(out Delta delta, out Cid cid)
 {
     delta = Delta;
     cid   = Cid;
 }
 /// <inheritdoc />
 public Task <Stream> ReadAsync(Cid cid,
                                CancellationToken cancellationToken = default)
 {
     _logger.Debug("Reading content at path {0} from Ipfs", cid);
     return(_ipfs.FileSystem.ReadFileAsync(cid, cancellationToken));
 }
Beispiel #4
0
 /// <summary>
 ///    Adds the <see cref="Cid"/> and <see cref="Peer"/> to the content routing system.
 /// </summary>
 /// <param name="cid">
 ///   The ID of some content that the <paramref name="provider"/> contains.
 /// </param>
 /// <param name="provider">
 ///   The peer ID that contains the <paramref name="cid"/>.
 /// </param>
 public void Add(Cid cid, MultiHash provider)
 {
     Add(cid, provider, DateTime.Now);
 }
Beispiel #5
0
 public Task <IDataBlock> StatAsync(Cid id, CancellationToken cancel = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
Beispiel #6
0
 /// <inheritdoc />
 public async Task <Stream> ReadAsync(Cid cid,
                                      CancellationToken cancellationToken = default)
 {
     _logger.Debug("Reading content at path {0} from Dfs", cid);
     return(await _ipfs.FileSystem.ReadFileAsync(cid, cancellationToken).ConfigureAwait(false));
 }
Beispiel #7
0
 public async Task <bool> IsPinnedAsync(Cid id, CancellationToken cancel = default(CancellationToken))
 {
     return(await Store.ExistsAsync(id, cancel).ConfigureAwait(false));
 }
Beispiel #8
0
 public Task <IEnumerable <Cid> > RemoveAsync(Cid id, bool recursive = true, CancellationToken cancel = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
 public Task ProvideAsync(Cid cid, bool advertise = true, CancellationToken cancel = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
Beispiel #10
0
 private string Key(Cid cid)
 {
     return("/providers/" + cid.Hash.ToBase32());
 }
Beispiel #11
0
        public async Task <DagNode> GetAsync(Cid id, CancellationToken cancel = default(CancellationToken))
        {
            var block = await ipfs.Block.GetAsync(id, cancel).ConfigureAwait(false);

            return(new DagNode(block.DataStream));
        }
Beispiel #12
0
        public async Task <Stream> DataAsync(Cid id, CancellationToken cancel = default(CancellationToken))
        {
            var node = await GetAsync(id, cancel).ConfigureAwait(false);

            return(node.DataStream);
        }
Beispiel #13
0
 public Task <IEnumerable <Peer> > FindProvidersAsync(Cid id, CancellationToken cancel = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
Beispiel #14
0
        public async Task <IEnumerable <Peer> > FindProvidersAsync(Cid id, CancellationToken cancel = default(CancellationToken))
        {
            var stream = await ipfs.PostDownloadAsync("dht/findprovs", cancel, id);

            return(ProviderFromStream(stream));
        }
Beispiel #15
0
 /// <inheritdoc />
 public async Task <string> ReadTextAsync(Cid cid, CancellationToken cancellationToken = default)
 {
     return(await _fileSystem.File.ReadAllTextAsync(Path.Combine(_baseFolder.FullName, cid),
                                                    Encoding.UTF8,
                                                    cancellationToken));
 }
Beispiel #16
0
 /// <inheritdoc />
 public async Task <Stream> ReadAsync(Cid cid, CancellationToken cancellationToken = default)
 {
     return(await Task.FromResult(_fileSystem.File.OpenRead(Path.Combine(_baseFolder.FullName, cid)))
            .ConfigureAwait(false));
 }
Beispiel #17
0
 public string GetCandidateListCacheKey(Cid previousDeltaHash)
 {
     return(nameof(DeltaElector) + "-" + previousDeltaHash);
 }
Beispiel #18
0
 public async Task UnwantAsync(Cid id, CancellationToken cancel = default(CancellationToken))
 {
     (await ipfs.BitswapService.ConfigureAwait(false)).Unwant(id);
 }
Beispiel #19
0
 public static Cid ToCid(this byte[] cid)
 {
     return(Cid.Decode(MultiBase.Encode(cid, Encoding)));
 }
Beispiel #20
0
 private static bool InternalCheckHash(byte[] data, Cid cid) => cid.Prefix.Sum(data) == cid;
        /// <summary>
        ///   Resolve an "IPFS path" to a content ID.
        /// </summary>
        /// <param name="path">
        ///   A IPFS path, such as "Qm...", "Qm.../a/b/c" or "/ipfs/QM..."
        /// </param>
        /// <param name="cancel">
        ///   Is used to stop the task.  When cancelled, the <see cref="TaskCanceledException"/> is raised.
        /// </param>
        /// <returns>
        ///   The content ID of <paramref name="path"/>.
        /// </returns>
        /// <exception cref="ArgumentException">
        ///   The <paramref name="path"/> cannot be resolved.
        /// </exception>
        public async Task <Cid> ResolveIpfsPathToCidAsync(string path, CancellationToken cancel = default(CancellationToken))
        {
            var r = await Generic.ResolveAsync(path, true, cancel).ConfigureAwait(false);

            return(Cid.Decode(r.Remove(0, 6)));  // strip '/ipfs/'.
        }
Beispiel #22
0
 public Task <Stream> DataAsync(Cid id, CancellationToken cancel = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
Beispiel #23
0
 public Task <Cid> RemoveAsync(Cid id, bool ignoreNonexistent = false, CancellationToken cancel = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
Beispiel #24
0
 public Task <DagNode> GetAsync(Cid id, CancellationToken cancel = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
Beispiel #25
0
 string Key(Cid cid) => "/providers/" + cid.Hash.ToBase32();
Beispiel #26
0
 public Task <IEnumerable <IMerkleLink> > LinksAsync(Cid id, CancellationToken cancel = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
 /// <inheritdoc />
 public Task <string> ReadTextAsync(Cid cid,
                                    CancellationToken cancellationToken = default)
 {
     _logger.Debug("Reading content at path {0} from IPFS", cid);
     return(_ipfs.FileSystem.ReadAllTextAsync(cid, cancellationToken));
 }
Beispiel #28
0
 public static Cid ToCid(this string cid)
 {
     //MultiBase.Encode(cid.ToUtf8Bytes(), Encoding)
     return(Cid.Decode(cid));
 }
Beispiel #29
0
 /// <summary>
 ///   Get the strong ETag for a CID.
 /// </summary>
 protected EntityTagHeaderValue ETag(Cid id)
 {
     return(new EntityTagHeaderValue(new StringSegment("\"" + id + "\""), isWeak: false));
 }
Beispiel #30
0
        public async Task <IDataBlock> GetAsync(Cid id, CancellationToken cancel = default)
        {
            // Hack for empty object and empty directory object
            var emptyDirectory = GetEmptyDirectory();

            if (id == emptyDirectory.Id)
            {
                return(emptyDirectory);
            }

            var emptyNode = GetEmptyNode();

            if (id == emptyNode.Id)
            {
                return(emptyNode);
            }

            // If identity hash, then CID has the content.
            if (id.Hash.IsIdentityHash)
            {
                return(new DataBlock
                {
                    DataBytes = id.Hash.Digest,
                    Id = id,
                    Size = id.Hash.Digest.Length
                });
            }

            // Check the local filesystem for the block.
            var block = await Store.TryGetAsync(id, cancel).ConfigureAwait(false);

            if (block != null)
            {
                return(block);
            }

            // Query the network, via DHT, for peers that can provide the
            // content.  As a provider peer is found, it is connected to and
            // the bitSwap want lists are exchanged.  Hopefully the provider will
            // then send the block to us via bitSwap and the get task will finish.
            using (var queryCancel = CancellationTokenSource.CreateLinkedTokenSource(cancel))
            {
                var bitswapGet = await _bitSwapApi.GetAsync(id, queryCancel.Token).ConfigureAwait(false);

                var _ = _dhtApi.FindProvidersAsync(
                    id,
                    20, // TODO: remove this
                    peer =>
                {
                    var __ = ProviderFoundAsync(peer, queryCancel.Token).ConfigureAwait(false);
                },
                    queryCancel.Token
                    );

                //log.Debug("bitswap got the block");

                queryCancel.Cancel(false); // stop the network query.
                return(bitswapGet);
            }

            //using (var queryCancel = CancellationTokenSource.CreateLinkedTokenSource(cancel))
            //{
            //    var bitSwapGet = _bitSwapApi.GetAsync(id, queryCancel.Token).ConfigureAwait(false);

            //    var providers = await _dhtApi.FindProvidersAsync(
            //        id: id,
            //        cancel: queryCancel.Token
            //    );

            //    var enumerable = providers as Peer[] ?? providers.ToArray();
            //    for (var index = 0; index < enumerable.ToArray().Length; index++)
            //    {
            //        var peer = enumerable.ToArray()[index];
            //        var _ = ProviderFoundAsync(peer, queryCancel.Token).ConfigureAwait(false);
            //    }

            //    var got = await bitSwapGet;
            //    Log.Debug("bitSwap got the block");

            //    queryCancel.Cancel(false); // stop the network query.
            //    return got;
            //}
        }
Beispiel #31
0
        public async Task <Cid> PutAsync(byte[] data,
                                         string contentType       = Cid.DefaultContentType,
                                         string multiHash         = MultiHash.DefaultAlgorithmName,
                                         string encoding          = MultiBase.DefaultAlgorithmName,
                                         bool pin                 = false,
                                         CancellationToken cancel = default)
        {
            if (data.Length > _dfsOptions.Block.MaxBlockSize)
            {
                throw new ArgumentOutOfRangeException($"data.Length",
                                                      $@"Block length can not exceed {_dfsOptions.Block.MaxBlockSize.ToString()}.");
            }

            // Small enough for an inline CID?
            if (_dfsOptions.Block.AllowInlineCid && data.Length <= _dfsOptions.Block.InlineCidLimit)
            {
                return(new Cid
                {
                    ContentType = contentType,
                    Hash = MultiHash.ComputeHash(data, "identity")
                });
            }

            // CID V1 encoding defaulting to base32 which is not
            var cid = new Cid
            {
                ContentType = contentType,
                Hash        = MultiHash.ComputeHash(data, multiHash)
            };

            if (encoding != "base58btc")
            {
                cid.Encoding = encoding;
            }

            var block = new DataBlock
            {
                DataBytes = data,
                Id        = cid,
                Size      = data.Length
            };

            if (await Store.ExistsAsync(cid, cancel).ConfigureAwait(false))
            {
                Log.DebugFormat("Block '{0}' already present", cid);
            }
            else
            {
                await Store.PutAsync(cid, block, cancel).ConfigureAwait(false);

                if (_dfsState.IsStarted)
                {
                    await _dhtApi.ProvideAsync(cid, false, cancel).ConfigureAwait(false);
                }

                Log.DebugFormat("Added block '{0}'", cid);
            }

            // Inform the BitSwap service.
            _bitSwapApi.FoundBlock(block);

            // To pin or not.
            if (pin)
            {
                await PinApi.AddAsync(cid, false, cancel).ConfigureAwait(false);
            }
            else
            {
                await PinApi.RemoveAsync(cid, false, cancel).ConfigureAwait(false);
            }

            return(cid);
        }
Beispiel #32
0
 public void TokenCallback(ParadoxParser parser, string token)
 {
     switch (token)
     {
         case "actual_added_value": actualAddedValue = parser.ReadInt32(); break;
         case "value": value = parser.ReadInt32(); break;
         case "from": from = parser.ReadInt32(); break;
         case "modifier": modifier = parser.Parse(new Cid()); break;
     }
 }