Defaults.cpp 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include "Constants.hpp"
  31. #include "Defaults.hpp"
  32. #include "Utils.hpp"
  33. #ifdef __WINDOWS__
  34. #include <WinSock2.h>
  35. #include <Windows.h>
  36. #include <ShlObj.h>
  37. #endif
  38. namespace ZeroTier {
  39. const Defaults ZT_DEFAULTS;
  40. static inline std::map< Identity,std::vector< std::pair<InetAddress,bool> > > _mkSupernodeMap()
  41. {
  42. std::map< Identity,std::vector< std::pair<InetAddress,bool> > > sn;
  43. Identity id;
  44. std::vector< std::pair<InetAddress,bool> > addrs;
  45. // Nothing special about a supernode... except that they are
  46. // designated as such and trusted to provide WHOIS lookup.
  47. #ifdef ZT_USE_TESTNET
  48. // If ZT_USE_TESTNET is defined we talk to test rather than live supernode
  49. // instances. The testnet may not always be running, so this is probably not
  50. // of any interest to users. Testnet servers run on port 7773 (UDP) and
  51. // 773 (TCP).
  52. // cthulhu.zerotier.com - New York, New York, USA
  53. addrs.clear();
  54. if (!id.fromString("0bfa76f104:0:aff4d4604f2a2538d414a1d69fc722a28bea049d52192aded117c28b0f6c1052db9d36c488c5fe5e2071f2def8f86b6db64db09e819f90fdaedbfcb9f3bcdef9"))
  55. throw std::runtime_error("invalid identity in Defaults");
  56. addrs.push_back(std::pair<InetAddress,bool>(InetAddress("162.243.77.111",7773),false));
  57. addrs.push_back(std::pair<InetAddress,bool>(InetAddress("162.243.77.111",773),true));
  58. sn[id] = addrs;
  59. // nyarlathotep.zerotier.com - San Francisco, California, USA
  60. addrs.clear();
  61. if (!id.fromString("9f2b042cdb:0:8993f9348bb9642afa9a60995a35ef19817894fd0b6859201c0e56e399288867c8f0d01ae2858f9dc6f95eee6d42e2f6d08c44551404906b25679aa6db1faee7"))
  62. throw std::runtime_error("invalid identity in Defaults");
  63. addrs.push_back(std::pair<InetAddress,bool>(InetAddress("198.199.97.220",7773),false));
  64. addrs.push_back(std::pair<InetAddress,bool>(InetAddress("198.199.97.220",773),true));
  65. sn[id] = addrs;
  66. // shub-niggurath.zerotier.com - Amsterdam, Netherlands
  67. addrs.clear();
  68. if (!id.fromString("916a4ca17d:0:b679a8d6761096ba4958fea0036dc4dbb76cb8cbf1ce9bc352cc594c3c24987bb3b30b5448d1f494f5e90a6cdaac9d28317cb4088780278ef20bc7c366cb214a"))
  69. throw std::runtime_error("invalid identity in Defaults");
  70. addrs.push_back(std::pair<InetAddress,bool>(InetAddress("198.211.127.172",7773),false));
  71. addrs.push_back(std::pair<InetAddress,bool>(InetAddress("198.211.127.172",773),true));
  72. sn[id] = addrs;
  73. // yig.zerotier.com - Sydney, Australia
  74. addrs.clear();
  75. if (!id.fromString("3b62c7a69a:0:d967595a3b96d780151764e6ffb47af2fa8865f8e344fba4a684c10dd2e70014e26312f5b8a1590c13bfeb909a1fd35b96a84a8a43e0704cd8d01d9c2b791359"))
  76. throw std::runtime_error("invalid identity in Defaults");
  77. addrs.push_back(std::pair<InetAddress,bool>(InetAddress("108.61.212.61",7773),false));
  78. addrs.push_back(std::pair<InetAddress,bool>(InetAddress("108.61.212.61",773),true));
  79. sn[id] = addrs;
  80. // shoggoth.zerotier.com - Tokyo, Japan
  81. addrs.clear();
  82. if (!id.fromString("345ad16512:0:9e796aec6e083726f45fbfdc10bcf18c0dc7a7914c9ce29f5eb5abcf41bfcb6b3698b68131d347235ae488804317df9c6102e2753841b973037d1e4685dce9fc"))
  83. throw std::runtime_error("invalid identity in Defaults");
  84. addrs.push_back(std::pair<InetAddress,bool>(InetAddress("108.61.200.101",7773),false));
  85. addrs.push_back(std::pair<InetAddress,bool>(InetAddress("108.61.200.101",773),true));
  86. sn[id] = addrs;
  87. #else
  88. // Normally we use the live supernodes.
  89. // cthulhu.zerotier.com - New York, New York, USA
  90. addrs.clear();
  91. if (!id.fromString("8acf059fe3:0:482f6ee5dfe902319b419de5bdc765209c0ecda38c4d6e4fcf0d33658398b4527dcd22f93112fb9befd02fd78bf7261b333fc105d192a623ca9e50fc60b374a5"))
  92. throw std::runtime_error("invalid identity in Defaults");
  93. addrs.push_back(std::pair<InetAddress,bool>(InetAddress("162.243.77.111",ZT_DEFAULT_UDP_PORT),false));
  94. addrs.push_back(std::pair<InetAddress,bool>(InetAddress("162.243.77.111",443),true));
  95. sn[id] = addrs;
  96. // nyarlathotep.zerotier.com - San Francisco, California, USA
  97. addrs.clear();
  98. if (!id.fromString("7e19876aba:0:2a6e2b2318930f60eb097f70d0f4b028b2cd6d3d0c63c014b9039ff35390e41181f216fb2e6fa8d95c1ee9667156411905c3dccfea78d8c6dfafba688170b3fa"))
  99. throw std::runtime_error("invalid identity in Defaults");
  100. addrs.push_back(std::pair<InetAddress,bool>(InetAddress("198.199.97.220",ZT_DEFAULT_UDP_PORT),false));
  101. addrs.push_back(std::pair<InetAddress,bool>(InetAddress("198.199.97.220",443),true));
  102. sn[id] = addrs;
  103. // shub-niggurath.zerotier.com - Amsterdam, Netherlands
  104. addrs.clear();
  105. if (!id.fromString("36f63d6574:0:67a776487a1a99b32f413329f2b67c43fbf6152e42c6b66e89043e69d93e48314c7d709b58a83016bd2612dd89400b856e18c553da94892f7d3ca16bf2c92c24"))
  106. throw std::runtime_error("invalid identity in Defaults");
  107. addrs.push_back(std::pair<InetAddress,bool>(InetAddress("198.211.127.172",ZT_DEFAULT_UDP_PORT),false));
  108. addrs.push_back(std::pair<InetAddress,bool>(InetAddress("198.211.127.172",443),true));
  109. sn[id] = addrs;
  110. // yig.zerotier.com - Sydney, Australia
  111. addrs.clear();
  112. if (!id.fromString("275f0151f6:0:58716258283f7e14a2f999875d9cc681c1f0ca8403dce38ec354ceaf284a555f36402e79a32d03b8c0963245b7f1af61a1ad3519d90e05bc3ce591034f6a1c9c"))
  113. throw std::runtime_error("invalid identity in Defaults");
  114. addrs.push_back(std::pair<InetAddress,bool>(InetAddress("108.61.212.61",ZT_DEFAULT_UDP_PORT),false));
  115. addrs.push_back(std::pair<InetAddress,bool>(InetAddress("108.61.212.61",443),true));
  116. sn[id] = addrs;
  117. // shoggoth.zerotier.com - Tokyo, Japan
  118. addrs.clear();
  119. if (!id.fromString("48e8f875cb:0:5ca54f55e1094f65589f3e6d74158b6964d418ddac3570757128f1c6a2498322d92fcdcd47de459f4d1f9b38df2afd0c7b3fc247ba3d773c38ba35288f24988e"))
  120. throw std::runtime_error("invalid identity in Defaults");
  121. addrs.push_back(std::pair<InetAddress,bool>(InetAddress("108.61.200.101",ZT_DEFAULT_UDP_PORT),false));
  122. addrs.push_back(std::pair<InetAddress,bool>(InetAddress("108.61.200.101",443),true));
  123. sn[id] = addrs;
  124. #endif
  125. return sn;
  126. }
  127. static inline std::string _mkDefaultHomePath()
  128. {
  129. #ifdef __UNIX_LIKE__
  130. #ifdef __APPLE__
  131. return std::string("/Library/Application Support/ZeroTier/One");
  132. #else
  133. return std::string("/var/lib/zerotier-one");
  134. #endif
  135. #else // not __UNIX_LIKE__
  136. #ifdef __WINDOWS__
  137. char buf[16384];
  138. if (SUCCEEDED(SHGetFolderPathA(NULL,CSIDL_COMMON_APPDATA,NULL,0,buf)))
  139. return (std::string(buf) + "\\ZeroTier\\One");
  140. else return std::string("C:\\ZeroTier\\One");
  141. #else
  142. // unknown platform
  143. #endif
  144. #endif // __UNIX_LIKE__ or not...
  145. }
  146. static inline std::map< Address,Identity > _mkUpdateAuth()
  147. {
  148. std::map< Address,Identity > ua;
  149. { // 0001
  150. Identity id("e9bc3707b5:0:c4cef17bde99eadf9748c4fd11b9b06dc5cd8eb429227811d2c336e6b96a8d329e8abd0a4f45e47fe1bcebf878c004c822d952ff77fc2833af4c74e65985c435");
  151. ua[id.address()] = id;
  152. }
  153. { // 0002
  154. Identity id("56520eaf93:0:7d858b47988b34399a9a31136de07b46104d7edb4a98fa1d6da3e583d3a33e48be531532b886f0b12cd16794a66ab9220749ec5112cbe96296b18fe0cc79ca05");
  155. ua[id.address()] = id;
  156. }
  157. { // 0003
  158. Identity id("7c195de2e0:0:9f659071c960f9b0f0b96f9f9ecdaa27c7295feed9c79b7db6eedcc11feb705e6dd85c70fa21655204d24c897865b99eb946b753a2bbcf2be5f5e006ae618c54");
  159. ua[id.address()] = id;
  160. }
  161. { // 0004
  162. Identity id("415f4cfde7:0:54118e87777b0ea5d922c10b337c4f4bd1db7141845bd54004b3255551a6e356ba6b9e1e85357dbfafc45630b8faa2ebf992f31479e9005f0472685f2d8cbd6e");
  163. ua[id.address()] = id;
  164. }
  165. return ua;
  166. }
  167. static inline const char *_mkUpdateUrl()
  168. {
  169. #if defined(__LINUX__) && ( defined(__i386__) || defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(__i386) )
  170. if (sizeof(void *) == 8)
  171. return "http://download.zerotier.com/ZeroTierOneInstaller-linux-x64-LATEST.nfo";
  172. else return "http://download.zerotier.com/ZeroTierOneInstaller-linux-x86-LATEST.nfo";
  173. #define GOT_UPDATE_URL
  174. #endif
  175. #ifdef __APPLE__
  176. return "http://download.zerotier.com/ZeroTierOneInstaller-mac-combined-LATEST.nfo";
  177. #define GOT_UPDATE_URL
  178. #endif
  179. #ifdef __WINDOWS__
  180. return "http://download.zerotier.com/ZeroTierOneInstaller-windows-intel-LATEST.nfo";
  181. #define GOT_UPDATE_URL
  182. #endif
  183. #ifndef GOT_UPDATE_URL
  184. return "";
  185. #endif
  186. }
  187. Defaults::Defaults() :
  188. #ifdef ZT_TRACE_MULTICAST
  189. multicastTraceWatcher(ZT_TRACE_MULTICAST),
  190. #endif
  191. defaultHomePath(_mkDefaultHomePath()),
  192. supernodes(_mkSupernodeMap()),
  193. updateAuthorities(_mkUpdateAuth()),
  194. updateLatestNfoURL(_mkUpdateUrl()),
  195. v4Broadcast(((uint32_t)0xffffffff),ZT_DEFAULT_UDP_PORT)
  196. {
  197. }
  198. } // namespace ZeroTier