1
0

test.lua 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. cjdns = require "cjdns/init"
  2. -- CONFIG
  3. confpath = "/etc/cjdroute.conf"
  4. -- SETUP
  5. print("Using config file: " .. confpath)
  6. conf = cjdns.ConfigFile.new(confpath)
  7. ai = conf:makeInterface()
  8. -- TESTS
  9. function testInterface(iface)
  10. local testip = "fc5d:baa5:61fc:6ffd:9554:67f0:e290:7535"
  11. print("Can I ping the admin server?")
  12. print("ping", iface.util:ping())
  13. print("Memory usage in bytes.")
  14. print("bytes", iface.util:memory())
  15. print("Route lookup?")
  16. print("lookup", iface.router:lookup(testip))
  17. print("Router ping?")
  18. local ms, err = iface.router:pingNode(testip)
  19. if err then
  20. print("error", err)
  21. else
  22. print("ping", ms .. "ms")
  23. end
  24. print("Router ping by lookup address...")
  25. local testpath, err = iface.router:lookup(testip)
  26. if testpath then
  27. print("Path: " .. testpath)
  28. local ms, err = iface.router:pingNode(testpath)
  29. if err then
  30. print("error", err)
  31. else
  32. print("ping", ms .. "ms")
  33. end
  34. else
  35. print("testpath failed: " .. err)
  36. end
  37. end
  38. function testAdmin(ai)
  39. testInterface(ai)
  40. print("Can I get a cookie?")
  41. print("cookie", ai:getCookie())
  42. print("Can I ping via auth?")
  43. auth_ping = ai:auth({q = "ping"})
  44. print("ping", (auth_ping and auth_ping.q == "pong"))
  45. end
  46. function testPerm(perm)
  47. testInterface(perm)
  48. print("Attempting to open new UDP interface")
  49. print("serve", perm.udp:newBind("127.0.0.1:20"))
  50. print("Adding remote connection to UDP interface")
  51. print("connect", perm.udp:beginConnection(
  52. "v0zyvrjuc4xbzh4n9c4k3qpx7kg8xgndv2k45j9nfgb373m8sss0.k",
  53. "192.168.0.2:10000",
  54. "null"
  55. ))
  56. end
  57. print("\nAdminInterface ==============================================")
  58. testAdmin(ai)
  59. print("\nPermanence ==================================================")
  60. testPerm(ai.perm)
  61. print("\nConfigFile ==================================================")
  62. print("Exporting compressed conf to test.conf...")
  63. print("save", conf:save("test.conf"))