ZeroTierOne.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. /*
  2. * ZeroTier One - Global Peer to Peer Ethernet
  3. * Copyright (C) 2011-2014 ZeroTier Networks LLC
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * --
  19. *
  20. * ZeroTier may be used and distributed under the terms of the GPLv3, which
  21. * are available at: http://www.gnu.org/licenses/gpl-3.0.html
  22. *
  23. * If you would like to embed ZeroTier into a commercial application or
  24. * redistribute it in a modified binary form, please contact ZeroTier Networks
  25. * LLC. Start here: http://www.zerotier.com/
  26. */
  27. /*
  28. * This defines the external C API for ZeroTier One, the core network
  29. * virtualization engine.
  30. */
  31. #ifndef ZT_ZEROTIERONE_H
  32. #define ZT_ZEROTIERONE_H
  33. #include <stdint.h>
  34. /* ------------------------------------------------------------------------ */
  35. /* Query result buffers */
  36. /* ------------------------------------------------------------------------ */
  37. /**
  38. * Node status result buffer
  39. */
  40. struct ZT1_Node_Status
  41. {
  42. /**
  43. * Public identity in string form
  44. */
  45. char publicIdentity[256];
  46. /**
  47. * ZeroTier address in 10-digit hex form
  48. */
  49. char address[16];
  50. /**
  51. * ZeroTier address in least significant 40 bits of 64-bit integer
  52. */
  53. uint64_t rawAddress;
  54. /**
  55. * Number of known peers (including supernodes)
  56. */
  57. unsigned int knownPeers;
  58. /**
  59. * Number of upstream supernodes
  60. */
  61. unsigned int supernodes;
  62. /**
  63. * Number of peers with active direct links
  64. */
  65. unsigned int directlyConnectedPeers;
  66. /**
  67. * Number of peers that have recently communicated with us
  68. */
  69. unsigned int alivePeers;
  70. /**
  71. * Success rate at establishing direct links (0.0 to 1.0, approximate)
  72. */
  73. float directLinkSuccessRate;
  74. /**
  75. * True if connectivity appears good
  76. */
  77. bool online;
  78. /**
  79. * True if running; all other fields are technically undefined if this is false
  80. */
  81. bool running;
  82. /**
  83. * True if initialization is complete
  84. */
  85. bool initialized;
  86. };
  87. /**
  88. * Physical address type
  89. */
  90. enum ZT1_Node_PhysicalAddressType {
  91. ZT1_Node_PhysicalAddress_TYPE_NULL = 0, /* none/invalid */
  92. ZT1_Node_PhysicalAddress_TYPE_IPV4 = 1, /* 32-bit IPv4 address (and port) */
  93. ZT1_Node_PhysicalAddress_TYPE_IPV6 = 2, /* 128-bit IPv6 address (and port) */
  94. ZT1_Node_PhysicalAddress_TYPE_ETHERNET = 3 /* 48-bit Ethernet MAC address */
  95. };
  96. /**
  97. * Physical address result buffer
  98. */
  99. struct ZT1_Node_PhysicalAddress
  100. {
  101. /**
  102. * Physical address type
  103. */
  104. enum ZT1_Node_PhysicalAddressType type;
  105. /**
  106. * Address in raw binary form -- length depends on type
  107. */
  108. unsigned char bits[16];
  109. /**
  110. * Port or netmask bits (for IPV4 and IPV6)
  111. */
  112. unsigned int port;
  113. /**
  114. * Address in canonical human-readable form
  115. */
  116. char ascii[64];
  117. /**
  118. * Zone index identifier (thing after % on IPv6 link-local addresses only)
  119. */
  120. char zoneIndex[16];
  121. };
  122. /**
  123. * Physical path type
  124. */
  125. enum ZT1_Node_PhysicalPathType { /* These must be numerically the same as type in Path.hpp */
  126. ZT1_Node_PhysicalPath_TYPE_NULL = 0, /* none/invalid */
  127. ZT1_Node_PhysicalPath_TYPE_UDP = 1, /* UDP association */
  128. ZT1_Node_PhysicalPath_TYPE_TCP_OUT = 2, /* outgoing TCP tunnel using pseudo-SSL */
  129. ZT1_Node_PhysicalPath_TYPE_TCP_IN = 3, /* incoming TCP tunnel using pseudo-SSL */
  130. ZT1_Node_PhysicalPath_TYPE_ETHERNET = 4 /* raw ethernet frames over trusted backplane */
  131. };
  132. /**
  133. * Network path result buffer
  134. */
  135. struct ZT1_Node_PhysicalPath
  136. {
  137. /**
  138. * Physical path type
  139. */
  140. enum ZT1_Node_PhysicalPathType type;
  141. /**
  142. * Physical address of endpoint
  143. */
  144. struct ZT1_Node_PhysicalAddress address;
  145. /**
  146. * Time since last send in milliseconds or -1 for never
  147. */
  148. long lastSend;
  149. /**
  150. * Time since last receive in milliseconds or -1 for never
  151. */
  152. long lastReceive;
  153. /**
  154. * Time since last ping in milliseconds or -1 for never
  155. */
  156. long lastPing;
  157. /**
  158. * Is path active/connected? Non-fixed active paths may be garbage collected over time.
  159. */
  160. bool active;
  161. /**
  162. * Is path fixed? (i.e. not learned, static)
  163. */
  164. bool fixed;
  165. };
  166. /**
  167. * What trust hierarchy role does this device have?
  168. */
  169. enum ZT1_Node_PeerRole {
  170. ZT1_Node_Peer_SUPERNODE = 0, // planetary supernode
  171. ZT1_Node_Peer_HUB = 1, // locally federated hub (coming soon)
  172. ZT1_Node_Peer_NODE = 2 // ordinary node
  173. };
  174. /**
  175. * Peer status result buffer
  176. */
  177. struct ZT1_Node_Peer
  178. {
  179. /**
  180. * Remote peer version: major.minor.revision (or empty if unknown)
  181. */
  182. char remoteVersion[16];
  183. /**
  184. * ZeroTier address of peer as 10-digit hex string
  185. */
  186. char address[16];
  187. /**
  188. * ZeroTier address in least significant 40 bits of 64-bit integer
  189. */
  190. uint64_t rawAddress;
  191. /**
  192. * Last measured latency in milliseconds or zero if unknown
  193. */
  194. unsigned int latency;
  195. /**
  196. * What trust hierarchy role does this device have?
  197. */
  198. enum ZT1_Node_PeerRole role;
  199. /**
  200. * Array of network paths to peer
  201. */
  202. struct ZT1_Node_PhysicalPath *paths;
  203. /**
  204. * Number of paths (size of paths[])
  205. */
  206. unsigned int numPaths;
  207. };
  208. /**
  209. * List of peers
  210. */
  211. struct ZT1_Node_PeerList
  212. {
  213. struct ZT1_Node_Peer *peers;
  214. unsigned int numPeers;
  215. };
  216. /**
  217. * Network status code
  218. */
  219. enum ZT1_Node_NetworkStatus {
  220. ZT1_Node_Network_INITIALIZING = 0,
  221. ZT1_Node_Network_WAITING_FOR_FIRST_AUTOCONF = 1,
  222. ZT1_Node_Network_OK = 2,
  223. ZT1_Node_Network_ACCESS_DENIED = 3,
  224. ZT1_Node_Network_NOT_FOUND = 4,
  225. ZT1_Node_Network_INITIALIZATION_FAILED = 5,
  226. ZT1_Node_Network_NO_MORE_DEVICES = 6
  227. };
  228. /**
  229. * Network status result buffer
  230. */
  231. struct ZT1_Node_Network
  232. {
  233. /**
  234. * 64-bit network ID
  235. */
  236. uint64_t nwid;
  237. /**
  238. * 64-bit network ID in hex form
  239. */
  240. char nwidHex[32];
  241. /**
  242. * Short network name
  243. */
  244. char name[256];
  245. /**
  246. * Longer network description
  247. */
  248. char description[4096];
  249. /**
  250. * Device name (system-dependent)
  251. */
  252. char device[256];
  253. /**
  254. * Status code in string format
  255. */
  256. char statusStr[64];
  257. /**
  258. * Ethernet MAC address of this endpoint in string form
  259. */
  260. char macStr[32];
  261. /**
  262. * Ethernet MAC address of this endpoint on the network in raw binary form
  263. */
  264. unsigned char mac[6];
  265. /**
  266. * Age of configuration in milliseconds or -1 if never refreshed
  267. */
  268. long configAge;
  269. /**
  270. * Assigned layer-3 IPv4 and IPv6 addresses
  271. *
  272. * Note that PhysicalAddress also supports other address types, but this
  273. * list will only list IP address assignments. The port field will contain
  274. * the number of bits in the netmask -- e.g. 192.168.1.1/24.
  275. */
  276. struct ZT1_Node_PhysicalAddress *ips;
  277. /**
  278. * Number of layer-3 IPs (size of ips[])
  279. */
  280. unsigned int numIps;
  281. /**
  282. * Network status code
  283. */
  284. enum ZT1_Node_NetworkStatus status;
  285. /**
  286. * True if traffic on network is enabled
  287. */
  288. bool enabled;
  289. /**
  290. * Is this a private network? If false, network lacks access control.
  291. */
  292. bool isPrivate;
  293. };
  294. /**
  295. * Return buffer for list of networks
  296. */
  297. struct ZT1_Node_NetworkList
  298. {
  299. struct ZT1_Node_Network *networks;
  300. unsigned int numNetworks;
  301. };
  302. /* ------------------------------------------------------------------------ */
  303. /* ZeroTier One C API */
  304. /* ------------------------------------------------------------------------ */
  305. /* coming soon... */
  306. #endif