ZeroTierPeer.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Newtonsoft.Json;
  7. namespace WinUI
  8. {
  9. public class ZeroTierPeer : IEquatable<ZeroTierPeer>
  10. {
  11. [JsonProperty("address")]
  12. public string Address { get; set; }
  13. private Int64 _lastUnicast;
  14. [JsonProperty("lastUnicastFrame")]
  15. public Int64 LastUnicastFrame
  16. {
  17. get
  18. {
  19. if (_lastUnicast == 0)
  20. return 0;
  21. TimeSpan t = DateTime.UtcNow - new DateTime(1970, 1, 1);
  22. Int64 millisecondsSinceEpoch = (Int64)t.TotalMilliseconds;
  23. return (millisecondsSinceEpoch - _lastUnicast) / 1000;
  24. }
  25. set
  26. {
  27. _lastUnicast = value;
  28. }
  29. }
  30. private Int64 _lastMulticast;
  31. [JsonProperty("lastMulticastFrame")]
  32. public Int64 LastMulticastFrame
  33. {
  34. get
  35. {
  36. if (_lastMulticast == 0)
  37. return 0;
  38. TimeSpan t = DateTime.UtcNow - new DateTime(1970, 1, 1);
  39. Int64 millisecondsSinceEpoch = (Int64)t.TotalMilliseconds;
  40. return (millisecondsSinceEpoch - _lastMulticast) / 1000;
  41. }
  42. set
  43. {
  44. _lastMulticast = value;
  45. }
  46. }
  47. [JsonProperty("versionMajor")]
  48. public int VersionMajor { get; set; }
  49. [JsonProperty("versionMinor")]
  50. public int VersionMinor { get; set; }
  51. [JsonProperty("versionRev")]
  52. public int VersionRev { get; set; }
  53. [JsonProperty("version")]
  54. public string Version { get; set; }
  55. public string VersionString
  56. {
  57. get
  58. {
  59. if (Version == "-1.-1.-1")
  60. return "-";
  61. else
  62. return Version;
  63. }
  64. }
  65. [JsonProperty("latency")]
  66. public string Latency { get; set; }
  67. [JsonProperty("role")]
  68. public string Role { get; set; }
  69. [JsonProperty("paths")]
  70. public List<ZeroTierPeerPhysicalPath> Paths { get; set; }
  71. public string DataPaths
  72. {
  73. get
  74. {
  75. string pathStr = "";
  76. foreach(ZeroTierPeerPhysicalPath path in Paths)
  77. {
  78. pathStr += path.Address + "\n";
  79. }
  80. return pathStr;
  81. }
  82. }
  83. public bool Equals(ZeroTierPeer other)
  84. {
  85. return this.Address.Equals(other.Address, StringComparison.InvariantCultureIgnoreCase);
  86. }
  87. public void Update(ZeroTierPeer other)
  88. {
  89. _lastUnicast = other._lastUnicast;
  90. _lastMulticast = other._lastMulticast;
  91. VersionMajor = other.VersionMajor;
  92. VersionMinor = other.VersionMinor;
  93. VersionRev = other.VersionRev;
  94. Version = other.Version;
  95. Latency = other.Latency;
  96. Role = other.Role;
  97. Paths = other.Paths;
  98. }
  99. }
  100. }