RuntimeEnvironment.hpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 "Constants.hpp"
  16. #include "Identity.hpp"
  17. #include "Utils.hpp"
  18. #include <string.h>
  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. public:
  35. RuntimeEnvironment(Node* n) : node(n), localNetworkController((NetworkController*)0), rtmem((void*)0), sw((Switch*)0), mc((Multicaster*)0), topology((Topology*)0), sa((SelfAwareness*)0)
  36. {
  37. publicIdentityStr[0] = (char)0;
  38. secretIdentityStr[0] = (char)0;
  39. }
  40. ~RuntimeEnvironment()
  41. {
  42. Utils::burn(secretIdentityStr, sizeof(secretIdentityStr));
  43. }
  44. // Node instance that owns this RuntimeEnvironment
  45. Node* const node;
  46. // This is set externally to an instance of this base class
  47. NetworkController* localNetworkController;
  48. // Memory actually occupied by Trace, Switch, etc.
  49. void* rtmem;
  50. /* Order matters a bit here. These are constructed in this order
  51. * and then deleted in the opposite order on Node exit. The order ensures
  52. * that things that are needed are there before they're needed.
  53. *
  54. * These are constant and never null after startup unless indicated. */
  55. Trace* t;
  56. Switch* sw;
  57. Multicaster* mc;
  58. Topology* topology;
  59. SelfAwareness* sa;
  60. Bond* bc;
  61. PacketMultiplexer* pm;
  62. // This node's identity and string representations thereof
  63. Identity identity;
  64. char publicIdentityStr[ZT_IDENTITY_STRING_BUFFER_LENGTH];
  65. char secretIdentityStr[ZT_IDENTITY_STRING_BUFFER_LENGTH];
  66. };
  67. } // namespace ZeroTier
  68. #endif