cluster.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package main
  2. import (
  3. "net/http"
  4. "imuslab.com/arozos/mod/network/neighbour"
  5. prout "imuslab.com/arozos/mod/prouter"
  6. )
  7. /*
  8. Functions related to ArozOS clusters
  9. Author: tobychui
  10. This is a section of the arozos core that handle cluster
  11. related function endpoints
  12. */
  13. var (
  14. NeighbourDiscoverer *neighbour.Discoverer
  15. )
  16. func ClusterInit() {
  17. //Only enable cluster scanning on mdns enabled mode
  18. if *allow_mdns && MDNS != nil {
  19. //Start the network discovery
  20. thisDiscoverer := neighbour.NewDiscoverer(MDNS, sysdb)
  21. //Start a scan immediately (in go routine for non blocking)
  22. go func() {
  23. thisDiscoverer.UpdateScan(10)
  24. }()
  25. //Setup the scanning timer
  26. thisDiscoverer.StartScanning(300, 15)
  27. NeighbourDiscoverer = &thisDiscoverer
  28. //Register the settings
  29. registerSetting(settingModule{
  30. Name: "Neighbourhood",
  31. Desc: "Nearby ArOZ Host for Clustering",
  32. IconPath: "SystemAO/cluster/img/small_icon.png",
  33. Group: "Cluster",
  34. StartDir: "SystemAO/cluster/neighbour.html",
  35. RequireAdmin: false,
  36. })
  37. //Register cluster scanning endpoints
  38. router := prout.NewModuleRouter(prout.RouterOption{
  39. ModuleName: "System Setting",
  40. UserHandler: userHandler,
  41. DeniedHandler: func(w http.ResponseWriter, r *http.Request) {
  42. errorHandlePermissionDenied(w, r)
  43. },
  44. })
  45. router.HandleFunc("/system/cluster/scan", NeighbourDiscoverer.HandleScanningRequest)
  46. router.HandleFunc("/system/cluster/record", NeighbourDiscoverer.HandleScanRecord)
  47. router.HandleFunc("/system/cluster/wol", NeighbourDiscoverer.HandleWakeOnLan)
  48. /*
  49. Start and Cluster Server and Client
  50. */
  51. //WIP
  52. } else {
  53. systemWideLogger.PrintAndLog("Cluster", "MDNS not enabled or startup failed. Skipping Cluster Scanner initiation.", nil)
  54. }
  55. }