Defaults.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * ZeroTier One - Global Peer to Peer Ethernet
  3. * Copyright (C) 2011-2015 ZeroTier Networks
  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. // bin2c'd signed default root topology dictionary
  34. #include "../root-topology/ZT_DEFAULT_ROOT_TOPOLOGY.c"
  35. #ifdef __WINDOWS__
  36. #include <WinSock2.h>
  37. #include <Windows.h>
  38. #include <ShlObj.h>
  39. #endif
  40. namespace ZeroTier {
  41. const Defaults ZT_DEFAULTS;
  42. static inline std::string _mkDefaultHomePath()
  43. {
  44. #ifdef __UNIX_LIKE__
  45. #ifdef __APPLE__
  46. // /Library/... on Apple
  47. return std::string("/Library/Application Support/ZeroTier/One");
  48. #else
  49. #ifdef __FreeBSD__
  50. // FreeBSD likes /var/db instead of /var/lib
  51. return std::string("/var/db/zerotier-one");
  52. #else
  53. // Use /var/lib for Linux and other *nix
  54. return std::string("/var/lib/zerotier-one");
  55. #endif
  56. #endif
  57. #else // not __UNIX_LIKE__
  58. #ifdef __WINDOWS__
  59. // Look up app data folder on Windows, e.g. C:\ProgramData\...
  60. char buf[16384];
  61. if (SUCCEEDED(SHGetFolderPathA(NULL,CSIDL_COMMON_APPDATA,NULL,0,buf)))
  62. return (std::string(buf) + "\\ZeroTier\\One");
  63. else return std::string("C:\\ZeroTier\\One");
  64. #else
  65. #error Unknown platform, please define a default home path!
  66. #endif
  67. #endif // __UNIX_LIKE__ or not...
  68. }
  69. static inline std::map< Address,Identity > _mkRootTopologyAuth()
  70. {
  71. std::map< Address,Identity > ua;
  72. { // 0001
  73. Identity id("77792b1c02:0:b5c361e8e9c2154e82c3e902fdfc337468b092a7c4d8dc685c37eb10ee4f3c17cc0bb1d024167e8cb0824d12263428373582da3d0a9a14b36e4546c317e811e6");
  74. ua[id.address()] = id;
  75. }
  76. { // 0002
  77. Identity id("86921e6de1:0:9ba04f9f12ed54ef567f548cb69d31e404537d7b0ee000c63f3d7c8d490a1a47a5a5b2af0cbe12d23f9194270593f298d936d7c872612ea509ef1c67ce2c7fc1");
  78. ua[id.address()] = id;
  79. }
  80. { // 0003
  81. Identity id("90302b7025:0:358154a57af1b7afa07d0d91b69b92eaad2f11ade7f02343861f0c1b757d15626e8cb7f08fc52993d2202a39cbf5128c5647ee8c63d27d92db5a1d0fbe1eba19");
  82. ua[id.address()] = id;
  83. }
  84. { // 0004
  85. Identity id("e5174078ee:0:c3f90daa834a74ee47105f5726ae2e29fc8ae0e939c9326788b52b16d847354de8de3b13a81896bbb509b91e1da21763073a30bbfb2b8e994550798d30a2d709");
  86. ua[id.address()] = id;
  87. }
  88. return ua;
  89. }
  90. static inline std::map< Address,Identity > _mkUpdateAuth()
  91. {
  92. std::map< Address,Identity > ua;
  93. { // 0001
  94. Identity id("e9bc3707b5:0:c4cef17bde99eadf9748c4fd11b9b06dc5cd8eb429227811d2c336e6b96a8d329e8abd0a4f45e47fe1bcebf878c004c822d952ff77fc2833af4c74e65985c435");
  95. ua[id.address()] = id;
  96. }
  97. { // 0002
  98. Identity id("56520eaf93:0:7d858b47988b34399a9a31136de07b46104d7edb4a98fa1d6da3e583d3a33e48be531532b886f0b12cd16794a66ab9220749ec5112cbe96296b18fe0cc79ca05");
  99. ua[id.address()] = id;
  100. }
  101. { // 0003
  102. Identity id("7c195de2e0:0:9f659071c960f9b0f0b96f9f9ecdaa27c7295feed9c79b7db6eedcc11feb705e6dd85c70fa21655204d24c897865b99eb946b753a2bbcf2be5f5e006ae618c54");
  103. ua[id.address()] = id;
  104. }
  105. { // 0004
  106. Identity id("415f4cfde7:0:54118e87777b0ea5d922c10b337c4f4bd1db7141845bd54004b3255551a6e356ba6b9e1e85357dbfafc45630b8faa2ebf992f31479e9005f0472685f2d8cbd6e");
  107. ua[id.address()] = id;
  108. }
  109. return ua;
  110. }
  111. static inline const char *_mkUpdateUrl()
  112. {
  113. #if defined(__LINUX__) && ( defined(__i386__) || defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(__i386) )
  114. if (sizeof(void *) == 8)
  115. return "http://download.zerotier.com/ZeroTierOneInstaller-linux-x64-LATEST.nfo";
  116. else return "http://download.zerotier.com/ZeroTierOneInstaller-linux-x86-LATEST.nfo";
  117. #define GOT_UPDATE_URL
  118. #endif
  119. #ifdef __APPLE__
  120. return "http://download.zerotier.com/ZeroTierOneInstaller-mac-combined-LATEST.nfo";
  121. #define GOT_UPDATE_URL
  122. #endif
  123. #ifdef __WINDOWS__
  124. return "http://download.zerotier.com/ZeroTierOneInstaller-windows-intel-LATEST.nfo";
  125. #define GOT_UPDATE_URL
  126. #endif
  127. #ifndef GOT_UPDATE_URL
  128. return "";
  129. #endif
  130. }
  131. Defaults::Defaults() :
  132. defaultHomePath(_mkDefaultHomePath()),
  133. defaultRootTopology((const char *)ZT_DEFAULT_ROOT_TOPOLOGY,ZT_DEFAULT_ROOT_TOPOLOGY_LEN),
  134. rootTopologyAuthorities(_mkRootTopologyAuth()),
  135. updateAuthorities(_mkUpdateAuth()),
  136. updateLatestNfoURL(_mkUpdateUrl()),
  137. rootTopologyUpdateURL("http://download.zerotier.com/net/topology/ROOT"),
  138. v4Broadcast(((uint32_t)0xffffffff),ZT_DEFAULT_UDP_PORT)
  139. {
  140. }
  141. } // namespace ZeroTier