-
Notifications
You must be signed in to change notification settings - Fork 139
/
IProtocol.cs
81 lines (76 loc) · 3.86 KB
/
IProtocol.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Libplanet.Net.Messages;
namespace Libplanet.Net.Protocols
{
/// <summary>
/// An interface of protocol to discover peers from the distributed network.
/// </summary>
public interface IProtocol
{
/// <summary>
/// Conducts peer discovery for given <paramref name="bootstrapPeers"/>.
/// </summary>
/// <param name="bootstrapPeers">A <see cref="IEnumerable{T}"/> of <see cref="BoundPeer"/>s
/// to bootstrap.</param>
/// <param name="dialTimeout">The timeout used when waiting a reply for either
/// <see cref="PingMsg"/> or <see cref="FindNeighborsMsg"/>.
/// If <c>null</c> is given, the task never halts by itself
/// even no any response was given from the the target seed.</param>
/// <param name="depth">Recursive operation depth to search peers from network.</param>
/// <param name="cancellationToken">
/// A cancellation token used to propagate notification that this
/// operation should be canceled.</param>
/// <returns>An awaitable task without value.</returns>
Task BootstrapAsync(
IEnumerable<BoundPeer> bootstrapPeers,
TimeSpan? dialTimeout,
int depth,
CancellationToken cancellationToken);
/// <summary>
/// Tries to add given <paramref name="peers"/> to routing table
/// by sending <see cref="PingMsg"/>.
/// </summary>
/// <param name="peers">The peers to add.</param>
/// <param name="timeout">A timeout of waiting for the reply of <see cref="PingMsg"/>
/// message sent to <paramref name="peers"/>.
/// If <c>null</c> is given, task never halts by itself
/// even the target peer gives no any response.</param>
/// <param name="cancellationToken">
/// A cancellation token used to propagate notification that this
/// operation should be canceled.</param>
/// <returns>An awaitable task without value.</returns>
Task AddPeersAsync(
IEnumerable<BoundPeer> peers,
TimeSpan? timeout,
CancellationToken cancellationToken);
/// <summary>
/// Checks whether <see cref="BoundPeer"/>s in <see cref="RoutingTable"/> is online by
/// sending <see cref="PingMsg"/>.
/// </summary>
/// <param name="maxAge">Maximum age of peer to validate.</param>
/// <param name="cancellationToken">A cancellation token used to propagate notification
/// that this operation should be canceled.</param>
/// <returns>An awaitable task without value.</returns>
Task RefreshTableAsync(TimeSpan maxAge, CancellationToken cancellationToken);
/// <summary>
/// Reconstructs network connection between peers on network.
/// </summary>
/// <param name="depth">Recursive operation depth to search peers from network.</param>
/// <param name="cancellationToken">A cancellation token used to propagate notification
/// that this operation should be canceled.</param>
/// <returns>An awaitable task without value.</returns>
Task RebuildConnectionAsync(int depth, CancellationToken cancellationToken);
/// <summary>
/// Checks the <see cref="KBucket"/> in the <see cref="RoutingTable"/> and if
/// there is an empty <see cref="KBucket"/>, fill it with <see cref="BoundPeer"/>s
/// in the <see cref="KBucket.ReplacementCache"/>.
/// </summary>
/// <param name="cancellationToken">A cancellation token used to propagate notification
/// that this operation should be canceled.</param>
/// <returns>An awaitable task without value.</returns>
Task CheckReplacementCacheAsync(CancellationToken cancellationToken);
}
}