Defaults.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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<InetAddress> > _mkSupernodeMap()
  41. {
  42. std::map< Identity,std::vector<InetAddress> > sn;
  43. Identity id;
  44. std::vector<InetAddress> addrs;
  45. // Nothing special about a supernode... except that they are
  46. // designated as such and trusted to provide WHOIS lookup.
  47. // cthulhu.zerotier.com - New York, New York, USA
  48. addrs.clear();
  49. if (!id.fromString("8acf059fe3:0:482f6ee5dfe902319b419de5bdc765209c0ecda38c4d6e4fcf0d33658398b4527dcd22f93112fb9befd02fd78bf7261b333fc105d192a623ca9e50fc60b374a5"))
  50. throw std::runtime_error("invalid identity in Defaults");
  51. addrs.push_back(InetAddress("162.243.77.111",ZT_DEFAULT_UDP_PORT));
  52. sn[id] = addrs;
  53. // nyarlathotep.zerotier.com - San Francisco, California, USA
  54. addrs.clear();
  55. if (!id.fromString("7e19876aba:0:2a6e2b2318930f60eb097f70d0f4b028b2cd6d3d0c63c014b9039ff35390e41181f216fb2e6fa8d95c1ee9667156411905c3dccfea78d8c6dfafba688170b3fa"))
  56. throw std::runtime_error("invalid identity in Defaults");
  57. addrs.push_back(InetAddress("198.199.97.220",ZT_DEFAULT_UDP_PORT));
  58. sn[id] = addrs;
  59. // shub-niggurath.zerotier.com - Amsterdam, Netherlands
  60. addrs.clear();
  61. if (!id.fromString("36f63d6574:0:67a776487a1a99b32f413329f2b67c43fbf6152e42c6b66e89043e69d93e48314c7d709b58a83016bd2612dd89400b856e18c553da94892f7d3ca16bf2c92c24"))
  62. throw std::runtime_error("invalid identity in Defaults");
  63. addrs.push_back(InetAddress("198.211.127.172",ZT_DEFAULT_UDP_PORT));
  64. sn[id] = addrs;
  65. // mi-go.zerotier.com - Singapore
  66. addrs.clear();
  67. if (!id.fromString("abbb7f4622:0:89d2c6b2062b10f4ce314dfcb914c082566247090a6f74c8ba1c15c63b205f540758f0abae85287397152c9d8cf463cfe51e7a480946cd6a31495b24ca13253c"))
  68. throw std::runtime_error("invalid identity in Defaults");
  69. addrs.push_back(InetAddress("128.199.254.204",ZT_DEFAULT_UDP_PORT));
  70. sn[id] = addrs;
  71. // shoggoth.zerotier.com - Tokyo, Japan
  72. addrs.clear();
  73. if (!id.fromString("48e8f875cb:0:5ca54f55e1094f65589f3e6d74158b6964d418ddac3570757128f1c6a2498322d92fcdcd47de459f4d1f9b38df2afd0c7b3fc247ba3d773c38ba35288f24988e"))
  74. throw std::runtime_error("invalid identity in Defaults");
  75. addrs.push_back(InetAddress("108.61.200.101",ZT_DEFAULT_UDP_PORT));
  76. sn[id] = addrs;
  77. return sn;
  78. }
  79. static inline std::string _mkDefaultHomePath()
  80. {
  81. #ifdef __UNIX_LIKE__
  82. #ifdef __APPLE__
  83. return std::string("/Library/Application Support/ZeroTier/One");
  84. #else
  85. return std::string("/var/lib/zerotier-one");
  86. #endif
  87. #else // not __UNIX_LIKE__
  88. #ifdef __WINDOWS__
  89. char buf[16384];
  90. if (SUCCEEDED(SHGetFolderPathA(NULL,CSIDL_COMMON_APPDATA,NULL,0,buf)))
  91. return (std::string(buf) + "\\ZeroTier\\One");
  92. else return std::string("C:\\ZeroTier\\One");
  93. #else
  94. // unknown platform
  95. #endif
  96. #endif // __UNIX_LIKE__ or not...
  97. }
  98. static inline std::map< Address,Identity > _mkUpdateAuth()
  99. {
  100. std::map< Address,Identity > ua;
  101. { // 0001
  102. Identity id("e9bc3707b5:0:c4cef17bde99eadf9748c4fd11b9b06dc5cd8eb429227811d2c336e6b96a8d329e8abd0a4f45e47fe1bcebf878c004c822d952ff77fc2833af4c74e65985c435");
  103. ua[id.address()] = id;
  104. }
  105. { // 0002
  106. Identity id("56520eaf93:0:7d858b47988b34399a9a31136de07b46104d7edb4a98fa1d6da3e583d3a33e48be531532b886f0b12cd16794a66ab9220749ec5112cbe96296b18fe0cc79ca05");
  107. ua[id.address()] = id;
  108. }
  109. { // 0003
  110. Identity id("7c195de2e0:0:9f659071c960f9b0f0b96f9f9ecdaa27c7295feed9c79b7db6eedcc11feb705e6dd85c70fa21655204d24c897865b99eb946b753a2bbcf2be5f5e006ae618c54");
  111. ua[id.address()] = id;
  112. }
  113. { // 0004
  114. Identity id("415f4cfde7:0:54118e87777b0ea5d922c10b337c4f4bd1db7141845bd54004b3255551a6e356ba6b9e1e85357dbfafc45630b8faa2ebf992f31479e9005f0472685f2d8cbd6e");
  115. ua[id.address()] = id;
  116. }
  117. return ua;
  118. }
  119. static inline const char *_mkUpdateUrl()
  120. {
  121. #if defined(__LINUX__) && ( defined(__i386__) || defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(__i386) )
  122. if (sizeof(void *) == 8)
  123. return "http://download.zerotier.com/ZeroTierOneInstaller-linux-x64-LATEST.nfo";
  124. else return "http://download.zerotier.com/ZeroTierOneInstaller-linux-x86-LATEST.nfo";
  125. #define GOT_UPDATE_URL
  126. #endif
  127. #ifdef __APPLE__
  128. return "http://download.zerotier.com/ZeroTierOneInstaller-mac-combined-LATEST.nfo";
  129. #define GOT_UPDATE_URL
  130. #endif
  131. #ifdef __WINDOWS__
  132. return "http://download.zerotier.com/ZeroTierOneInstaller-windows-intel-LATEST.nfo";
  133. #define GOT_UPDATE_URL
  134. #endif
  135. #ifndef GOT_UPDATE_URL
  136. return "";
  137. #endif
  138. }
  139. Defaults::Defaults() :
  140. #ifdef ZT_TRACE_MULTICAST
  141. multicastTraceWatcher(ZT_TRACE_MULTICAST),
  142. #endif
  143. defaultHomePath(_mkDefaultHomePath()),
  144. supernodes(_mkSupernodeMap()),
  145. updateAuthorities(_mkUpdateAuth()),
  146. updateLatestNfoURL(_mkUpdateUrl())
  147. {
  148. }
  149. } // namespace ZeroTier