Ejemplo n.º 1
0
        /// <summary>
        ///   Find the providers for content that is addressed by a hash.
        /// </summary>
        /// <param name="hash">
        ///   The <see cref="string"/> representation of a base58 encoded <see cref="Ipfs.MultiHash"/>.
        /// </param>
        /// <returns>
        ///   A sequence of IPFS peer IDs.
        /// </returns>
        public async Task <IEnumerable <string> > FindProvidersAsync(string hash)
        {
            var serializer = new JsonSerializer();
            var stream     = await ipfs.PostDownloadAsync("dht/findprovs", hash);

            return(ProviderFromStream(stream));
        }
Ejemplo n.º 2
0
        /// <summary>
        ///   Find the providers for content that is addressed by a hash.
        /// </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>
        /// <returns>
        ///   A sequence of IPFS peer IDs.
        /// </returns>
        public async Task <IEnumerable <string> > FindProvidersAsync(string hash, CancellationToken cancel = default(CancellationToken))
        {
            var serializer = new JsonSerializer();
            var stream     = await ipfs.PostDownloadAsync("dht/findprovs", cancel, hash);

            return(ProviderFromStream(stream));
        }
Ejemplo n.º 3
0
        /// <summary>
        ///   Subscribe to messages on a given topic.
        /// </summary>
        /// <param name="topic">
        ///   The topic name.
        /// </param>
        /// <param name="handler">
        ///   The action to perform when a <see cref="PublishedMessage"/> is received.
        /// </param>
        /// <param name="cancellationToken">
        ///   Is used to stop the topic listener.  When cancelled, the <see cref="OperationCanceledException"/>
        ///   is <b>NOT</b> raised.
        /// </param>
        /// <returns>
        ///   After the topic listener is register with the IPFS server.
        /// </returns>
        /// <remarks>
        ///   The <paramref name="handler"/> is invoked on the topic listener thread.
        /// </remarks>
        public async Task Subscribe(string topic, Action <PublishedMessage> handler, CancellationToken cancellationToken = default(CancellationToken))
        {
            var messageStream = await ipfs.PostDownloadAsync("pubsub/sub", cancellationToken, topic);

#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            Task.Run(() => ProcessMessages(topic, handler, messageStream, cancellationToken));
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            return;
        }
Ejemplo n.º 4
0
        /// <summary>
        ///   Subscribe to messages on a given topic.
        /// </summary>
        /// <param name="topic">
        ///   The topic name.
        /// </param>
        /// <param name="handler">
        ///   The action to perform when a <see cref="PublishedMessage"/> is received.
        /// </param>
        /// <param name="cancellationToken">
        ///   Is used to stop the topic listener.  When cancelled, the <see cref="OperationCanceledException"/>
        ///   is <b>NOT</b> raised.
        /// </param>
        /// <returns>
        ///   After the topic listener is register with the IPFS server.
        /// </returns>
        /// <remarks>
        ///   The <paramref name="handler"/> is invoked on the topic listener thread.
        /// </remarks>
        public async Task Subscribe(string topic, Action <PublishedMessage> handler, CancellationToken cancellationToken)
        {
            var messageStream = await ipfs.PostDownloadAsync("pubsub/sub", cancellationToken, topic);

            var sr       = new StreamReader(messageStream);
            var response = sr.ReadLine();

            if (log.IsDebugEnabled)
            {
                log.Debug("RSP " + response);
            }

            // First line is always an empty JSON object,
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            Task.Run(() => ProcessMessages(topic, handler, sr, cancellationToken));
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

            return;
        }
Ejemplo n.º 5
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));
        }