Beispiel #1
0
 public async Task <IKey> CreateAsync(string name, string keyType, int size, CancellationToken cancel = default(CancellationToken))
 {
     return(await ipfs.DoCommandAsync <KeyInfo>("key/gen", cancel,
                                                name,
                                                $"type={keyType}",
                                                $"size={size}"));
 }
Beispiel #2
0
        public async Task <IEnumerable <Cid> > AddAsync(string path, bool recursive = true, CancellationToken cancel = default(CancellationToken))
        {
            var opts = "recursive=" + recursive.ToString().ToLowerInvariant();
            var json = await ipfs.DoCommandAsync("pin/add", cancel, path, opts);

            return(((JArray)JObject.Parse(json)["Pins"])
                   .Select(p => (Cid)(string)p));
        }
Beispiel #3
0
        /// <summary>
        ///   Create a new MerkleDAG node, using a specific layout.
        /// </summary>
        /// <param name="template"><b>null</b> or "unixfs-dir".</param>
        /// <param name="cancel">
        ///   Is used to stop the task.  When cancelled, the <see cref="TaskCanceledException"/> is raised.
        /// </param>
        /// <returns></returns>
        /// <remarks>
        ///  Caveat: So far, only UnixFS object layouts are supported.
        /// </remarks>
        public async Task <DagNode> NewAsync(string template = null, CancellationToken cancel = default(CancellationToken))
        {
            var json = await ipfs.DoCommandAsync("object/new", cancel, template);

            var hash = (string)(JObject.Parse(json)["Hash"]);

            return(await GetAsync(hash));
        }
        /// <inheritdoc />
        public void Add(MultiAddress peer)
        {
            if (peer == null)
            {
                throw new ArgumentNullException();
            }

            ipfs.DoCommandAsync("bootstrap/add", peer.ToString()).Wait();
            peers = null;
        }
Beispiel #5
0
        /// <summary>
        ///   Adds an IPFS object to the pinset and also stores it to the IPFS repo. pinset is the set of hashes currently pinned (not gc'able).
        /// </summary>
        /// <param name="hash">
        ///   The <see cref="string"/> representation of a base58 encoded <see cref="Ipfs.MultiHash"/>.
        /// </param>
        /// <param name="recursive">
        ///   <b>true</b> to recursively pin links of object; otherwise, <b>false</b> to only pin
        ///   the specified object.  Default is <b>true</b>.
        /// </param>
        /// <param name="cancel">
        ///   Is used to stop the task.  When cancelled, the <see cref="TaskCanceledException"/> is raised.
        /// </param>
        public async Task <PinnedObject[]> AddAsync(string hash, bool recursive = true, CancellationToken cancel = default(CancellationToken))
        {
            var opts = "recursive=" + recursive.ToString().ToLowerInvariant();
            var json = await ipfs.DoCommandAsync("pin/add", cancel, hash, opts);

            return(((JArray)JObject.Parse(json)["Pins"])
                   .Select(p => new PinnedObject {
                Id = (string)p
            })
                   .ToArray());
        }
Beispiel #6
0
        /// <summary>
        ///   Get the peers in the current swarm.
        /// </summary>
        /// <returns></returns>
        public async Task <IEnumerable <PeerNode> > AddressesAsync()
        {
            var json = await ipfs.DoCommandAsync("swarm/addrs");

            return(((JObject)JObject.Parse(json)["Addrs"])
                   .Properties()
                   .Select(p => new PeerNode {
                Id = p.Name,
                Addresses = ((JArray)p.Value)
                            .Select(v => new MultiAddress((string)v))
            }));
        }
Beispiel #7
0
        public async Task <IEnumerable <Peer> > AddressesAsync(CancellationToken cancel = default(CancellationToken))
        {
            var json = await ipfs.DoCommandAsync("swarm/addrs", cancel);

            return(((JObject)JObject.Parse(json)["Addrs"])
                   .Properties()
                   .Select(p => new Peer {
                Id = p.Name,
                Addresses = ((JArray)p.Value)
                            .Select(v => new MultiAddress((string)v))
            }));
        }
Beispiel #8
0
        public async Task <MultiAddress> AddAsync(MultiAddress address, CancellationToken cancel = default(CancellationToken))
        {
            var json = await ipfs.DoCommandAsync("bootstrap/add", cancel, address.ToString());

            var addrs = (JArray)(JObject.Parse(json)["Peers"]);
            var a     = addrs.FirstOrDefault();

            if (a == null)
            {
                return(null);
            }
            return(new MultiAddress((string)a));
        }
        public void Do_Command_Throws_Exception_On_Invalid_Command()
        {
            IpfsClient target = TestFixture.Ipfs;
            object     unknown;

            ExceptionAssert.Throws <Exception>(() => unknown = target.DoCommandAsync("foobar").Result, "Invalid IPFS command");
        }
Beispiel #10
0
        public void Do_Command_Throws_Exception_On_Missing_Argument()
        {
            IpfsClient target = TestFixture.Ipfs;
            object     unknown;

            ExceptionAssert.Throws <HttpRequestException>(() => unknown = target.DoCommandAsync("key/gen", default(CancellationToken)).Result);
        }
Beispiel #11
0
        public void Do_Command_Throws_Exception_On_Invalid_Command()
        {
            IpfsClient target = TestFixture.Ipfs;
            object     unknown;

            ExceptionAssert.Throws <HttpRequestException>(() => unknown = target.DoCommandAsync("foobar", default(CancellationToken)).Result);
        }
Beispiel #12
0
        /// <summary>
        ///   Will resolve the ipfs path for the ipns entry passed in hash
        /// </summary>
        /// <param name="hash">
        ///   The <see cref="string"/> representation of a ipns entry
        /// </param>
        /// <param name="cancel"></param>
        /// <param name="cancel">
        ///   Is used to stop the task.  When cancelled, the <see cref="TaskCanceledException"/> is raised.
        /// </param>
        public async Task <string> ResolveAsync(string hash = null, CancellationToken cancel = default(CancellationToken))
        {
            string json = await ipfs.DoCommandAsync("name/resolve", cancel, hash);

            JObject jObject = JObject.Parse(json);

            return(jObject.Value <string>("Path"));
        }
Beispiel #13
0
        public async Task <IEnumerable <Cid> > WantsAsync(MultiHash peer = null, CancellationToken cancel = default(CancellationToken))
        {
            var json = await ipfs.DoCommandAsync("bitswap/wantlist", cancel, peer?.ToString());

            var keys = (JArray)(JObject.Parse(json)["Keys"]);

            // https://github.com/ipfs/go-ipfs/issues/5077
            return(keys
                   .Select(k =>
            {
                if (k.Type == JTokenType.String)
                {
                    return Cid.Decode(k.ToString());
                }
                var obj = (JObject)k;
                return Cid.Decode(obj["/"].ToString());
            }));
        }
 public void Do_Command_Throws_IpfsException_On_Invalid_Command()
 {
     IpfsClient target = new IpfsClient();
     object unknown;
     ExceptionAssert.Throws<IpfsException>(() => unknown = target.DoCommandAsync("foobar").Result, "Invalid command");
 }
Beispiel #15
0
 /// <summary>
 ///   Information on a raw <see cref="Block">IPFS block</see>.
 /// </summary>
 /// <param name="hash">
 ///   The <see cref="string"/> representation of a base58 encoded <see cref="Ipfs.MultiHash"/>.
 /// </param>
 /// <param name="cancel">
 ///   Is used to stop the task.  When cancelled, the <see cref="TaskCanceledException"/> is raised.
 /// </param>
 public Task <BlockInfo> StatAsync(string hash, CancellationToken cancel = default(CancellationToken))
 {
     return(ipfs.DoCommandAsync <BlockInfo>("block/stat", cancel, hash));
 }
Beispiel #16
0
        /// <summary>
        ///   Fetch a MerkleDAG node.
        /// </summary>
        /// <param name="hash">
        ///   The <see cref="string"/> representation of an encoded <see cref="Ipfs.MultiHash"/>.
        /// </param>
        /// <returns></returns>
        public async Task <DagNode> GetAsync(string hash)
        {
            var json = await ipfs.DoCommandAsync("object/get", hash);

            return(GetDagFromJson(json));
        }
Beispiel #17
0
        /// <summary>
        ///   Fetch a MerkleDAG node.
        /// </summary>
        /// <param name="hash">
        ///   The <see cref="string"/> representation of an encoded <see cref="Ipfs.MultiHash"/>.
        /// </param>
        /// <param name="cancel">
        ///   Is used to stop the task.  When cancelled, the <see cref="TaskCanceledException"/> is raised.
        /// </param>
        /// <returns></returns>
        public async Task <DagNode> GetAsync(string hash, CancellationToken cancel = default(CancellationToken))
        {
            var json = await ipfs.DoCommandAsync("object/get", cancel, hash);

            return(GetDagFromJson(json));
        }
Beispiel #18
0
 /// <summary>
 ///   Information on a raw <see cref="Block">IPFS block</see>.
 /// </summary>
 /// <param name="hash">
 ///   The <see cref="string"/> representation of a base58 encoded <see cref="Ipfs.MultiHash"/>.
 /// </param>
 public Task <BlockInfo> StatAsync(string hash)
 {
     return(ipfs.DoCommandAsync <BlockInfo>("block/stat", hash));
 }