cluster.go 1.7 KB

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