oclib -> Generate Peer ID
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"runtime/debug"
|
||||
@@ -30,6 +31,7 @@ import (
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
"github.com/beego/beego/v2/server/web/context"
|
||||
"github.com/google/uuid"
|
||||
"github.com/goraz/onion"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
@@ -60,6 +62,25 @@ const (
|
||||
NATIVE_TOOL = tools.NATIVE_TOOL
|
||||
)
|
||||
|
||||
func GenerateNodeID() (string, error) {
|
||||
folderStatic := "/var/lib/opencloud-node"
|
||||
if _, err := os.Stat(folderStatic); err == nil {
|
||||
os.MkdirAll(folderStatic, 0644)
|
||||
}
|
||||
folderStatic += "/node_id"
|
||||
if _, err := os.Stat(folderStatic); os.IsNotExist(err) {
|
||||
hostname, err := os.Hostname()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
id := uuid.NewSHA1(uuid.NameSpaceOID, []byte("oc-"+hostname))
|
||||
err = os.WriteFile(folderStatic, []byte(id.String()), 0644)
|
||||
return id.String(), err
|
||||
}
|
||||
data, err := os.ReadFile(folderStatic)
|
||||
return string(data), err
|
||||
}
|
||||
|
||||
// will turn into standards api hostnames
|
||||
func (d LibDataEnum) API() string {
|
||||
return tools.DefaultAPI[d]
|
||||
|
||||
Reference in New Issue
Block a user