RuntimeEnvironment.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2017 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. * --
  19. *
  20. * You can be released from the requirements of the license by purchasing
  21. * a commercial license. Buying such a license is mandatory as soon as you
  22. * develop commercial closed-source software that incorporates or links
  23. * directly against ZeroTier software without disclosing the source code
  24. * of your own application.
  25. */
  26. #ifndef ZT_RUNTIMEENVIRONMENT_HPP
  27. #define ZT_RUNTIMEENVIRONMENT_HPP
  28. #include <string.h>
  29. #include "Constants.hpp"
  30. #include "Utils.hpp"
  31. #include "Identity.hpp"
  32. namespace ZeroTier {
  33. class NodeConfig;
  34. class Switch;
  35. class Topology;
  36. class Node;
  37. class Multicaster;
  38. class NetworkController;
  39. class SelfAwareness;
  40. class Cluster;
  41. /**
  42. * Holds global state for an instance of ZeroTier::Node
  43. */
  44. class RuntimeEnvironment
  45. {
  46. public:
  47. RuntimeEnvironment(Node *n) :
  48. node(n)
  49. ,identity()
  50. ,localNetworkController((NetworkController *)0)
  51. ,sw((Switch *)0)
  52. ,mc((Multicaster *)0)
  53. ,topology((Topology *)0)
  54. ,sa((SelfAwareness *)0)
  55. {
  56. Utils::getSecureRandom(&instanceId,sizeof(instanceId));
  57. memset(publicIdentityStr,0,sizeof(publicIdentityStr));
  58. memset(secretIdentityStr,0,sizeof(secretIdentityStr));
  59. }
  60. ~RuntimeEnvironment()
  61. {
  62. Utils::burn(secretIdentityStr,sizeof(secretIdentityStr));
  63. }
  64. /**
  65. * A random integer identifying this running instance in a cluster
  66. */
  67. uint64_t instanceId;
  68. // Node instance that owns this RuntimeEnvironment
  69. Node *const node;
  70. // This node's identity
  71. Identity identity;
  72. char publicIdentityStr[ZT_IDENTITY_STRING_BUFFER_LENGTH];
  73. char secretIdentityStr[ZT_IDENTITY_STRING_BUFFER_LENGTH];
  74. // This is set externally to an instance of this base class
  75. NetworkController *localNetworkController;
  76. /*
  77. * Order matters a bit here. These are constructed in this order
  78. * and then deleted in the opposite order on Node exit. The order ensures
  79. * that things that are needed are there before they're needed.
  80. *
  81. * These are constant and never null after startup unless indicated.
  82. */
  83. Switch *sw;
  84. Multicaster *mc;
  85. Topology *topology;
  86. SelfAwareness *sa;
  87. };
  88. } // namespace ZeroTier
  89. #endif