RuntimeEnvironment.hpp 2.4 KB

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