RuntimeEnvironment.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #include "Condition.hpp"
  32. namespace ZeroTier {
  33. class NodeConfig;
  34. class Logger;
  35. class Demarc;
  36. class Switch;
  37. class Topology;
  38. class SysEnv;
  39. class Multicaster;
  40. class CMWC4096;
  41. /**
  42. * Holds global state for an instance of ZeroTier::Node
  43. *
  44. * I do not believe in mutable static variables, period, or in global static
  45. * instances of objects that don't basically represent constants. It makes
  46. * unit testing, embedding, threading, and other things hard and is poor
  47. * practice.
  48. *
  49. * So we put everything that we would want to be global, like Logger, here
  50. * and we give everybody this as _r. The Node creates and initializes this
  51. * on startup and deletes things on shutdown.
  52. */
  53. class RuntimeEnvironment
  54. {
  55. public:
  56. RuntimeEnvironment() :
  57. log((Logger *)0),
  58. prng((CMWC4096 *)0),
  59. nc((NodeConfig *)0),
  60. demarc((Demarc *)0),
  61. multicaster((Multicaster *)0),
  62. sw((Switch *)0),
  63. topology((Topology *)0),
  64. sysEnv((SysEnv *)0)
  65. {
  66. }
  67. std::string homePath;
  68. // signal() to prematurely interrupt main loop wait
  69. Condition mainLoopWaitCondition;
  70. Identity identity;
  71. // Order matters a bit here. These are constructed in this order
  72. // and then deleted in the opposite order on Node exit.
  73. Logger *log; // may be null
  74. CMWC4096 *prng;
  75. NodeConfig *nc;
  76. Demarc *demarc;
  77. Multicaster *multicaster;
  78. Switch *sw;
  79. Topology *topology;
  80. SysEnv *sysEnv;
  81. };
  82. } // namespace ZeroTier
  83. #endif