test.lua 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. print("ping", iface.router:pingNode(testip) .. "ms")
  19. print("Router ping by lookup address...")
  20. local testpath, err = iface.router:lookup(testip)
  21. if testpath then
  22. print("Path: " .. testpath)
  23. print("ping", iface.router:pingNode(testpath) .. "ms")
  24. else
  25. print("testpath failed: " .. err)
  26. end
  27. end
  28. function testAdmin(ai)
  29. testInterface(ai)
  30. print("Can I get a cookie?")
  31. print("cookie", ai:getCookie())
  32. print("Can I ping via auth?")
  33. auth_ping = ai:auth({q = "ping"})
  34. print("ping", (auth_ping and auth_ping.q == "pong"))
  35. end
  36. function testPerm(perm)
  37. testInterface(perm)
  38. print("Attempting to open new UDP interface")
  39. print("serve", perm.udp:newBind("127.0.0.1:20"))
  40. print("Adding remote connection to UDP interface")
  41. print("connect", perm.udp:beginConnection(
  42. "v0zyvrjuc4xbzh4n9c4k3qpx7kg8xgndv2k45j9nfgb373m8sss0.k",
  43. "192.168.0.2:10000",
  44. "null"
  45. ))
  46. end
  47. print("\nAdminInterface ==============================================")
  48. testAdmin(ai)
  49. print("\nPermanence ==================================================")
  50. testPerm(ai.perm)
  51. print("\nConfigFile ==================================================")
  52. print("Exporting compressed conf to test.conf...")
  53. print("save", conf:save("test.conf"))