DBMirrorSet.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2019 ZeroTier, Inc. https://www.zerotier.com/
  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. * You can be released from the requirements of the license by purchasing
  21. * a commercial license. Buying such a license is mandatory as soon as you
  22. * develop commercial closed-source software that incorporates or links
  23. * directly against ZeroTier software without disclosing the source code
  24. * of your own application.
  25. */
  26. #include "DBMirrorSet.hpp"
  27. namespace ZeroTier {
  28. DBMirrorSet::DBMirrorSet()
  29. {
  30. }
  31. DBMirrorSet::~DBMirrorSet()
  32. {
  33. }
  34. bool DBMirrorSet::waitForReady()
  35. {
  36. bool r = false;
  37. std::lock_guard<std::mutex> l(_dbs_l);
  38. for(auto d=_dbs.begin();d!=_dbs.end();++d) {
  39. r |= (*d)->waitForReady();
  40. }
  41. return r;
  42. }
  43. bool DBMirrorSet::isReady()
  44. {
  45. std::lock_guard<std::mutex> l(_dbs_l);
  46. for(auto d=_dbs.begin();d!=_dbs.end();++d) {
  47. if (!(*d)->isReady())
  48. return false;
  49. }
  50. return true;
  51. }
  52. void DBMirrorSet::save(nlohmann::json &record)
  53. {
  54. std::lock_guard<std::mutex> l(_dbs_l);
  55. for(auto d=_dbs.begin();d!=_dbs.end();++d) {
  56. (*d)->save(record);
  57. }
  58. }
  59. void DBMirrorSet::eraseNetwork(const uint64_t networkId)
  60. {
  61. std::lock_guard<std::mutex> l(_dbs_l);
  62. for(auto d=_dbs.begin();d!=_dbs.end();++d) {
  63. (*d)->eraseNetwork(networkId);
  64. }
  65. }
  66. void DBMirrorSet::eraseMember(const uint64_t networkId,const uint64_t memberId)
  67. {
  68. std::lock_guard<std::mutex> l(_dbs_l);
  69. for(auto d=_dbs.begin();d!=_dbs.end();++d) {
  70. (*d)->eraseMember(networkId,memberId);
  71. }
  72. }
  73. void DBMirrorSet::nodeIsOnline(const uint64_t networkId,const uint64_t memberId,const InetAddress &physicalAddress)
  74. {
  75. std::lock_guard<std::mutex> l(_dbs_l);
  76. for(auto d=_dbs.begin();d!=_dbs.end();++d) {
  77. (*d)->nodeIsOnline(networkId,memberId,physicalAddress);
  78. }
  79. }
  80. void DBMirrorSet::onNetworkUpdate(const DB *db,uint64_t networkId,const nlohmann::json &network)
  81. {
  82. std::lock_guard<std::mutex> l(_dbs_l);
  83. for(auto d=_dbs.begin();d!=_dbs.end();++d) {
  84. if (d->get() != db) {
  85. }
  86. }
  87. }
  88. void DBMirrorSet::onNetworkMemberUpdate(const DB *db,uint64_t networkId,uint64_t memberId,const nlohmann::json &member)
  89. {
  90. }
  91. void DBMirrorSet::onNetworkMemberDeauthorize(const DB *db,uint64_t networkId,uint64_t memberId)
  92. {
  93. }
  94. void DBMirrorSet::onNetworkMemberOnline(const DB *db,uint64_t networkId,uint64_t memberId,const InetAddress &physicalAddress)
  95. {
  96. }
  97. } // namespace ZeroTier