RuntimeEnvironment.hpp 1.9 KB

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