RuntimeEnvironment.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 "Constants.hpp"
  16. #include "Utils.hpp"
  17. #include "Identity.hpp"
  18. namespace ZeroTier {
  19. class VL1;
  20. class VL2;
  21. class Topology;
  22. class Node;
  23. class NetworkController;
  24. class SelfAwareness;
  25. class Trace;
  26. class Expect;
  27. /**
  28. * ZeroTier::Node execution context
  29. *
  30. * This just holds pointers and various other information used by all the
  31. * various moving parts of a node. It's stored or passed as 'RR' to give it
  32. * a common name througout the code.
  33. */
  34. class RuntimeEnvironment
  35. {
  36. public:
  37. ZT_ALWAYS_INLINE RuntimeEnvironment(Node *n) noexcept :
  38. node(n),
  39. localNetworkController(nullptr),
  40. rtmem(nullptr),
  41. t(nullptr),
  42. expect(nullptr),
  43. vl2(nullptr),
  44. vl1(nullptr),
  45. topology(nullptr),
  46. sa(nullptr)
  47. {
  48. publicIdentityStr[0] = (char)0;
  49. secretIdentityStr[0] = (char)0;
  50. }
  51. ZT_ALWAYS_INLINE ~RuntimeEnvironment()
  52. {
  53. Utils::burn(secretIdentityStr,sizeof(secretIdentityStr));
  54. Utils::burn(localCacheSymmetricKey,sizeof(localCacheSymmetricKey));
  55. }
  56. // Node instance that owns this RuntimeEnvironment
  57. Node *const node;
  58. // This is set externally to an instance of this base class
  59. NetworkController *localNetworkController;
  60. // Memory actually occupied by Trace, Switch, etc.
  61. void *rtmem;
  62. Trace *t;
  63. Expect *expect;
  64. VL2 *vl2;
  65. VL1 *vl1;
  66. Topology *topology;
  67. SelfAwareness *sa;
  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. // A hash of this node identity's public and private keys that is used as
  73. // a secret key to encrypt locally cached sensitive information.
  74. uint8_t localCacheSymmetricKey[ZT_IDENTITY_HASH_SIZE];
  75. };
  76. } // namespace ZeroTier
  77. #endif