Defaults.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. {
  41. std::map< Identity,std::vector<InetAddress> > sn;
  42. Identity id;
  43. std::vector<InetAddress> addrs;
  44. // Nothing special about a supernode... except that they are
  45. // designated as such and trusted to provide WHOIS lookup.
  46. // cthulhu.zerotier.com - New York, New York, USA
  47. addrs.clear();
  48. if (!id.fromString("8acf059fe3:0:482f6ee5dfe902319b419de5bdc765209c0ecda38c4d6e4fcf0d33658398b4527dcd22f93112fb9befd02fd78bf7261b333fc105d192a623ca9e50fc60b374a5"))
  49. throw std::runtime_error("invalid identity in Defaults");
  50. addrs.push_back(InetAddress("198.199.73.93",ZT_DEFAULT_UDP_PORT));
  51. sn[id] = addrs;
  52. // nyarlathotep.zerotier.com - San Francisco, California, USA
  53. addrs.clear();
  54. if (!id.fromString("7e19876aba:0:2a6e2b2318930f60eb097f70d0f4b028b2cd6d3d0c63c014b9039ff35390e41181f216fb2e6fa8d95c1ee9667156411905c3dccfea78d8c6dfafba688170b3fa"))
  55. throw std::runtime_error("invalid identity in Defaults");
  56. addrs.push_back(InetAddress("198.199.97.220",ZT_DEFAULT_UDP_PORT));
  57. sn[id] = addrs;
  58. // shub-niggurath.zerotier.com - Amsterdam, Netherlands
  59. addrs.clear();
  60. if (!id.fromString("36f63d6574:0:67a776487a1a99b32f413329f2b67c43fbf6152e42c6b66e89043e69d93e48314c7d709b58a83016bd2612dd89400b856e18c553da94892f7d3ca16bf2c92c24"))
  61. throw std::runtime_error("invalid identity in Defaults");
  62. addrs.push_back(InetAddress("198.211.127.172",ZT_DEFAULT_UDP_PORT));
  63. sn[id] = addrs;
  64. return sn;
  65. }
  66. static inline std::string _mkDefaultHomePath()
  67. {
  68. #ifdef __UNIX_LIKE__
  69. #ifdef __APPLE__
  70. return std::string("/Library/Application Support/ZeroTier/One");
  71. #else
  72. return std::string("/var/lib/zerotier-one");
  73. #endif
  74. #else
  75. #ifdef __WINDOWS__
  76. OSVERSIONINFO vi;
  77. memset (&vi,0,sizeof(vi));
  78. vi.dwOSVersionInfoSize = sizeof(vi);
  79. GetVersionEx(&vi);
  80. if (vi.dwMajorVersion < 6)
  81. return std::string("C:\\Documents and Settings\\All Users\\Application Data\\ZeroTier\\One");
  82. return std::string("C:\\ProgramData\\ZeroTier\\One");
  83. #else
  84. // unknown platform
  85. #endif
  86. #endif
  87. }
  88. Defaults::Defaults() :
  89. #ifdef ZT_TRACE_MULTICAST
  90. multicastTraceWatcher(ZT_TRACE_MULTICAST),
  91. #endif
  92. defaultHomePath(_mkDefaultHomePath()),
  93. supernodes(_mkSupernodeMap())
  94. {
  95. }
  96. } // namespace ZeroTier