Files
oc-peer/main.go
2026-04-29 11:43:52 +02:00

43 lines
1.2 KiB
Go

package main
import (
"encoding/json"
"oc-peer/infrastructure"
_ "oc-peer/routers"
oclib "cloud.o-forge.io/core/oc-lib"
"cloud.o-forge.io/core/oc-lib/config"
"cloud.o-forge.io/core/oc-lib/tools"
beego "github.com/beego/beego/v2/server/web"
)
const appname = "oc-peer"
func main() {
oclib.InitAPI(appname, map[string][]string{
"/oc/decentralized/search/:search": {"GET"},
"/oc/decentralized/observe": {"GET"},
})
go infrastructure.ListenNATS()
// On startup: reset all ongoing observations in oc-discovery.
// If oc-peer crashed while oc-discovery was still running, oc-discovery may
// hold stale observe streams. Close-all clears them and enters drain mode.
go infrastructure.EmitCloseAll("")
d := oclib.NewRequestAdmin(oclib.LibDataEnum(oclib.PEER), nil).LoadAll(false, 0, 100000)
for _, dd := range d.Data {
if b, err := json.Marshal(dd); err == nil {
go infrastructure.EmitNATS("root", []string{}, tools.PropalgationMessage{
DataType: tools.PEER.EnumIndex(),
Action: tools.PB_CREATE,
Payload: b,
})
}
}
// Retry observe for offline peers every minute.
infrastructure.StartOfflineRetryLoop()
if config.GetConfig().IsApi {
beego.Run()
}
}