Skip to content

Commit

Permalink
feat(IGenericApi): add ping methods; closes #39
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider committed Aug 28, 2019
1 parent 06cc4c2 commit f0efcf5
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/CoreApi/IGenericApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,48 @@ Task<string> ResolveAsync(
CancellationToken cancel = default(CancellationToken)
);

/// <summary>
/// Send echo requests to a peer.
/// </summary>
/// <param name="peer">
/// The peer ID to receive the echo requests.
/// </param>
/// <param name="count">
/// The number of echo requests to send. Defaults to 10.
/// </param>
/// <param name="cancel">
/// Is used to stop the task. When cancelled, the <see cref="TaskCanceledException"/> is raised.
/// </param>
/// <returns>
/// A task that represents the asynchronous operation. The task's value is
/// the sequence of <see cref="PingResult"/>.
/// </returns>
Task<IEnumerable<PingResult>> PingAsync(
MultiHash peer,
int count = 10,
CancellationToken cancel = default(CancellationToken)
);

/// <summary>
/// Send echo requests to a peer.
/// </summary>
/// <param name="address">
/// The address of a peer to receive the echo requests.
/// </param>
/// <param name="count">
/// The number of echo requests to send. Defaults to 10.
/// </param>
/// <param name="cancel">
/// Is used to stop the task. When cancelled, the <see cref="TaskCanceledException"/> is raised.
/// </param>
/// <returns>
/// A task that represents the asynchronous operation. The task's value is
/// the sequence of <see cref="PingResult"/>.
/// </returns>
Task<IEnumerable<PingResult>> PingAsync(
MultiAddress address,
int count = 10,
CancellationToken cancel = default(CancellationToken)
);
}
}
27 changes: 27 additions & 0 deletions src/CoreApi/PingResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Ipfs.CoreApi
{
/// <summary>
/// The result from sending a <see cref="IGenericApi.PingAsync(MultiHash, int, System.Threading.CancellationToken)"/>.
/// </summary>
public class PingResult
{
/// <summary>
/// Indicates success or failure.
/// </summary>
public bool Success { get; set; }

/// <summary>
/// The round trip time; nano second resolution.
/// </summary>
public TimeSpan Time { get; set; }

/// <summary>
/// The text to echo.
/// </summary>
public string Text { get; set; }
}
}

0 comments on commit f0efcf5

Please sign in to comment.