RuntimeEnvironment.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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: 2025-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. #include "AES.hpp"
  19. namespace ZeroTier {
  20. class VL1;
  21. class VL2;
  22. class Topology;
  23. class Node;
  24. class NetworkController;
  25. class SelfAwareness;
  26. class Trace;
  27. class Expect;
  28. /**
  29. * ZeroTier::Node execution context
  30. *
  31. * This just holds pointers and various other information used by all the
  32. * various moving parts of a node. It's stored or passed as 'RR' to give it
  33. * a common name througout the code.
  34. */
  35. class RuntimeEnvironment
  36. {
  37. public:
  38. ZT_INLINE RuntimeEnvironment(Node *const n) noexcept:
  39. instanceId(Utils::getSecureRandomU64()),
  40. node(n),
  41. localNetworkController(nullptr),
  42. rtmem(nullptr),
  43. t(nullptr),
  44. expect(nullptr),
  45. vl2(nullptr),
  46. vl1(nullptr),
  47. topology(nullptr),
  48. sa(nullptr)
  49. {
  50. publicIdentityStr[0] = 0;
  51. secretIdentityStr[0] = 0;
  52. }
  53. ZT_INLINE ~RuntimeEnvironment() noexcept
  54. {
  55. Utils::burn(secretIdentityStr, sizeof(secretIdentityStr));
  56. }
  57. // Unique ID generated on startup
  58. const uint64_t instanceId;
  59. // Node instance that owns this RuntimeEnvironment
  60. Node *const node;
  61. // This is set externally to an instance of this base class
  62. NetworkController *localNetworkController;
  63. // Memory actually occupied by Trace, Switch, etc.
  64. void *rtmem;
  65. Trace *t;
  66. Expect *expect;
  67. VL2 *vl2;
  68. VL1 *vl1;
  69. Topology *topology;
  70. SelfAwareness *sa;
  71. // This node's identity and string representations thereof
  72. Identity identity;
  73. char publicIdentityStr[ZT_IDENTITY_STRING_BUFFER_LENGTH];
  74. char secretIdentityStr[ZT_IDENTITY_STRING_BUFFER_LENGTH];
  75. // AES keyed with a hash of this node's identity secret keys for local cache encryption at rest (where needed).
  76. AES localCacheSymmetric;
  77. // Privileged ports from 1 to 1023 in a random order (for IPv4 NAT traversal)
  78. uint16_t randomPrivilegedPortOrder[1023];
  79. };
  80. } // namespace ZeroTier
  81. #endif