Node.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2015 ZeroTier, Inc.
  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 "Node.hpp"
  28. #include "RuntimeEnvironment.hpp"
  29. #include "NetworkConfigMaster.hpp"
  30. #include "CMWC4096.hpp"
  31. #include "Switch.hpp"
  32. #include "Multicaster.hpp"
  33. #include "AntiRecursion.hpp"
  34. #include "Topology.hpp"
  35. #include "Buffer.hpp"
  36. #include "Packet.hpp"
  37. #include "Logger.hpp"
  38. #include "Address.hpp"
  39. #include "Identity.hpp"
  40. namespace ZeroTier {
  41. Node::Node(
  42. ZT1_DataStoreGetFunction *dataStoreGetFunction,
  43. ZT1_DataStorePutFunction *dataStorePutFunction,
  44. ZT1_WirePacketSendFunction *wirePacketSendFunction,
  45. ZT1_VirtualNetworkFrameFunction *virtualNetworkFrameFunction,
  46. ZT1_VirtualNetworkConfigCallback *networkConfigCallback,
  47. ZT1_StatusCallback *statusCallback) :
  48. RR(new RuntimeEnvironment(this)),
  49. _dataStoreGetFunction(dataStoreGetFunction),
  50. _dataStorePutFunction(dataStorePutFunction),
  51. _wirePacketSendFunction(wirePacketSendFunction),
  52. _virtualNetworkFrameFunction(virtualNetworkFrameFunction),
  53. _networkConfigCallback(networkConfigCallback),
  54. _statusCallback(statusCallback),
  55. _networks(),
  56. _networks_m(),
  57. _now(0),
  58. _timeOfLastPacketReceived(0),
  59. _timeOfLastPrivilegedPacket(0),
  60. _spamCounter(0)
  61. {
  62. try {
  63. RR->prng = new CMWC4096();
  64. RR->sw = new Switch(RR);
  65. RR->mc = new Multicaster(RR);
  66. RR->antiRec = new AntiRecursion(RR);
  67. RR->topology = new Topology(RR);
  68. } catch ( ... ) {
  69. delete RR->topology;
  70. delete RR->antiRec;
  71. delete RR->mc;
  72. delete RR->sw;
  73. delete RR->prng;
  74. delete RR->log;
  75. delete RR;
  76. throw;
  77. }
  78. }
  79. Node::~Node()
  80. {
  81. delete RR->topology;
  82. delete RR->antiRec;
  83. delete RR->mc;
  84. delete RR->sw;
  85. delete RR->prng;
  86. delete RR->log;
  87. delete RR;
  88. }
  89. ZT1_ResultCode Node::join(uint64_t nwid)
  90. {
  91. }
  92. ZT1_ResultCode Node::leave(uint64_t nwid)
  93. {
  94. }
  95. ZT1_ResultCode Node::multicastSubscribe(ZT1_Node *node,uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
  96. {
  97. }
  98. ZT1_ResultCode Node::multicastUnsubscribe(ZT1_Node *node,uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
  99. {
  100. }
  101. void Node::status(ZT1_NodeStatus *status)
  102. {
  103. }
  104. ZT1_PeerList *Node::peers()
  105. {
  106. }
  107. ZT1_VirtualNetworkConfig *Node::networkConfig(uint64_t nwid)
  108. {
  109. }
  110. ZT1_VirtualNetworkList *Node::listNetworks()
  111. {
  112. }
  113. void Node::freeQueryResult(void *qr)
  114. {
  115. if (qr)
  116. ::free(qr);
  117. }
  118. void Node::setNetconfMaster(void *networkConfigMasterInstance)
  119. {
  120. RR->netconfMaster = reinterpret_cast<NetworkConfigMaster *>(networkConfigMasterInstance);
  121. }
  122. } // namespace ZeroTier