getLinks 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env python2
  2. # You may redistribute this program and/or modify it under the terms of
  3. # the GNU General Public License as published by the Free Software Foundation,
  4. # either version 3 of the License, or (at your option) any later version.
  5. #
  6. # This program is distributed in the hope that it will be useful,
  7. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. # GNU General Public License for more details.
  10. #
  11. # You should have received a copy of the GNU General Public License
  12. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. from cjdnsadmin.cjdnsadmin import connectWithAdminInfo;
  14. from cjdnsadmin.publicToIp6 import PublicToIp6_convert;
  15. cjdns = connectWithAdminInfo();
  16. def getLink(node, num, nodes, spaces, parentPath):
  17. resp = cjdns.NodeStore_getLink(node, num);
  18. getNode(resp['result'], resp['result']['cannonicalLabel'], nodes, spaces + ' ', parentPath);
  19. def getNode(next, path, nodes, spaces, parentPath):
  20. if (next['child'] in nodes): return;
  21. #nodes = list(nodes);
  22. nodes.append(next['child']);
  23. resp = cjdns.NodeStore_getNode(next['child']);
  24. #print 'cjdns.NodeStore_getNode(' + next['child'] + '); --> ' + str(resp);
  25. #next['child'] = PublicToIp6_convert(resp['result']['key']);
  26. path = '';
  27. if (parentPath != 'ffff.ffff.ffff.ffff' and len(parentPath) == 19):
  28. path = cjdns.NodeStore_getRouteLabel(parentPath, next['child']);
  29. if path['error'] != 'none':
  30. path = path['error'] + ' ' + str(nodes);
  31. print 'cjdns.NodeStore_getRouteLabel(' + parentPath + ', ' + next['child'] + '); --> ' + path;
  32. exit(1);
  33. else: path = path['result'];
  34. print spaces + str(next['child']) + ' ' + str(next['cannonicalLabel']) + " -> " + path;
  35. #print str(resp['result']) + ',';
  36. for i in range(0, int(resp['result']['linkCount'])):
  37. getLink(next['child'], i, nodes, spaces, path);
  38. resp = cjdns.NodeStore_getNode(0);
  39. myIp6 = PublicToIp6_convert(resp['result']['key']);
  40. getNode({"child":myIp6,"cannonicalLabel":""}, '', [], '', '0000.0000.0000.0001');