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: 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 14 #ifndef ZT_RUNTIMEENVIRONMENT_HPP 15 #define ZT_RUNTIMEENVIRONMENT_HPP 16 17 #include <string.h> 18 19 #include "Constants.hpp" 20 #include "Utils.hpp" 21 #include "Identity.hpp" 22 23 namespace ZeroTier { 24 25 class NodeConfig; 26 class Switch; 27 class Topology; 28 class Node; 29 class Multicaster; 30 class NetworkController; 31 class SelfAwareness; 32 class Trace; 33 class Bond; 34 35 /** 36 * Holds global state for an instance of ZeroTier::Node 37 */ 38 class RuntimeEnvironment 39 { 40 public: RuntimeEnvironment(Node * n)41 RuntimeEnvironment(Node *n) : 42 node(n) 43 ,localNetworkController((NetworkController *)0) 44 ,rtmem((void *)0) 45 ,sw((Switch *)0) 46 ,mc((Multicaster *)0) 47 ,topology((Topology *)0) 48 ,sa((SelfAwareness *)0) 49 { 50 publicIdentityStr[0] = (char)0; 51 secretIdentityStr[0] = (char)0; 52 } 53 ~RuntimeEnvironment()54 ~RuntimeEnvironment() 55 { 56 Utils::burn(secretIdentityStr,sizeof(secretIdentityStr)); 57 } 58 59 // Node instance that owns this RuntimeEnvironment 60 Node *const node; 61 62 // This is set externally to an instance of this base class 63 NetworkController *localNetworkController; 64 65 // Memory actually occupied by Trace, Switch, etc. 66 void *rtmem; 67 68 /* Order matters a bit here. These are constructed in this order 69 * and then deleted in the opposite order on Node exit. The order ensures 70 * that things that are needed are there before they're needed. 71 * 72 * These are constant and never null after startup unless indicated. */ 73 74 Trace *t; 75 Switch *sw; 76 Multicaster *mc; 77 Topology *topology; 78 SelfAwareness *sa; 79 Bond *bc; 80 81 // This node's identity and string representations thereof 82 Identity identity; 83 char publicIdentityStr[ZT_IDENTITY_STRING_BUFFER_LENGTH]; 84 char secretIdentityStr[ZT_IDENTITY_STRING_BUFFER_LENGTH]; 85 }; 86 87 } // namespace ZeroTier 88 89 #endif 90