RuntimeEnvironment.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (c)2019 ZeroTier, Inc.
  3. *
  4. * Use of this software is governed by the Business Source License included
  5. * in the LICENSE.TXT file in the project's root directory.
  6. *
  7. * Change Date: 2026-01-01
  8. *
  9. * On the date above, in accordance with the Business Source License, use
  10. * of this software will be governed by version 2.0 of the Apache License.
  11. */
  12. /****/
  13. #ifndef ZT_RUNTIMEENVIRONMENT_HPP
  14. #define ZT_RUNTIMEENVIRONMENT_HPP
  15. #include <string.h>
  16. #include "Constants.hpp"
  17. #include "Utils.hpp"
  18. #include "Identity.hpp"
  19. namespace ZeroTier {
  20. class NodeConfig;
  21. class Switch;
  22. class Topology;
  23. class Node;
  24. class Multicaster;
  25. class NetworkController;
  26. class SelfAwareness;
  27. class Trace;
  28. class Bond;
  29. class PacketMultiplexer;
  30. /**
  31. * Holds global state for an instance of ZeroTier::Node
  32. */
  33. class RuntimeEnvironment
  34. {
  35. public:
  36. RuntimeEnvironment(Node *n) :
  37. node(n)
  38. ,localNetworkController((NetworkController *)0)
  39. ,rtmem((void *)0)
  40. ,sw((Switch *)0)
  41. ,mc((Multicaster *)0)
  42. ,topology((Topology *)0)
  43. ,sa((SelfAwareness *)0)
  44. {
  45. publicIdentityStr[0] = (char)0;
  46. secretIdentityStr[0] = (char)0;
  47. }
  48. ~RuntimeEnvironment()
  49. {
  50. Utils::burn(secretIdentityStr,sizeof(secretIdentityStr));
  51. }
  52. // Node instance that owns this RuntimeEnvironment
  53. Node *const node;
  54. // This is set externally to an instance of this base class
  55. NetworkController *localNetworkController;
  56. // Memory actually occupied by Trace, Switch, etc.
  57. void *rtmem;
  58. /* Order matters a bit here. These are constructed in this order
  59. * and then deleted in the opposite order on Node exit. The order ensures
  60. * that things that are needed are there before they're needed.
  61. *
  62. * These are constant and never null after startup unless indicated. */
  63. Trace *t;
  64. Switch *sw;
  65. Multicaster *mc;
  66. Topology *topology;
  67. SelfAwareness *sa;
  68. Bond *bc;
  69. PacketMultiplexer *pm;
  70. // This node's identity and string representations thereof
  71. Identity identity;
  72. char publicIdentityStr[ZT_IDENTITY_STRING_BUFFER_LENGTH];
  73. char secretIdentityStr[ZT_IDENTITY_STRING_BUFFER_LENGTH];
  74. };
  75. } // namespace ZeroTier
  76. #endif