cluster.go 1.7 KB

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