mktopology.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* Makes topology dictionary out of source dictionary and signs with
  2. * 'topology.secret', which must be present (or symlinked) from where
  3. * this is run. */
  4. /* Just type 'make' and then run (Only tested on Linux) */
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <stdlib.h>
  8. #include <string>
  9. #include <iostream>
  10. #include <map>
  11. #include "../node/Utils.hpp"
  12. #include "../node/Identity.hpp"
  13. #include "../node/Dictionary.hpp"
  14. using namespace ZeroTier;
  15. int main(int argc,char **argv)
  16. {
  17. std::string buf;
  18. if (!Utils::readFile("topology.secret",buf)) {
  19. std::cerr << "Cannot read topology.secret" << std::endl;
  20. return 1;
  21. }
  22. Identity topologyAuthority(buf);
  23. Dictionary topology;
  24. Dictionary supernodes;
  25. std::map<std::string,bool> supernodeDictionaries(Utils::listDirectory("supernodes"));
  26. for(std::map<std::string,bool>::iterator sn(supernodeDictionaries.begin());sn!=supernodeDictionaries.end();++sn) {
  27. if ((sn->first.length() == 10)&&(!sn->second)) {
  28. buf.clear();
  29. if (!Utils::readFile((std::string("supernodes/")+sn->first).c_str(),buf)) {
  30. std::cerr << "Cannot read supernodes/" << sn->first << std::endl;
  31. return 1;
  32. }
  33. supernodes[sn->first] = buf;
  34. }
  35. }
  36. topology["supernodes"] = supernodes.toString();
  37. if (!topology.sign(topologyAuthority)) {
  38. std::cerr << "Unable to sign!" << std::endl;
  39. return 1;
  40. }
  41. std::cout << topology.toString();
  42. return 0;
  43. }