RuntimeEnvironment.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
  4. *
  5. * (c) ZeroTier, Inc.
  6. * https://www.zerotier.com/
  7. */
  8. #ifndef ZT_RUNTIMEENVIRONMENT_HPP
  9. #define ZT_RUNTIMEENVIRONMENT_HPP
  10. #include "Constants.hpp"
  11. #include "Identity.hpp"
  12. #include "Utils.hpp"
  13. #include <string.h>
  14. namespace ZeroTier {
  15. class NodeConfig;
  16. class Switch;
  17. class Topology;
  18. class Node;
  19. class Multicaster;
  20. class NetworkController;
  21. class SelfAwareness;
  22. class Trace;
  23. class Bond;
  24. class PacketMultiplexer;
  25. /**
  26. * Holds global state for an instance of ZeroTier::Node
  27. */
  28. class RuntimeEnvironment {
  29. public:
  30. RuntimeEnvironment(Node* n) : node(n), localNetworkController((NetworkController*)0), rtmem((void*)0), sw((Switch*)0), mc((Multicaster*)0), topology((Topology*)0), sa((SelfAwareness*)0)
  31. {
  32. publicIdentityStr[0] = (char)0;
  33. secretIdentityStr[0] = (char)0;
  34. }
  35. ~RuntimeEnvironment()
  36. {
  37. Utils::burn(secretIdentityStr, sizeof(secretIdentityStr));
  38. }
  39. // Node instance that owns this RuntimeEnvironment
  40. Node* const node;
  41. // This is set externally to an instance of this base class
  42. NetworkController* localNetworkController;
  43. // Memory actually occupied by Trace, Switch, etc.
  44. void* rtmem;
  45. /* Order matters a bit here. These are constructed in this order
  46. * and then deleted in the opposite order on Node exit. The order ensures
  47. * that things that are needed are there before they're needed.
  48. *
  49. * These are constant and never null after startup unless indicated. */
  50. Trace* t;
  51. Switch* sw;
  52. Multicaster* mc;
  53. Topology* topology;
  54. SelfAwareness* sa;
  55. Bond* bc;
  56. PacketMultiplexer* pm;
  57. // This node's identity and string representations thereof
  58. Identity identity;
  59. char publicIdentityStr[ZT_IDENTITY_STRING_BUFFER_LENGTH];
  60. char secretIdentityStr[ZT_IDENTITY_STRING_BUFFER_LENGTH];
  61. };
  62. } // namespace ZeroTier
  63. #endif