RuntimeEnvironment.hpp 2.0 KB

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