|
6 | 6 | namespace Ipfs.Api |
7 | 7 | { |
8 | 8 | /// <summary> |
9 | | - /// Information about a peer node. |
| 9 | + /// An IPFS node. |
10 | 10 | /// </summary> |
11 | 11 | public class PeerNode |
12 | 12 | { |
13 | 13 | /// <summary> |
14 | 14 | /// Unique identifier (multihash) |
15 | 15 | /// </summary> |
| 16 | + /// <value> |
| 17 | + /// This is the <see cref="MultiHash"/> of the peer's <see cref="PublicKey"/>. |
| 18 | + /// </value> |
16 | 19 | public string Id { get; set; } |
17 | 20 |
|
18 | 21 | /// <summary> |
19 | 22 | /// The public key of the node. |
20 | 23 | /// </summary> |
| 24 | + /// <value> |
| 25 | + /// The base 64 encoding of the node's public key. |
| 26 | + /// </value> |
21 | 27 | public string PublicKey { get; set; } |
22 | 28 |
|
23 | 29 | /// <summary> |
24 | | - /// The multi addresses of the node. |
| 30 | + /// The multiple addresses of the node. |
25 | 31 | /// </summary> |
| 32 | + /// <value> |
| 33 | + /// Where the peer can be found. |
| 34 | + /// </value> |
26 | 35 | public IEnumerable<MultiAddress> Addresses { get; set; } |
27 | 36 |
|
28 | 37 | /// <summary> |
29 | | - /// TODO |
| 38 | + /// The name and version of the IPFS software. |
30 | 39 | /// </summary> |
| 40 | + /// <value> |
| 41 | + /// For example "go-ipfs/0.4.7/". |
| 42 | + /// </value> |
| 43 | + /// <remarks> |
| 44 | + /// There is no specification that describes the agent version string. |
| 45 | + /// </remarks> |
31 | 46 | public string AgentVersion { get; set; } |
32 | 47 |
|
33 | 48 | /// <summary> |
34 | | - /// TODO |
| 49 | + /// The name and version of the supported IPFS protocol. |
35 | 50 | /// </summary> |
| 51 | + /// <value> |
| 52 | + /// For example "go-ipfs/0.4.7/". |
| 53 | + /// </value> |
| 54 | + /// <remarks> |
| 55 | + /// There is no specification that describes the protocol version string. |
| 56 | + /// </remarks> |
36 | 57 | public string ProtocolVersion { get; set; } |
| 58 | + |
| 59 | + /// <summary> |
| 60 | + /// Determines if the information on the peer is valid. |
| 61 | + /// </summary> |
| 62 | + /// <returns> |
| 63 | + /// <b>true</b> if all validation rules pass; otherwise <b>false</b>. |
| 64 | + /// </returns> |
| 65 | + /// <remarks> |
| 66 | + /// Verifies that |
| 67 | + /// <list type="bullet"> |
| 68 | + /// <item>The <see cref="Id"/> is a hash of the <see cref="PublicKey"/></item> |
| 69 | + /// <item>All <see cref="Addresses"/> point to the node</item> |
| 70 | + /// </list> |
| 71 | + /// </remarks> |
| 72 | + public bool IsValid() |
| 73 | + { |
| 74 | + var mh = new MultiHash(Id); |
| 75 | + if (!mh.Matches(Convert.FromBase64String(PublicKey))) |
| 76 | + return false; |
| 77 | + if (!Addresses.All(a => |
| 78 | + a.Protocols.Last().Name == "ipfs" && |
| 79 | + a.Protocols.Last().Value == Id)) |
| 80 | + return false; |
| 81 | + return true; |
| 82 | + } |
37 | 83 | } |
38 | 84 | } |
0 commit comments