RuntimeEnvironment.hpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. /**
  30. * Holds global state for an instance of ZeroTier::Node
  31. */
  32. class RuntimeEnvironment
  33. {
  34. public:
  35. RuntimeEnvironment(Node *n) :
  36. node(n)
  37. ,localNetworkController((NetworkController *)0)
  38. ,rtmem((void *)0)
  39. ,sw((Switch *)0)
  40. ,mc((Multicaster *)0)
  41. ,topology((Topology *)0)
  42. ,sa((SelfAwareness *)0)
  43. {
  44. publicIdentityStr[0] = (char)0;
  45. secretIdentityStr[0] = (char)0;
  46. }
  47. ~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. Switch *sw;
  64. Multicaster *mc;
  65. Topology *topology;
  66. SelfAwareness *sa;
  67. Bond *bc;
  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