neo local peer draft

This commit is contained in:
mr
2024-10-30 11:17:52 +01:00
parent 1a55212378
commit 4de43a301c
8 changed files with 23 additions and 49 deletions

View File

@@ -5,7 +5,6 @@ import (
"fmt"
"cloud.o-forge.io/core/oc-lib/models/utils"
"cloud.o-forge.io/core/oc-lib/static"
"cloud.o-forge.io/core/oc-lib/tools"
"github.com/google/uuid"
)
@@ -21,6 +20,14 @@ const (
BLACKLIST
)
func (m PeerState) String() string {
return [...]string{"NONE", "SELF", "PARTNER", "BLACKLIST"}[m]
}
func (m PeerState) EnumIndex() int {
return int(m)
}
// Peer is a struct that represents a peer
type Peer struct {
utils.AbstractObject
@@ -57,9 +64,13 @@ func (ao *Peer) RemoveExecution(exec PeerExecution) {
}
// IsMySelf checks if the peer is the local peer
func (ao *Peer) IsMySelf() bool {
id, _ := static.GetMyLocalJsonPeer()
return ao.UUID == id
func (ao *Peer) IsMySelf() (bool, string) {
d, code, err := ao.GetAccessor(nil).Search(nil, SELF.String())
if code != 200 || err != nil || len(d) == 0 {
return false, ""
}
id := d[0].GetID()
return ao.UUID == id, id
}
// LaunchPeerExecution launches an execution on a peer

View File

@@ -1,6 +1,7 @@
package peer
import (
"fmt"
"strconv"
"cloud.o-forge.io/core/oc-lib/dbs"
@@ -70,6 +71,7 @@ func (wfa *peerMongoAccessor) Search(filters *dbs.Filters, search string) ([]uti
objs := []utils.ShallowDBObject{}
if (filters == nil || len(filters.And) == 0 || len(filters.Or) == 0) && search != "" {
s, err := strconv.Atoi(search)
fmt.Println(s, err, search)
if err == nil {
filters = &dbs.Filters{
Or: map[string][]dbs.Filter{ // search by name if no filters are provided