One.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2015 ZeroTier, Inc.
  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_ONE_HPP
  28. #define ZT_ONE_HPP
  29. namespace ZeroTier {
  30. class NetworkConfigMaster;
  31. /**
  32. * ZeroTier One -- local VPN/NVF service built around ZeroTier core
  33. *
  34. * Actual implementation is under the fold, hence the pure virtual
  35. * interface.
  36. */
  37. class One
  38. {
  39. public:
  40. /**
  41. * Returned by node main if/when it terminates
  42. */
  43. enum ReasonForTermination
  44. {
  45. /**
  46. * Instance is still running
  47. */
  48. ONE_STILL_RUNNING = 0,
  49. /**
  50. * Normal shutdown
  51. */
  52. ONE_NORMAL_TERMINATION = 1,
  53. /**
  54. * A serious unrecoverable error has occurred
  55. */
  56. ONE_UNRECOVERABLE_ERROR = 2,
  57. /**
  58. * Your identity has collided with another
  59. */
  60. ONE_IDENTITY_COLLISION = 3
  61. };
  62. /**
  63. * Create and start a new instance of the service
  64. *
  65. * @param hp Home path
  66. * @param port TCP and UDP port for packets and HTTP control
  67. * @param master Instance of network config master if this instance is to act as one (default: NULL)
  68. * @param overrideRootTopology String-serialized root topology (for testing, default: NULL)
  69. */
  70. static One *newInstance(
  71. const char *hp,
  72. unsigned int port,
  73. NetworkConfigMaster *master = (NetworkConfigMaster *)0),
  74. const char *overrideRootTopology = (const char *)0);
  75. /**
  76. * Deletion will block until service stops if it's still running
  77. */
  78. virtual ~One();
  79. /**
  80. * @return Reason for terminating or ONE_STILL_RUNNING if running
  81. */
  82. virtual ReasonForTermination reasonForTermination() = 0;
  83. /**
  84. * @return Fatal error message or empty string if none
  85. */
  86. virtual std::string fatalErrorMessage() = 0;
  87. /**
  88. * Block until service terminates
  89. */
  90. virtual void waitForTermination() = 0;
  91. /**
  92. * Terminate background service
  93. *
  94. * Actual shutdown might take a few seconds.
  95. */
  96. virtual void terminate() = 0;
  97. /**
  98. * @return True if service is still running
  99. */
  100. inline isRunning() const { return (this->reasonForTermination() == ONE_STILL_RUNNING); }
  101. protected:
  102. One() {}
  103. private:
  104. One(const One &one) {}
  105. inline One &operator=(const One &one) { return *this; }
  106. };
  107. } // namespace ZeroTier
  108. #endif