Node.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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_VirtualNetworkConfigCallback *networkConfigCallback,
  45. ZT1_StatusCallback *statusCallback) :
  46. RR(new RuntimeEnvironment(this)),
  47. _outputWireMessages((ZT1_WireMessage *)0),
  48. _outputWireMessageCount(0),
  49. _outputWireMessageCapacity(8),
  50. _outputWireMessages_m(),
  51. _outputFrames((ZT1_VirtualNetworkFrame *)0),
  52. _outputFrameCount(0),
  53. _outputFrameCapacity(8),
  54. _outputFrames_m(),
  55. _dataStoreGetFunction(dataStoreGetFunction),
  56. _dataStorePutFunction(dataStorePutFunction),
  57. _networkConfigCallback(networkConfigCallback),
  58. _statusCallback(statusCallback),
  59. _networks(),
  60. _networks_m(),
  61. _now(0),
  62. _timeOfLastPacketReceived(0),
  63. _timeOfLastPrivilegedPacket(0),
  64. _spamCounter(0)
  65. {
  66. try {
  67. _outputWireMessages = new ZT1_WireMessage[_outputWireMessageCapacity];
  68. _outputFrames = new ZT1_VirtualNetworkFrame[_outputFrameCapacity];
  69. RR->prng = new CMWC4096();
  70. RR->sw = new Switch(RR);
  71. RR->mc = new Multicaster(RR);
  72. RR->antiRec = new AntiRecursion(RR);
  73. RR->topology = new Topology(RR);
  74. } catch ( ... ) {
  75. delete [] _outputFrames;
  76. delete [] _outputWireMessages;
  77. delete RR->topology;
  78. delete RR->antiRec;
  79. delete RR->mc;
  80. delete RR->sw;
  81. delete RR->prng;
  82. delete RR->log;
  83. delete RR;
  84. throw;
  85. }
  86. }
  87. Node::~Node()
  88. {
  89. delete [] _outputFrames;
  90. delete [] _outputWireMessages;
  91. delete RR->topology;
  92. delete RR->antiRec;
  93. delete RR->mc;
  94. delete RR->sw;
  95. delete RR->prng;
  96. delete RR->log;
  97. delete RR;
  98. }
  99. ZT1_ResultCode Node::run(
  100. uint64_t now,
  101. const ZT1_WireMessage *inputWireMessages,
  102. unsigned int inputWireMessageCount,
  103. const ZT1_VirtualNetworkFrame *inputFrames,
  104. unsigned int inputFrameCount,
  105. const ZT1_WireMessage **outputWireMessages,
  106. unsigned int *outputWireMessageCount,
  107. const ZT1_VirtualNetworkFrame **outputFrames,
  108. unsigned int *outputLanFrameCount,
  109. unsigned long *maxNextInterval)
  110. {
  111. }
  112. ZT1_ResultCode Node::join(uint64_t nwid)
  113. {
  114. }
  115. ZT1_ResultCode Node::leave(uint64_t nwid)
  116. {
  117. }
  118. void Node::status(ZT1_NodeStatus *status)
  119. {
  120. }
  121. ZT1_PeerList *Node::peers()
  122. {
  123. }
  124. ZT1_VirtualNetworkConfig *Node::networkConfig(uint64_t nwid)
  125. {
  126. }
  127. ZT1_VirtualNetworkList *Node::listNetworks()
  128. {
  129. }
  130. void Node::freeQueryResult(void *qr)
  131. {
  132. if (qr)
  133. ::free(qr);
  134. }
  135. void Node::setNetconfMaster(void *networkConfigMasterInstance)
  136. {
  137. RR->netconfMaster = reinterpret_cast<NetworkConfigMaster *>(networkConfigMasterInstance);
  138. }
  139. } // namespace ZeroTier