DBMirrorSet.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #ifndef ZT_DBMIRRORSET_HPP
  27. #define ZT_DBMIRRORSET_HPP
  28. #include "DB.hpp"
  29. #include <vector>
  30. #include <memory>
  31. #include <mutex>
  32. namespace ZeroTier {
  33. class DBMirrorSet : public DB::ChangeListener
  34. {
  35. public:
  36. DBMirrorSet();
  37. virtual ~DBMirrorSet();
  38. bool waitForReady();
  39. bool isReady();
  40. void save(nlohmann::json &record);
  41. void eraseNetwork(const uint64_t networkId);
  42. void eraseMember(const uint64_t networkId,const uint64_t memberId);
  43. void nodeIsOnline(const uint64_t networkId,const uint64_t memberId,const InetAddress &physicalAddress);
  44. // These are called by various DB instances when changes occur.
  45. virtual void onNetworkUpdate(const DB *db,uint64_t networkId,const nlohmann::json &network);
  46. virtual void onNetworkMemberUpdate(const DB *db,uint64_t networkId,uint64_t memberId,const nlohmann::json &member);
  47. virtual void onNetworkMemberDeauthorize(const DB *db,uint64_t networkId,uint64_t memberId);
  48. virtual void onNetworkMemberOnline(const DB *db,uint64_t networkId,uint64_t memberId,const InetAddress &physicalAddress);
  49. inline void addDB(const std::shared_ptr<DB> &db)
  50. {
  51. std::lock_guard<std::mutex> l(_dbs_l);
  52. _dbs.push_back(db);
  53. }
  54. private:
  55. std::vector< std::shared_ptr< DB > > _dbs;
  56. std::mutex _dbs_l;
  57. };
  58. } // namespace ZeroTier
  59. #endif