RuntimeEnvironment.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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_RUNTIMEENVIRONMENT_HPP
  28. #define ZT_RUNTIMEENVIRONMENT_HPP
  29. #include <string>
  30. #include "Constants.hpp"
  31. #include "Identity.hpp"
  32. #include "Mutex.hpp"
  33. namespace ZeroTier {
  34. class NodeConfig;
  35. class Switch;
  36. class Topology;
  37. class Node;
  38. class Multicaster;
  39. class NetworkController;
  40. class SelfAwareness;
  41. class Cluster;
  42. class DeferredPackets;
  43. /**
  44. * Holds global state for an instance of ZeroTier::Node
  45. */
  46. class RuntimeEnvironment
  47. {
  48. public:
  49. RuntimeEnvironment(Node *n) :
  50. node(n)
  51. ,identity()
  52. ,localNetworkController((NetworkController *)0)
  53. ,sw((Switch *)0)
  54. ,mc((Multicaster *)0)
  55. ,topology((Topology *)0)
  56. ,sa((SelfAwareness *)0)
  57. ,dp((DeferredPackets *)0)
  58. #ifdef ZT_ENABLE_CLUSTER
  59. ,cluster((Cluster *)0)
  60. #endif
  61. ,dpEnabled(0)
  62. {
  63. }
  64. // Node instance that owns this RuntimeEnvironment
  65. Node *const node;
  66. // This node's identity
  67. Identity identity;
  68. std::string publicIdentityStr;
  69. std::string secretIdentityStr;
  70. // This is set externally to an instance of this base class
  71. NetworkController *localNetworkController;
  72. /*
  73. * Order matters a bit here. These are constructed in this order
  74. * and then deleted in the opposite order on Node exit. The order ensures
  75. * that things that are needed are there before they're needed.
  76. *
  77. * These are constant and never null after startup unless indicated.
  78. */
  79. Switch *sw;
  80. Multicaster *mc;
  81. Topology *topology;
  82. SelfAwareness *sa;
  83. DeferredPackets *dp;
  84. #ifdef ZT_ENABLE_CLUSTER
  85. Cluster *cluster;
  86. #endif
  87. // This is set to >0 if background threads are waiting on deferred
  88. // packets, otherwise 'dp' should not be used.
  89. volatile int dpEnabled;
  90. };
  91. } // namespace ZeroTier
  92. #endif