RuntimeEnvironment.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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_RUNTIMEENVIRONMENT_HPP
  28. #define _ZT_RUNTIMEENVIRONMENT_HPP
  29. #include <string>
  30. #include "Identity.hpp"
  31. namespace ZeroTier {
  32. class NodeConfig;
  33. class Logger;
  34. class Demarc;
  35. class Switch;
  36. class Topology;
  37. class SysEnv;
  38. class Multicaster;
  39. /**
  40. * Holds global state for an instance of ZeroTier::Node
  41. *
  42. * I do not believe in mutable static variables, period, or in global static
  43. * instances of objects that don't basically represent constants. It makes
  44. * unit testing, embedding, threading, and other things hard and is poor
  45. * practice.
  46. *
  47. * So we put everything that we would want to be global, like Logger, here
  48. * and we give everybody this as _r. The Node creates and initializes this
  49. * on startup and deletes things on shutdown.
  50. */
  51. class RuntimeEnvironment
  52. {
  53. public:
  54. RuntimeEnvironment() :
  55. identity(),
  56. log((Logger *)0),
  57. nc((NodeConfig *)0),
  58. demarc((Demarc *)0),
  59. multicaster((Multicaster *)0),
  60. sw((Switch *)0),
  61. topology((Topology *)0)
  62. {
  63. }
  64. std::string homePath;
  65. std::string autoconfUrlPrefix;
  66. std::string configAuthorityIdentityStr;
  67. std::string ownershipVerificationSecret;
  68. std::string ownershipVerificationSecretHash; // base64 of SHA-256 X16 rounds
  69. Identity configAuthority;
  70. Identity identity;
  71. Logger *log; // may be null
  72. NodeConfig *nc;
  73. Demarc *demarc;
  74. Multicaster *multicaster;
  75. Switch *sw;
  76. Topology *topology;
  77. SysEnv *sysEnv;
  78. };
  79. } // namespace ZeroTier
  80. #endif