Defaults.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * ZeroTier One - Global Peer to Peer Ethernet
  3. * Copyright (C) 2012-2013 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. #endif
  37. namespace ZeroTier {
  38. const Defaults ZT_DEFAULTS;
  39. static inline std::map< Identity,std::vector<InetAddress> > _mkSupernodeMap()
  40. throw(std::runtime_error)
  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. #if 0
  49. addrs.clear();
  50. if (!id.fromString("a0fa79d81c:2:0bb348bb38883a29054659a37c204f2c0b082985cb51b36fad31366dfedd616c20aacc5e33ceee2b054670639563238c4fe50bb8716c1ac7996762c0eaefbb23:b7e91f4c77815327c59ff0979f33861e665d002a357448572954c85919be61f768ee6a4d4e42318ffd9cfcc08cadedcd0277a33a950e316a1d7b5bf082919400c44cad1e725fc2035e2d7087d0c8bf51adc5875b643d759a475f899cfbf3e1a4"))
  51. throw std::runtime_error("invalid identity in Defaults");
  52. addrs.push_back(InetAddress("198.199.73.93",ZT_DEFAULT_UDP_PORT));
  53. sn[id] = addrs;
  54. // nyarlathotep.zerotier.com - San Francisco, California, USA
  55. addrs.clear();
  56. if (!id.fromString("1521e171ab:2:43bcdc31f2d75667163f3384bc8866e95ce39b4735999e7760494f6480e0fb70f45675f887f8fdfe50e47b082f3fcfc589381f78b3d3bd1dcbf888ccf14d7935:5026836a5732ed890e778f46ded38410dda51c448f82ab76dd0d2c0152bddd5f05fee2fedf8c9f4ccf1f6181f2cdc1f723c59a143a9928c560b2da652f656507f490acfe70e8f5b2a2bba0eca4ea85b03ce00480afd00d49fc756a03bb740592"))
  57. throw std::runtime_error("invalid identity in Defaults");
  58. addrs.push_back(InetAddress("198.199.97.220",ZT_DEFAULT_UDP_PORT));
  59. sn[id] = addrs;
  60. // shub-niggurath.zerotier.com - Amsterdam, Netherlands
  61. addrs.clear();
  62. if (!id.fromString("11c3bddb9a:2:27e1c10a937dde0d6013e7a93755040ff93a98f5bcad809722a6dcde0b255f07da523f9eae818079be0deccbd4572d2e746fe7b8ba8ae6a7a15bdf0456062c37:5f0a7ea9615388a5532c8ce58f9352ba8950c8b3db261d60c02e1ed5a1a42a5e79bc757b38d8a94d00d8e738a6a33cd9b1586022bdff77c9c49ae16609cf5d03f0f60e36a67467c01870ccf26f61793853b93fb6eab53f65f20f623898e9d28d"))
  63. throw std::runtime_error("invalid identity in Defaults");
  64. addrs.push_back(InetAddress("198.211.127.172",ZT_DEFAULT_UDP_PORT));
  65. sn[id] = addrs;
  66. #endif
  67. return sn;
  68. }
  69. static inline std::string _mkDefaultHomePath()
  70. {
  71. #ifdef __UNIX_LIKE__
  72. #ifdef __APPLE__
  73. return std::string("/Library/Application Support/ZeroTier/One");
  74. #else
  75. return std::string("/var/lib/zerotier-one");
  76. #endif
  77. #else
  78. #ifdef __WINDOWS__
  79. OSVERSIONINFO vi;
  80. memset (&vi,0,sizeof(vi));
  81. vi.dwOSVersionInfoSize = sizeof(vi);
  82. GetVersionEx(&vi);
  83. if (vi.dwMajorVersion < 6)
  84. return std::string("C:\\Documents and Settings\\All Users\\Application Data\\ZeroTier\\One");
  85. return std::string("C:\\ProgramData\\ZeroTier\\One");
  86. #else
  87. // unknown platform
  88. #endif
  89. #endif
  90. }
  91. Defaults::Defaults()
  92. throw(std::runtime_error) :
  93. #ifdef ZT_TRACE_MULTICAST
  94. multicastTraceWatcher(ZT_TRACE_MULTICAST),
  95. #endif
  96. defaultHomePath(_mkDefaultHomePath()),
  97. supernodes(_mkSupernodeMap())
  98. {
  99. }
  100. } // namespace ZeroTier