Discover Catalog Per
This commit is contained in:
51
main.go
51
main.go
@@ -1,12 +1,19 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"oc-catalog/conf"
|
||||
"oc-catalog/infrastructure"
|
||||
_ "oc-catalog/routers"
|
||||
|
||||
oclib "cloud.o-forge.io/core/oc-lib"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
"github.com/beego/beego/v2/server/web/filter/cors"
|
||||
"github.com/libp2p/go-libp2p"
|
||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||
)
|
||||
|
||||
const appname = "oc-catalog"
|
||||
@@ -26,6 +33,10 @@ func main() {
|
||||
o.GetStringDefault("LOKI_URL", ""),
|
||||
o.GetStringDefault("LOG_LEVEL", "info"),
|
||||
)
|
||||
conf.GetConfig().PSKPath = o.GetStringDefault("PSK_PATH", "./psk/psk")
|
||||
conf.GetConfig().DHTEndpointPort = o.GetInt64Default("DHT_ENDPOINT_PORT", 4002)
|
||||
conf.GetConfig().PublicKeyPath = o.GetStringDefault("CATALOG_PUBLIC_KEY_PATH", "./pem/public.pem")
|
||||
conf.GetConfig().PrivateKeyPath = o.GetStringDefault("CATALOG_PRIVATE_KEY_PATH", "./pem/private.pem")
|
||||
// Beego initialization
|
||||
beego.BConfig.AppName = appname
|
||||
beego.BConfig.Listen.HTTPPort = o.GetIntDefault("port", 8080)
|
||||
@@ -40,5 +51,45 @@ func main() {
|
||||
ExposeHeaders: []string{"Content-Length", "Content-Type"},
|
||||
AllowCredentials: true,
|
||||
}))
|
||||
InitDTH()
|
||||
beego.Run()
|
||||
}
|
||||
|
||||
func InitDTH() error {
|
||||
priv, err := infrastructure.LoadKeyFromFile(false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
psk, err := infrastructure.LoadPSKFromFile()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
h, err := libp2p.New(
|
||||
libp2p.PrivateNetwork(psk),
|
||||
libp2p.Identity(priv),
|
||||
libp2p.ListenAddrStrings(
|
||||
fmt.Sprintf("/ip4/0.0.0.0/tcp/%d", conf.GetConfig().DHTEndpointPort),
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ps, err := pubsub.NewGossipSub(context.Background(), h,
|
||||
pubsub.WithMessageSigning(true),
|
||||
pubsub.WithStrictSignatureVerification(true),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
infrastructure.Singleton = &infrastructure.PubSubService{
|
||||
PS: ps,
|
||||
Subscription: []string{},
|
||||
SearchStream: make(map[string]chan resources.ResourceInterface),
|
||||
// mutex field is ready without explicit literal
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user