2024-07-11 11:40:11 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2026-04-29 11:43:52 +02:00
|
|
|
"encoding/json"
|
2026-02-23 17:18:16 +01:00
|
|
|
"oc-peer/infrastructure"
|
2024-10-15 10:51:12 +02:00
|
|
|
_ "oc-peer/routers"
|
2024-07-11 11:40:11 +02:00
|
|
|
|
2024-07-24 10:25:08 +02:00
|
|
|
oclib "cloud.o-forge.io/core/oc-lib"
|
2026-04-29 11:43:52 +02:00
|
|
|
"cloud.o-forge.io/core/oc-lib/config"
|
|
|
|
|
"cloud.o-forge.io/core/oc-lib/tools"
|
2026-02-05 15:48:41 +01:00
|
|
|
beego "github.com/beego/beego/v2/server/web"
|
2024-07-11 11:40:11 +02:00
|
|
|
)
|
|
|
|
|
|
2024-10-15 10:51:12 +02:00
|
|
|
const appname = "oc-peer"
|
2024-07-11 11:40:11 +02:00
|
|
|
|
|
|
|
|
func main() {
|
2026-04-01 11:27:05 +02:00
|
|
|
oclib.InitAPI(appname, map[string][]string{
|
|
|
|
|
"/oc/decentralized/search/:search": {"GET"},
|
2026-04-29 11:43:52 +02:00
|
|
|
"/oc/decentralized/observe": {"GET"},
|
2026-04-01 11:27:05 +02:00
|
|
|
})
|
2026-02-23 17:18:16 +01:00
|
|
|
go infrastructure.ListenNATS()
|
2026-04-29 11:43:52 +02:00
|
|
|
// 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()
|
|
|
|
|
}
|
2024-07-11 11:40:11 +02:00
|
|
|
}
|