RuntimeEnvironment.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. 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. ~RuntimeEnvironment()
  47. {
  48. Utils::burn(secretIdentityStr,sizeof(secretIdentityStr));
  49. }
  50. // Node instance that owns this RuntimeEnvironment
  51. Node *const node;
  52. // This is set externally to an instance of this base class
  53. NetworkController *localNetworkController;
  54. // Memory actually occupied by Trace, Switch, etc.
  55. void *rtmem;
  56. /* Order matters a bit here. These are constructed in this order
  57. * and then deleted in the opposite order on Node exit. The order ensures
  58. * that things that are needed are there before they're needed.
  59. *
  60. * These are constant and never null after startup unless indicated. */
  61. Trace *t;
  62. Switch *sw;
  63. Multicaster *mc;
  64. Topology *topology;
  65. SelfAwareness *sa;
  66. // This node's identity and string representations thereof
  67. Identity identity;
  68. char publicIdentityStr[ZT_IDENTITY_STRING_BUFFER_LENGTH];
  69. char secretIdentityStr[ZT_IDENTITY_STRING_BUFFER_LENGTH];
  70. };
  71. } // namespace ZeroTier
  72. #endif