RuntimeEnvironment.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (c)2013-2020 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: 2024-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 "Utils.hpp"
  17. #include "Identity.hpp"
  18. namespace ZeroTier {
  19. class VL1;
  20. class VL2;
  21. class Topology;
  22. class Node;
  23. class NetworkController;
  24. class SelfAwareness;
  25. class Trace;
  26. class Expect;
  27. /**
  28. * Holds global state for an instance of ZeroTier::Node
  29. */
  30. class RuntimeEnvironment
  31. {
  32. public:
  33. ZT_ALWAYS_INLINE RuntimeEnvironment(Node *n) :
  34. node(n),
  35. localNetworkController(nullptr),
  36. rtmem(nullptr),
  37. t(nullptr),
  38. expect(nullptr),
  39. vl2(nullptr),
  40. vl1(nullptr),
  41. topology(nullptr),
  42. sa(nullptr)
  43. {
  44. publicIdentityStr[0] = (char)0;
  45. secretIdentityStr[0] = (char)0;
  46. }
  47. ZT_ALWAYS_INLINE ~RuntimeEnvironment()
  48. {
  49. Utils::burn(secretIdentityStr,sizeof(secretIdentityStr));
  50. }
  51. // Node instance that owns this RuntimeEnvironment
  52. Node *const node;
  53. // This is set externally to an instance of this base class
  54. NetworkController *localNetworkController;
  55. // Memory actually occupied by Trace, Switch, etc.
  56. void *rtmem;
  57. /* Order matters a bit here. These are constructed in this order
  58. * and then deleted in the opposite order on Node exit. The order ensures
  59. * that things that are needed are there before they're needed.
  60. *
  61. * These are constant and never null after startup unless indicated. */
  62. Trace *t;
  63. Expect *expect;
  64. VL2 *vl2;
  65. VL1 *vl1;
  66. Topology *topology;
  67. SelfAwareness *sa;
  68. // This node's identity and string representations thereof
  69. Identity identity;
  70. char publicIdentityStr[ZT_IDENTITY_STRING_BUFFER_LENGTH];
  71. char secretIdentityStr[ZT_IDENTITY_STRING_BUFFER_LENGTH];
  72. };
  73. } // namespace ZeroTier
  74. #endif