Fixup Server Settings + IntentRunning event
This commit is contained in:
parent
a48b217d2c
commit
da1658d36a
|
@ -44,14 +44,12 @@ type ServerInfo struct {
|
|||
StorageType string
|
||||
}
|
||||
|
||||
type PublishFn func(event.Event)
|
||||
|
||||
var lock sync.Mutex
|
||||
var appServers server.Servers
|
||||
var killStatsUpdate chan bool = make(chan bool, 1)
|
||||
var enabled bool = false
|
||||
|
||||
func Init(acn connectivity.ACN, appdir string, ) *ServersFunctionality {
|
||||
func Init(acn connectivity.ACN, appdir string) *ServersFunctionality {
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
if appServers == nil {
|
||||
|
@ -73,12 +71,21 @@ var acnStatus = -1
|
|||
|
||||
func (sf *ServersFunctionality) OnACNStatusEvent(appl app.Application, e *event.Event) {
|
||||
newAcnStatus, err := strconv.Atoi(e.Data[event.Progress])
|
||||
if err != nil {
|
||||
if !appl.IsFeatureEnabled(serversExperiment) || err != nil {
|
||||
return
|
||||
}
|
||||
if newAcnStatus == 100 {
|
||||
if acnStatus != 100 {
|
||||
// just came online
|
||||
for _, onion := range sf.ListServers() {
|
||||
autostart := false
|
||||
if s := sf.GetServer(onion); s != nil {
|
||||
autostart = s.GetAttribute(server.AttrAutostart) == "true"
|
||||
}
|
||||
if autostart {
|
||||
sf.LaunchServer(appl, onion)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if acnStatus == 100 {
|
||||
|
@ -114,11 +121,11 @@ type ServersFunctionality struct {
|
|||
|
||||
func (sh *ServersFunctionality) UpdateSettings(appl app.Application, acn connectivity.ACN) {
|
||||
if appl.IsFeatureEnabled(serversExperiment) {
|
||||
sh.Disable()
|
||||
} else {
|
||||
sh.LoadServers(appl, acn, app.DefactoPasswordForUnencryptedProfiles)
|
||||
if !sh.Enabled() {
|
||||
sh.Enable(appl, acn)
|
||||
|
||||
// republish servers
|
||||
serversList := sh.ListServers()
|
||||
for _, server := range serversList {
|
||||
serverInfo := sh.GetServerInfo(server)
|
||||
|
@ -128,6 +135,8 @@ func (sh *ServersFunctionality) UpdateSettings(appl app.Application, acn connect
|
|||
}
|
||||
sh.LaunchServers(appl, acn)
|
||||
}
|
||||
} else {
|
||||
sh.Disable()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -164,7 +173,7 @@ func (sh *ServersFunctionality) LaunchServers(appl app.Application, acn connecti
|
|||
}
|
||||
}
|
||||
|
||||
func (sf *ServersFunctionality) Enable(application app.Application, acn connectivity.ACN, ) {
|
||||
func (sf *ServersFunctionality) Enable(application app.Application, acn connectivity.ACN) {
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
if appServers != nil && !enabled {
|
||||
|
@ -262,12 +271,14 @@ func (sf *ServersFunctionality) DeleteServer(appl app.Application, onion string,
|
|||
}
|
||||
|
||||
func (sf *ServersFunctionality) LaunchServer(appl app.Application, onion string) {
|
||||
log.Infof("Launching Server...")
|
||||
if appl.IsFeatureEnabled(serversExperiment) {
|
||||
appServers.LaunchServer(onion)
|
||||
server := appServers.GetServer(onion)
|
||||
if server != nil {
|
||||
newStats := server.GetStatistics()
|
||||
appl.GetPrimaryBus().Publish(event.NewEventList(ServerStatsUpdate, event.Identity, onion, TotalMessages, strconv.Itoa(newStats.TotalMessages), Connections, strconv.Itoa(newStats.TotalConnections)))
|
||||
appl.GetPrimaryBus().Publish(event.NewEventList(ServerIntentUpdate, event.Identity, onion, Intent, IntentRunning))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ func main() {
|
|||
generatedBindingsPrefix := ``
|
||||
generatedBindings := ``
|
||||
experimentRegistry := ``
|
||||
experimentUpdateSettings := ``
|
||||
|
||||
file, err := os.Open("spec")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
@ -70,6 +72,11 @@ func main() {
|
|||
eventHandler.AddModule(%s)
|
||||
%s.Enable(application, &globalACN)
|
||||
`, parts[2], parts[4], parts[2], parts[2])
|
||||
|
||||
experimentUpdateSettings += fmt.Sprintf(`
|
||||
%s.UpdateSettings(application, &globalACN)
|
||||
`, parts[2])
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -112,6 +119,7 @@ func main() {
|
|||
templateString := string(template)
|
||||
templateString = strings.ReplaceAll(templateString, "{{BINDINGS}}", generatedBindings)
|
||||
templateString = strings.ReplaceAll(templateString, "{{EXPERIMENT_REGISTER}}", experimentRegistry)
|
||||
templateString = strings.ReplaceAll(templateString, "{{EXPERIMENT_UPDATESETTINGS}}", experimentUpdateSettings)
|
||||
templateString = strings.ReplaceAll(templateString, "{{IMPORTS}}", generatedBindingsPrefix)
|
||||
os.WriteFile("lib.go", []byte(templateString), 0644)
|
||||
}
|
||||
|
|
|
@ -488,6 +488,7 @@ func UpdateSettings(settingsJson string) {
|
|||
var newSettings app.GlobalSettings
|
||||
json.Unmarshal([]byte(settingsJson), &newSettings)
|
||||
application.UpdateSettings(newSettings)
|
||||
{{EXPERIMENT_UPDATESETTINGS}}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue