ZT_jnicache.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. //
  2. // Created by Brenton Bostick on 1/18/23.
  3. //
  4. #include "ZT_jnicache.h"
  5. #include "ZT_jniutils.h"
  6. #include <cassert>
  7. #define LOG_TAG "Cache"
  8. #define EXCEPTIONANDNULLCHECK(var) \
  9. do { \
  10. if (env->ExceptionCheck()) { \
  11. assert(false && "Exception"); \
  12. } \
  13. if ((var) == NULL) { \
  14. assert(false && #var " is NULL"); \
  15. } \
  16. } while (false)
  17. #define SETCLASS(classVar, classNameString) \
  18. do { \
  19. jclass classVar ## _local = env->FindClass(classNameString); \
  20. EXCEPTIONANDNULLCHECK(classVar ## _local); \
  21. classVar = reinterpret_cast<jclass>(env->NewGlobalRef(classVar ## _local)); \
  22. EXCEPTIONANDNULLCHECK(classVar); \
  23. env->DeleteLocalRef(classVar ## _local); \
  24. } while (false)
  25. #define SETOBJECT(objectVar, code) \
  26. do { \
  27. jobject objectVar ## _local = code; \
  28. EXCEPTIONANDNULLCHECK(objectVar ## _local); \
  29. objectVar = env->NewGlobalRef(objectVar ## _local); \
  30. EXCEPTIONANDNULLCHECK(objectVar); \
  31. env->DeleteLocalRef(objectVar ## _local); \
  32. } while (false)
  33. //
  34. // Classes
  35. //
  36. jclass ArrayList_class;
  37. jclass DataStoreGetListener_class;
  38. jclass DataStorePutListener_class;
  39. jclass EventListener_class;
  40. jclass Event_class;
  41. jclass Inet4Address_class;
  42. jclass Inet6Address_class;
  43. jclass InetAddress_class;
  44. jclass InetSocketAddress_class;
  45. jclass NodeStatus_class;
  46. jclass Node_class;
  47. jclass PacketSender_class;
  48. jclass PathChecker_class;
  49. jclass PeerPhysicalPath_class;
  50. jclass PeerRole_class;
  51. jclass Peer_class;
  52. jclass ResultCode_class;
  53. jclass Version_class;
  54. jclass VirtualNetworkConfigListener_class;
  55. jclass VirtualNetworkConfigOperation_class;
  56. jclass VirtualNetworkConfig_class;
  57. jclass VirtualNetworkDNS_class;
  58. jclass VirtualNetworkFrameListener_class;
  59. jclass VirtualNetworkRoute_class;
  60. jclass VirtualNetworkStatus_class;
  61. jclass VirtualNetworkType_class;
  62. //
  63. // Instance methods
  64. //
  65. jmethodID ArrayList_add_method;
  66. jmethodID ArrayList_ctor;
  67. jmethodID DataStoreGetListener_onDataStoreGet_method;
  68. jmethodID DataStorePutListener_onDataStorePut_method;
  69. jmethodID DataStorePutListener_onDelete_method;
  70. jmethodID EventListener_onEvent_method;
  71. jmethodID EventListener_onTrace_method;
  72. jmethodID InetAddress_getAddress_method;
  73. jmethodID InetSocketAddress_ctor;
  74. jmethodID InetSocketAddress_getAddress_method;
  75. jmethodID InetSocketAddress_getPort_method;
  76. jmethodID NodeStatus_ctor;
  77. jmethodID PacketSender_onSendPacketRequested_method;
  78. jmethodID PathChecker_onPathCheck_method;
  79. jmethodID PathChecker_onPathLookup_method;
  80. jmethodID PeerPhysicalPath_ctor;
  81. jmethodID Peer_ctor;
  82. jmethodID Version_ctor;
  83. jmethodID VirtualNetworkConfigListener_onNetworkConfigurationUpdated_method;
  84. jmethodID VirtualNetworkConfig_ctor;
  85. jmethodID VirtualNetworkDNS_ctor;
  86. jmethodID VirtualNetworkFrameListener_onVirtualNetworkFrame_method;
  87. jmethodID VirtualNetworkRoute_ctor;
  88. //
  89. // Static methods
  90. //
  91. jmethodID Event_fromInt_method;
  92. jmethodID InetAddress_getByAddress_method;
  93. jmethodID PeerRole_fromInt_method;
  94. //
  95. // Instance fields
  96. //
  97. jfieldID NodeStatus_address_field;
  98. jfieldID NodeStatus_online_field;
  99. jfieldID NodeStatus_publicIdentity_field;
  100. jfieldID NodeStatus_secretIdentity_field;
  101. jfieldID Node_configListener_field;
  102. jfieldID Node_eventListener_field;
  103. jfieldID Node_frameListener_field;
  104. jfieldID Node_getListener_field;
  105. jfieldID Node_pathChecker_field;
  106. jfieldID Node_putListener_field;
  107. jfieldID Node_sender_field;
  108. jfieldID PeerPhysicalPath_address_field;
  109. jfieldID PeerPhysicalPath_lastReceive_field;
  110. jfieldID PeerPhysicalPath_lastSend_field;
  111. jfieldID PeerPhysicalPath_preferred_field;
  112. jfieldID Peer_address_field;
  113. jfieldID Peer_latency_field;
  114. jfieldID Peer_paths_field;
  115. jfieldID Peer_role_field;
  116. jfieldID Peer_versionMajor_field;
  117. jfieldID Peer_versionMinor_field;
  118. jfieldID Peer_versionRev_field;
  119. jfieldID Version_major_field;
  120. jfieldID Version_minor_field;
  121. jfieldID Version_revision_field;
  122. jfieldID VirtualNetworkConfig_assignedAddresses_field;
  123. jfieldID VirtualNetworkConfig_bridge_field;
  124. jfieldID VirtualNetworkConfig_broadcastEnabled_field;
  125. jfieldID VirtualNetworkConfig_dhcp_field;
  126. jfieldID VirtualNetworkConfig_dns_field;
  127. jfieldID VirtualNetworkConfig_enabled_field;
  128. jfieldID VirtualNetworkConfig_mac_field;
  129. jfieldID VirtualNetworkConfig_mtu_field;
  130. jfieldID VirtualNetworkConfig_name_field;
  131. jfieldID VirtualNetworkConfig_nwid_field;
  132. jfieldID VirtualNetworkConfig_portError_field;
  133. jfieldID VirtualNetworkConfig_routes_field;
  134. jfieldID VirtualNetworkConfig_status_field;
  135. jfieldID VirtualNetworkConfig_type_field;
  136. jfieldID VirtualNetworkDNS_domain_field;
  137. jfieldID VirtualNetworkDNS_servers_field;
  138. jfieldID VirtualNetworkRoute_flags_field;
  139. jfieldID VirtualNetworkRoute_metric_field;
  140. jfieldID VirtualNetworkRoute_target_field;
  141. jfieldID VirtualNetworkRoute_via_field;
  142. //
  143. // Static fields
  144. //
  145. jfieldID ResultCode_RESULT_ERROR_BAD_PARAMETER_field;
  146. jfieldID ResultCode_RESULT_ERROR_NETWORK_NOT_FOUND_field;
  147. jfieldID ResultCode_RESULT_ERROR_UNSUPPORTED_OPERATION_field;
  148. jfieldID ResultCode_RESULT_FATAL_ERROR_DATA_STORE_FAILED_field;
  149. jfieldID ResultCode_RESULT_FATAL_ERROR_INTERNAL_field;
  150. jfieldID ResultCode_RESULT_FATAL_ERROR_OUT_OF_MEMORY_field;
  151. jfieldID ResultCode_RESULT_OK_field;
  152. jfieldID VirtualNetworkConfigOperation_VIRTUAL_NETWORK_CONFIG_OPERATION_CONFIG_UPDATE_field;
  153. jfieldID VirtualNetworkConfigOperation_VIRTUAL_NETWORK_CONFIG_OPERATION_DESTROY_field;
  154. jfieldID VirtualNetworkConfigOperation_VIRTUAL_NETWORK_CONFIG_OPERATION_DOWN_field;
  155. jfieldID VirtualNetworkConfigOperation_VIRTUAL_NETWORK_CONFIG_OPERATION_UP_field;
  156. jfieldID VirtualNetworkStatus_NETWORK_STATUS_ACCESS_DENIED_field;
  157. jfieldID VirtualNetworkStatus_NETWORK_STATUS_AUTHENTICATION_REQUIRED_field;
  158. jfieldID VirtualNetworkStatus_NETWORK_STATUS_CLIENT_TOO_OLD_field;
  159. jfieldID VirtualNetworkStatus_NETWORK_STATUS_NOT_FOUND_field;
  160. jfieldID VirtualNetworkStatus_NETWORK_STATUS_OK_field;
  161. jfieldID VirtualNetworkStatus_NETWORK_STATUS_PORT_ERROR_field;
  162. jfieldID VirtualNetworkStatus_NETWORK_STATUS_REQUESTING_CONFIGURATION_field;
  163. jfieldID VirtualNetworkType_NETWORK_TYPE_PRIVATE_field;
  164. jfieldID VirtualNetworkType_NETWORK_TYPE_PUBLIC_field;
  165. //
  166. // Enums
  167. //
  168. jobject ResultCode_RESULT_FATAL_ERROR_INTERNAL_enum;
  169. jobject ResultCode_RESULT_OK_enum;
  170. void setupJNICache(JavaVM *vm) {
  171. JNIEnv *env;
  172. GETENV(env, vm);
  173. //
  174. // Classes
  175. //
  176. SETCLASS(ArrayList_class, "java/util/ArrayList");
  177. SETCLASS(DataStoreGetListener_class, "com/zerotier/sdk/DataStoreGetListener");
  178. SETCLASS(DataStorePutListener_class, "com/zerotier/sdk/DataStorePutListener");
  179. SETCLASS(EventListener_class, "com/zerotier/sdk/EventListener");
  180. SETCLASS(Event_class, "com/zerotier/sdk/Event");
  181. SETCLASS(Inet4Address_class, "java/net/Inet4Address");
  182. SETCLASS(Inet6Address_class, "java/net/Inet6Address");
  183. SETCLASS(InetAddress_class, "java/net/InetAddress");
  184. SETCLASS(InetSocketAddress_class, "java/net/InetSocketAddress");
  185. SETCLASS(NodeStatus_class, "com/zerotier/sdk/NodeStatus");
  186. SETCLASS(Node_class, "com/zerotier/sdk/Node");
  187. SETCLASS(PacketSender_class, "com/zerotier/sdk/PacketSender");
  188. SETCLASS(PathChecker_class, "com/zerotier/sdk/PathChecker");
  189. SETCLASS(PeerPhysicalPath_class, "com/zerotier/sdk/PeerPhysicalPath");
  190. SETCLASS(PeerRole_class, "com/zerotier/sdk/PeerRole");
  191. SETCLASS(Peer_class, "com/zerotier/sdk/Peer");
  192. SETCLASS(ResultCode_class, "com/zerotier/sdk/ResultCode");
  193. SETCLASS(Version_class, "com/zerotier/sdk/Version");
  194. SETCLASS(VirtualNetworkConfigListener_class, "com/zerotier/sdk/VirtualNetworkConfigListener");
  195. SETCLASS(VirtualNetworkConfigOperation_class, "com/zerotier/sdk/VirtualNetworkConfigOperation");
  196. SETCLASS(VirtualNetworkConfig_class, "com/zerotier/sdk/VirtualNetworkConfig");
  197. SETCLASS(VirtualNetworkDNS_class, "com/zerotier/sdk/VirtualNetworkDNS");
  198. SETCLASS(VirtualNetworkFrameListener_class, "com/zerotier/sdk/VirtualNetworkFrameListener");
  199. SETCLASS(VirtualNetworkRoute_class, "com/zerotier/sdk/VirtualNetworkRoute");
  200. SETCLASS(VirtualNetworkStatus_class, "com/zerotier/sdk/VirtualNetworkStatus");
  201. SETCLASS(VirtualNetworkType_class, "com/zerotier/sdk/VirtualNetworkType");
  202. //
  203. // Instance methods
  204. //
  205. EXCEPTIONANDNULLCHECK(ArrayList_add_method = env->GetMethodID(ArrayList_class, "add", "(Ljava/lang/Object;)Z"));
  206. EXCEPTIONANDNULLCHECK(ArrayList_ctor = env->GetMethodID(ArrayList_class, "<init>", "(I)V"));
  207. EXCEPTIONANDNULLCHECK(DataStoreGetListener_onDataStoreGet_method = env->GetMethodID(DataStoreGetListener_class, "onDataStoreGet", "(Ljava/lang/String;[B)J"));
  208. EXCEPTIONANDNULLCHECK(DataStorePutListener_onDataStorePut_method = env->GetMethodID(DataStorePutListener_class, "onDataStorePut", "(Ljava/lang/String;[BZ)I"));
  209. EXCEPTIONANDNULLCHECK(DataStorePutListener_onDelete_method = env->GetMethodID(DataStorePutListener_class, "onDelete", "(Ljava/lang/String;)I"));
  210. EXCEPTIONANDNULLCHECK(EventListener_onEvent_method = env->GetMethodID(EventListener_class, "onEvent", "(Lcom/zerotier/sdk/Event;)V"));
  211. EXCEPTIONANDNULLCHECK(EventListener_onTrace_method = env->GetMethodID(EventListener_class, "onTrace", "(Ljava/lang/String;)V"));
  212. EXCEPTIONANDNULLCHECK(InetAddress_getAddress_method = env->GetMethodID(InetAddress_class, "getAddress", "()[B"));
  213. EXCEPTIONANDNULLCHECK(InetSocketAddress_ctor = env->GetMethodID(InetSocketAddress_class, "<init>", "(Ljava/net/InetAddress;I)V"));
  214. EXCEPTIONANDNULLCHECK(InetSocketAddress_getAddress_method = env->GetMethodID(InetSocketAddress_class, "getAddress", "()Ljava/net/InetAddress;"));
  215. EXCEPTIONANDNULLCHECK(InetSocketAddress_getPort_method = env->GetMethodID(InetSocketAddress_class, "getPort", "()I"));
  216. EXCEPTIONANDNULLCHECK(NodeStatus_ctor = env->GetMethodID(NodeStatus_class, "<init>", "()V"));
  217. EXCEPTIONANDNULLCHECK(PacketSender_onSendPacketRequested_method = env->GetMethodID(PacketSender_class, "onSendPacketRequested", "(JLjava/net/InetSocketAddress;[BI)I"));
  218. EXCEPTIONANDNULLCHECK(PathChecker_onPathCheck_method = env->GetMethodID(PathChecker_class, "onPathCheck", "(JJLjava/net/InetSocketAddress;)Z"));
  219. EXCEPTIONANDNULLCHECK(PathChecker_onPathLookup_method = env->GetMethodID(PathChecker_class, "onPathLookup", "(JI)Ljava/net/InetSocketAddress;"));
  220. EXCEPTIONANDNULLCHECK(PeerPhysicalPath_ctor = env->GetMethodID(PeerPhysicalPath_class, "<init>", "()V"));
  221. EXCEPTIONANDNULLCHECK(Peer_ctor = env->GetMethodID(Peer_class, "<init>", "()V"));
  222. EXCEPTIONANDNULLCHECK(Version_ctor = env->GetMethodID(Version_class, "<init>", "()V"));
  223. EXCEPTIONANDNULLCHECK(VirtualNetworkConfigListener_onNetworkConfigurationUpdated_method = env->GetMethodID(VirtualNetworkConfigListener_class, "onNetworkConfigurationUpdated", "(JLcom/zerotier/sdk/VirtualNetworkConfigOperation;Lcom/zerotier/sdk/VirtualNetworkConfig;)I"));
  224. EXCEPTIONANDNULLCHECK(VirtualNetworkConfig_ctor = env->GetMethodID(VirtualNetworkConfig_class, "<init>", "()V"));
  225. EXCEPTIONANDNULLCHECK(VirtualNetworkDNS_ctor = env->GetMethodID(VirtualNetworkDNS_class, "<init>", "()V"));
  226. EXCEPTIONANDNULLCHECK(VirtualNetworkFrameListener_onVirtualNetworkFrame_method = env->GetMethodID(VirtualNetworkFrameListener_class, "onVirtualNetworkFrame", "(JJJJJ[B)V"));
  227. EXCEPTIONANDNULLCHECK(VirtualNetworkRoute_ctor = env->GetMethodID(VirtualNetworkRoute_class, "<init>", "()V"));
  228. //
  229. // Static methods
  230. //
  231. EXCEPTIONANDNULLCHECK(Event_fromInt_method = env->GetStaticMethodID(Event_class, "fromInt", "(I)Lcom/zerotier/sdk/Event;"));
  232. EXCEPTIONANDNULLCHECK(InetAddress_getByAddress_method = env->GetStaticMethodID(InetAddress_class, "getByAddress", "([B)Ljava/net/InetAddress;"));
  233. EXCEPTIONANDNULLCHECK(PeerRole_fromInt_method = env->GetStaticMethodID(PeerRole_class, "fromInt", "(I)Lcom/zerotier/sdk/PeerRole;"));
  234. //
  235. // Instance fields
  236. //
  237. EXCEPTIONANDNULLCHECK(NodeStatus_address_field = env->GetFieldID(NodeStatus_class, "address", "J"));
  238. EXCEPTIONANDNULLCHECK(NodeStatus_online_field = env->GetFieldID(NodeStatus_class, "online", "Z"));
  239. EXCEPTIONANDNULLCHECK(NodeStatus_publicIdentity_field = env->GetFieldID(NodeStatus_class, "publicIdentity", "Ljava/lang/String;"));
  240. EXCEPTIONANDNULLCHECK(NodeStatus_secretIdentity_field = env->GetFieldID(NodeStatus_class, "secretIdentity", "Ljava/lang/String;"));
  241. EXCEPTIONANDNULLCHECK(Node_configListener_field = env->GetFieldID(Node_class, "configListener", "Lcom/zerotier/sdk/VirtualNetworkConfigListener;"));
  242. EXCEPTIONANDNULLCHECK(Node_eventListener_field = env->GetFieldID(Node_class, "eventListener", "Lcom/zerotier/sdk/EventListener;"));
  243. EXCEPTIONANDNULLCHECK(Node_frameListener_field = env->GetFieldID(Node_class, "frameListener", "Lcom/zerotier/sdk/VirtualNetworkFrameListener;"));
  244. EXCEPTIONANDNULLCHECK(Node_getListener_field = env->GetFieldID(Node_class, "getListener", "Lcom/zerotier/sdk/DataStoreGetListener;"));
  245. EXCEPTIONANDNULLCHECK(Node_pathChecker_field = env->GetFieldID(Node_class, "pathChecker", "Lcom/zerotier/sdk/PathChecker;"));
  246. EXCEPTIONANDNULLCHECK(Node_putListener_field = env->GetFieldID(Node_class, "putListener", "Lcom/zerotier/sdk/DataStorePutListener;"));
  247. EXCEPTIONANDNULLCHECK(Node_sender_field = env->GetFieldID(Node_class, "sender", "Lcom/zerotier/sdk/PacketSender;"));
  248. EXCEPTIONANDNULLCHECK(PeerPhysicalPath_address_field = env->GetFieldID(PeerPhysicalPath_class, "address", "Ljava/net/InetSocketAddress;"));
  249. EXCEPTIONANDNULLCHECK(PeerPhysicalPath_lastReceive_field = env->GetFieldID(PeerPhysicalPath_class, "lastReceive", "J"));
  250. EXCEPTIONANDNULLCHECK(PeerPhysicalPath_lastSend_field = env->GetFieldID(PeerPhysicalPath_class, "lastSend", "J"));
  251. EXCEPTIONANDNULLCHECK(PeerPhysicalPath_preferred_field = env->GetFieldID(PeerPhysicalPath_class, "preferred", "Z"));
  252. EXCEPTIONANDNULLCHECK(Peer_address_field = env->GetFieldID(Peer_class, "address", "J"));
  253. EXCEPTIONANDNULLCHECK(Peer_latency_field = env->GetFieldID(Peer_class, "latency", "I"));
  254. EXCEPTIONANDNULLCHECK(Peer_paths_field = env->GetFieldID(Peer_class, "paths", "[Lcom/zerotier/sdk/PeerPhysicalPath;"));
  255. EXCEPTIONANDNULLCHECK(Peer_role_field = env->GetFieldID(Peer_class, "role", "Lcom/zerotier/sdk/PeerRole;"));
  256. EXCEPTIONANDNULLCHECK(Peer_versionMajor_field = env->GetFieldID(Peer_class, "versionMajor", "I"));
  257. EXCEPTIONANDNULLCHECK(Peer_versionMinor_field = env->GetFieldID(Peer_class, "versionMinor", "I"));
  258. EXCEPTIONANDNULLCHECK(Peer_versionRev_field = env->GetFieldID(Peer_class, "versionRev", "I"));
  259. EXCEPTIONANDNULLCHECK(Version_major_field = env->GetFieldID(Version_class, "major", "I"));
  260. EXCEPTIONANDNULLCHECK(Version_minor_field = env->GetFieldID(Version_class, "minor", "I"));
  261. EXCEPTIONANDNULLCHECK(Version_revision_field = env->GetFieldID(Version_class, "revision", "I"));
  262. EXCEPTIONANDNULLCHECK(VirtualNetworkConfig_assignedAddresses_field = env->GetFieldID(VirtualNetworkConfig_class, "assignedAddresses", "[Ljava/net/InetSocketAddress;"));
  263. EXCEPTIONANDNULLCHECK(VirtualNetworkConfig_bridge_field = env->GetFieldID(VirtualNetworkConfig_class, "bridge", "Z"));
  264. EXCEPTIONANDNULLCHECK(VirtualNetworkConfig_broadcastEnabled_field = env->GetFieldID(VirtualNetworkConfig_class, "broadcastEnabled", "Z"));
  265. EXCEPTIONANDNULLCHECK(VirtualNetworkConfig_dhcp_field = env->GetFieldID(VirtualNetworkConfig_class, "dhcp", "Z"));
  266. EXCEPTIONANDNULLCHECK(VirtualNetworkConfig_dns_field = env->GetFieldID(VirtualNetworkConfig_class, "dns", "Lcom/zerotier/sdk/VirtualNetworkDNS;"));
  267. EXCEPTIONANDNULLCHECK(VirtualNetworkConfig_enabled_field = env->GetFieldID(VirtualNetworkConfig_class, "enabled", "Z"));
  268. EXCEPTIONANDNULLCHECK(VirtualNetworkConfig_mac_field = env->GetFieldID(VirtualNetworkConfig_class, "mac", "J"));
  269. EXCEPTIONANDNULLCHECK(VirtualNetworkConfig_mtu_field = env->GetFieldID(VirtualNetworkConfig_class, "mtu", "I"));
  270. EXCEPTIONANDNULLCHECK(VirtualNetworkConfig_name_field = env->GetFieldID(VirtualNetworkConfig_class, "name", "Ljava/lang/String;"));
  271. EXCEPTIONANDNULLCHECK(VirtualNetworkConfig_nwid_field = env->GetFieldID(VirtualNetworkConfig_class, "nwid", "J"));
  272. EXCEPTIONANDNULLCHECK(VirtualNetworkConfig_portError_field = env->GetFieldID(VirtualNetworkConfig_class, "portError", "I"));
  273. EXCEPTIONANDNULLCHECK(VirtualNetworkConfig_routes_field = env->GetFieldID(VirtualNetworkConfig_class, "routes", "[Lcom/zerotier/sdk/VirtualNetworkRoute;"));
  274. EXCEPTIONANDNULLCHECK(VirtualNetworkConfig_status_field = env->GetFieldID(VirtualNetworkConfig_class, "status", "Lcom/zerotier/sdk/VirtualNetworkStatus;"));
  275. EXCEPTIONANDNULLCHECK(VirtualNetworkConfig_type_field = env->GetFieldID(VirtualNetworkConfig_class, "type", "Lcom/zerotier/sdk/VirtualNetworkType;"));
  276. EXCEPTIONANDNULLCHECK(VirtualNetworkDNS_domain_field = env->GetFieldID(VirtualNetworkDNS_class, "domain", "Ljava/lang/String;"));
  277. EXCEPTIONANDNULLCHECK(VirtualNetworkDNS_servers_field = env->GetFieldID(VirtualNetworkDNS_class, "servers", "Ljava/util/ArrayList;"));
  278. EXCEPTIONANDNULLCHECK(VirtualNetworkRoute_flags_field = env->GetFieldID(VirtualNetworkRoute_class, "flags", "I"));
  279. EXCEPTIONANDNULLCHECK(VirtualNetworkRoute_metric_field = env->GetFieldID(VirtualNetworkRoute_class, "metric", "I"));
  280. EXCEPTIONANDNULLCHECK(VirtualNetworkRoute_target_field = env->GetFieldID(VirtualNetworkRoute_class, "target", "Ljava/net/InetSocketAddress;"));
  281. EXCEPTIONANDNULLCHECK(VirtualNetworkRoute_via_field = env->GetFieldID(VirtualNetworkRoute_class, "via", "Ljava/net/InetSocketAddress;"));
  282. //
  283. // Static fields
  284. //
  285. EXCEPTIONANDNULLCHECK(ResultCode_RESULT_ERROR_BAD_PARAMETER_field = env->GetStaticFieldID(ResultCode_class, "RESULT_ERROR_BAD_PARAMETER", "Lcom/zerotier/sdk/ResultCode;"));
  286. EXCEPTIONANDNULLCHECK(ResultCode_RESULT_ERROR_NETWORK_NOT_FOUND_field = env->GetStaticFieldID(ResultCode_class, "RESULT_ERROR_NETWORK_NOT_FOUND", "Lcom/zerotier/sdk/ResultCode;"));
  287. EXCEPTIONANDNULLCHECK(ResultCode_RESULT_ERROR_UNSUPPORTED_OPERATION_field = env->GetStaticFieldID(ResultCode_class, "RESULT_ERROR_UNSUPPORTED_OPERATION", "Lcom/zerotier/sdk/ResultCode;"));
  288. EXCEPTIONANDNULLCHECK(ResultCode_RESULT_FATAL_ERROR_DATA_STORE_FAILED_field = env->GetStaticFieldID(ResultCode_class, "RESULT_FATAL_ERROR_DATA_STORE_FAILED", "Lcom/zerotier/sdk/ResultCode;"));
  289. EXCEPTIONANDNULLCHECK(ResultCode_RESULT_FATAL_ERROR_INTERNAL_field = env->GetStaticFieldID(ResultCode_class, "RESULT_FATAL_ERROR_INTERNAL", "Lcom/zerotier/sdk/ResultCode;"));
  290. EXCEPTIONANDNULLCHECK(ResultCode_RESULT_FATAL_ERROR_OUT_OF_MEMORY_field = env->GetStaticFieldID(ResultCode_class, "RESULT_FATAL_ERROR_OUT_OF_MEMORY", "Lcom/zerotier/sdk/ResultCode;"));
  291. EXCEPTIONANDNULLCHECK(ResultCode_RESULT_OK_field = env->GetStaticFieldID(ResultCode_class, "RESULT_OK", "Lcom/zerotier/sdk/ResultCode;"));
  292. EXCEPTIONANDNULLCHECK(VirtualNetworkConfigOperation_VIRTUAL_NETWORK_CONFIG_OPERATION_CONFIG_UPDATE_field = env->GetStaticFieldID(VirtualNetworkConfigOperation_class, "VIRTUAL_NETWORK_CONFIG_OPERATION_CONFIG_UPDATE", "Lcom/zerotier/sdk/VirtualNetworkConfigOperation;"));
  293. EXCEPTIONANDNULLCHECK(VirtualNetworkConfigOperation_VIRTUAL_NETWORK_CONFIG_OPERATION_DESTROY_field = env->GetStaticFieldID(VirtualNetworkConfigOperation_class, "VIRTUAL_NETWORK_CONFIG_OPERATION_DESTROY", "Lcom/zerotier/sdk/VirtualNetworkConfigOperation;"));
  294. EXCEPTIONANDNULLCHECK(VirtualNetworkConfigOperation_VIRTUAL_NETWORK_CONFIG_OPERATION_DOWN_field = env->GetStaticFieldID(VirtualNetworkConfigOperation_class, "VIRTUAL_NETWORK_CONFIG_OPERATION_DOWN", "Lcom/zerotier/sdk/VirtualNetworkConfigOperation;"));
  295. EXCEPTIONANDNULLCHECK(VirtualNetworkConfigOperation_VIRTUAL_NETWORK_CONFIG_OPERATION_UP_field = env->GetStaticFieldID(VirtualNetworkConfigOperation_class, "VIRTUAL_NETWORK_CONFIG_OPERATION_UP", "Lcom/zerotier/sdk/VirtualNetworkConfigOperation;"));
  296. EXCEPTIONANDNULLCHECK(VirtualNetworkStatus_NETWORK_STATUS_ACCESS_DENIED_field = env->GetStaticFieldID(VirtualNetworkStatus_class, "NETWORK_STATUS_ACCESS_DENIED", "Lcom/zerotier/sdk/VirtualNetworkStatus;"));
  297. EXCEPTIONANDNULLCHECK(VirtualNetworkStatus_NETWORK_STATUS_AUTHENTICATION_REQUIRED_field = env->GetStaticFieldID(VirtualNetworkStatus_class, "NETWORK_STATUS_AUTHENTICATION_REQUIRED", "Lcom/zerotier/sdk/VirtualNetworkStatus;"));
  298. EXCEPTIONANDNULLCHECK(VirtualNetworkStatus_NETWORK_STATUS_CLIENT_TOO_OLD_field = env->GetStaticFieldID(VirtualNetworkStatus_class, "NETWORK_STATUS_CLIENT_TOO_OLD", "Lcom/zerotier/sdk/VirtualNetworkStatus;"));
  299. EXCEPTIONANDNULLCHECK(VirtualNetworkStatus_NETWORK_STATUS_NOT_FOUND_field = env->GetStaticFieldID(VirtualNetworkStatus_class, "NETWORK_STATUS_NOT_FOUND", "Lcom/zerotier/sdk/VirtualNetworkStatus;"));
  300. EXCEPTIONANDNULLCHECK(VirtualNetworkStatus_NETWORK_STATUS_OK_field = env->GetStaticFieldID(VirtualNetworkStatus_class, "NETWORK_STATUS_OK", "Lcom/zerotier/sdk/VirtualNetworkStatus;"));
  301. EXCEPTIONANDNULLCHECK(VirtualNetworkStatus_NETWORK_STATUS_PORT_ERROR_field = env->GetStaticFieldID(VirtualNetworkStatus_class, "NETWORK_STATUS_PORT_ERROR", "Lcom/zerotier/sdk/VirtualNetworkStatus;"));
  302. EXCEPTIONANDNULLCHECK(VirtualNetworkStatus_NETWORK_STATUS_REQUESTING_CONFIGURATION_field = env->GetStaticFieldID(VirtualNetworkStatus_class, "NETWORK_STATUS_REQUESTING_CONFIGURATION", "Lcom/zerotier/sdk/VirtualNetworkStatus;"));
  303. EXCEPTIONANDNULLCHECK(VirtualNetworkType_NETWORK_TYPE_PRIVATE_field = env->GetStaticFieldID(VirtualNetworkType_class, "NETWORK_TYPE_PRIVATE", "Lcom/zerotier/sdk/VirtualNetworkType;"));
  304. EXCEPTIONANDNULLCHECK(VirtualNetworkType_NETWORK_TYPE_PUBLIC_field = env->GetStaticFieldID(VirtualNetworkType_class, "NETWORK_TYPE_PUBLIC", "Lcom/zerotier/sdk/VirtualNetworkType;"));
  305. //
  306. // Enums
  307. //
  308. SETOBJECT(ResultCode_RESULT_FATAL_ERROR_INTERNAL_enum, createResultObject(env, ZT_RESULT_FATAL_ERROR_INTERNAL));
  309. SETOBJECT(ResultCode_RESULT_OK_enum, createResultObject(env, ZT_RESULT_OK));
  310. }
  311. void teardownJNICache(JavaVM *vm) {
  312. JNIEnv *env;
  313. GETENV(env, vm);
  314. env->DeleteGlobalRef(ArrayList_class);
  315. env->DeleteGlobalRef(DataStoreGetListener_class);
  316. env->DeleteGlobalRef(DataStorePutListener_class);
  317. env->DeleteGlobalRef(EventListener_class);
  318. env->DeleteGlobalRef(Event_class);
  319. env->DeleteGlobalRef(InetAddress_class);
  320. env->DeleteGlobalRef(InetSocketAddress_class);
  321. env->DeleteGlobalRef(NodeStatus_class);
  322. env->DeleteGlobalRef(Node_class);
  323. env->DeleteGlobalRef(PacketSender_class);
  324. env->DeleteGlobalRef(PathChecker_class);
  325. env->DeleteGlobalRef(PeerPhysicalPath_class);
  326. env->DeleteGlobalRef(PeerRole_class);
  327. env->DeleteGlobalRef(Peer_class);
  328. env->DeleteGlobalRef(ResultCode_class);
  329. env->DeleteGlobalRef(Version_class);
  330. env->DeleteGlobalRef(VirtualNetworkConfigListener_class);
  331. env->DeleteGlobalRef(VirtualNetworkConfigOperation_class);
  332. env->DeleteGlobalRef(VirtualNetworkConfig_class);
  333. env->DeleteGlobalRef(VirtualNetworkDNS_class);
  334. env->DeleteGlobalRef(VirtualNetworkFrameListener_class);
  335. env->DeleteGlobalRef(VirtualNetworkRoute_class);
  336. env->DeleteGlobalRef(VirtualNetworkStatus_class);
  337. env->DeleteGlobalRef(VirtualNetworkType_class);
  338. env->DeleteGlobalRef(ResultCode_RESULT_FATAL_ERROR_INTERNAL_enum);
  339. env->DeleteGlobalRef(ResultCode_RESULT_OK_enum);
  340. }