Node.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * ZeroTier One - Global Peer to Peer Ethernet
  3. * Copyright (C) 2012-2013 ZeroTier Networks LLC
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * --
  19. *
  20. * ZeroTier may be used and distributed under the terms of the GPLv3, which
  21. * are available at: http://www.gnu.org/licenses/gpl-3.0.html
  22. *
  23. * If you would like to embed ZeroTier into a commercial application or
  24. * redistribute it in a modified binary form, please contact ZeroTier Networks
  25. * LLC. Start here: http://www.zerotier.com/
  26. */
  27. #ifndef _ZT_NODE_HPP
  28. #define _ZT_NODE_HPP
  29. namespace ZeroTier {
  30. /**
  31. * A ZeroTier One node
  32. *
  33. * This class hides all its implementation details and all other classes in
  34. * preparation for ZeroTier One being made available in library form for
  35. * embedding in mobile apps.
  36. */
  37. class Node
  38. {
  39. public:
  40. /**
  41. * Returned by node main if/when it terminates
  42. */
  43. enum ReasonForTermination
  44. {
  45. NODE_RUNNING = 0,
  46. NODE_NORMAL_TERMINATION = 1,
  47. NODE_RESTART_FOR_RECONFIGURATION = 2,
  48. NODE_UNRECOVERABLE_ERROR = 3,
  49. NODE_NEW_VERSION_AVAILABLE = 4
  50. };
  51. /**
  52. * Create a new node
  53. *
  54. * The node is not executed until run() is called.
  55. *
  56. * @param hp Home directory path
  57. */
  58. Node(const char *hp)
  59. throw();
  60. ~Node();
  61. /**
  62. * Execute node in current thread
  63. *
  64. * This does not return until the node shuts down. Shutdown may be caused
  65. * by an internally detected condition such as a new upgrade being
  66. * available or a fatal error, or it may be signaled externally using
  67. * the terminate() method.
  68. *
  69. * @return Reason for termination
  70. */
  71. ReasonForTermination run()
  72. throw();
  73. /**
  74. * Obtain a human-readable reason for node termination
  75. *
  76. * @return Reason for node termination or NULL if run() has not returned
  77. */
  78. const char *reasonForTermination() const
  79. throw();
  80. /**
  81. * Cause run() to return with NODE_NORMAL_TERMINATION
  82. *
  83. * This can be called from a signal handler or another thread to signal a
  84. * running node to shut down. Shutdown may take a few seconds, so run()
  85. * may not return instantly. Multiple calls are ignored.
  86. */
  87. void terminate()
  88. throw();
  89. /**
  90. * Get the ZeroTier version in major.minor.revision string format
  91. *
  92. * @return Version in string form
  93. */
  94. static const char *versionString()
  95. throw();
  96. static unsigned int versionMajor() throw();
  97. static unsigned int versionMinor() throw();
  98. static unsigned int versionRevision() throw();
  99. private:
  100. void *const _impl; // private implementation
  101. };
  102. /**
  103. * An embedded version code that can be searched for in the binary
  104. *
  105. * This shouldn't be used by users, but is exported to make certain that
  106. * the linker actually includes it in the image.
  107. */
  108. extern const unsigned char EMBEDDED_VERSION_STAMP[20];
  109. } // namespace ZeroTier
  110. #endif