Defaults.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. addrs.clear();
  49. if (!id.fromString("d2ba4048c3:0:cfa02701eb69e2f2c64aa498151e57f82c172036967186c93f2afbe45a64d64306f88fa1225724f6f87beabd6a0feb18c746cf4691867542e18b894390692303"))
  50. throw std::runtime_error("invalid identity in Defaults");
  51. addrs.push_back(InetAddress("198.199.73.93",ZT_DEFAULT_UDP_PORT));
  52. sn[id] = addrs;
  53. // nyarlathotep.zerotier.com - San Francisco, California, USA
  54. addrs.clear();
  55. if (!id.fromString("80eb92f707:0:7f0209663d815438dead321ec78c65c27fec6feeb8ccd9acc152c59066740521e45d1a1cbc5186e3773178429c4b26ab0df2c78f3e822540d70456724797f23f"))
  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("34594c9086:0:2ac70c00cc03a078a2a8f889d61e72397f8cd684a6daecbe6350f24e0193790e118805a1673eaf57ce9f7b41f45525c995289c406461c739ccad2c93efa36746"))
  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. return sn;
  66. }
  67. static inline std::string _mkDefaultHomePath()
  68. {
  69. #ifdef __UNIX_LIKE__
  70. #ifdef __APPLE__
  71. return std::string("/Library/Application Support/ZeroTier/One");
  72. #else
  73. return std::string("/var/lib/zerotier-one");
  74. #endif
  75. #else
  76. #ifdef __WINDOWS__
  77. OSVERSIONINFO vi;
  78. memset (&vi,0,sizeof(vi));
  79. vi.dwOSVersionInfoSize = sizeof(vi);
  80. GetVersionEx(&vi);
  81. if (vi.dwMajorVersion < 6)
  82. return std::string("C:\\Documents and Settings\\All Users\\Application Data\\ZeroTier\\One");
  83. return std::string("C:\\ProgramData\\ZeroTier\\One");
  84. #else
  85. // unknown platform
  86. #endif
  87. #endif
  88. }
  89. Defaults::Defaults()
  90. throw(std::runtime_error) :
  91. #ifdef ZT_TRACE_MULTICAST
  92. multicastTraceWatcher(ZT_TRACE_MULTICAST),
  93. #endif
  94. defaultHomePath(_mkDefaultHomePath()),
  95. supernodes(_mkSupernodeMap())
  96. {
  97. }
  98. } // namespace ZeroTier