cluster.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. /*
  49. Start and Cluster Server and Client
  50. */
  51. //WIP
  52. } else {
  53. log.Println("MDNS not enabled or startup failed. Skipping Cluster Scanner initiation.")
  54. }
  55. }