update lightest peer and nats behaviors
This commit is contained in:
@@ -17,7 +17,6 @@ import (
|
||||
"time"
|
||||
|
||||
oclib "cloud.o-forge.io/core/oc-lib"
|
||||
peer "cloud.o-forge.io/core/oc-lib/models/peer"
|
||||
"github.com/libp2p/go-libp2p/core/host"
|
||||
"github.com/libp2p/go-libp2p/core/network"
|
||||
pp "github.com/libp2p/go-libp2p/core/peer"
|
||||
@@ -72,20 +71,6 @@ func (ix *LongLivedStreamRecordedService[T]) gc() {
|
||||
delete(sstreams, pid)
|
||||
}
|
||||
}
|
||||
ix.PubsubMu.Lock()
|
||||
if ix.LongLivedPubSubs[TopicPubSubNodeActivity] != nil {
|
||||
if b, err := json.Marshal(TopicNodeActivityPub{
|
||||
Disposer: "/ip4/" + conf.GetConfig().Hostname + "/tcp/" + fmt.Sprintf("%v", conf.GetConfig().NodeEndpointPort) + "/p2p/" + ix.Host.ID().String(),
|
||||
Name: rec.HeartbeatStream.Name,
|
||||
DID: rec.HeartbeatStream.DID,
|
||||
PeerID: pid.String(),
|
||||
NodeActivity: peer.OFFLINE.EnumIndex(),
|
||||
}); err == nil {
|
||||
ix.LongLivedPubSubs[TopicPubSubNodeActivity].Publish(context.Background(), b)
|
||||
}
|
||||
|
||||
}
|
||||
ix.PubsubMu.Unlock()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,6 @@ func (pr *PeerRecord) ExtractPeer(ourkey string, key string, pubKey crypto.PubKe
|
||||
UUID: pr.DID,
|
||||
Name: pr.Name,
|
||||
},
|
||||
State: pp.ONLINE,
|
||||
Relation: rel, // VERIFY.... it crush nothing
|
||||
PeerID: pr.PeerID,
|
||||
PublicKey: base64.StdEncoding.EncodeToString(pubBytes),
|
||||
@@ -93,23 +92,22 @@ func (pr *PeerRecord) ExtractPeer(ourkey string, key string, pubKey crypto.PubKe
|
||||
NATSAddress: pr.NATSAddress,
|
||||
WalletAddress: pr.WalletAddress,
|
||||
}
|
||||
if time.Now().UTC().After(pr.ExpiryDate) { // is expired
|
||||
p.State = pp.OFFLINE // then is considers OFFLINE
|
||||
}
|
||||
b, err := json.Marshal(p)
|
||||
if err != nil {
|
||||
return pp.SELF == p.Relation, nil, err
|
||||
}
|
||||
fmt.Println("SENDPEER SELF")
|
||||
go tools.NewNATSCaller().SetNATSPub(tools.CREATE_PEER, tools.NATSResponse{
|
||||
FromApp: "oc-discovery",
|
||||
Datatype: tools.PEER,
|
||||
Method: int(tools.CREATE_PEER),
|
||||
Payload: b,
|
||||
})
|
||||
if p.State == pp.OFFLINE {
|
||||
|
||||
if time.Now().UTC().After(pr.ExpiryDate) {
|
||||
return pp.SELF == p.Relation, nil, errors.New("peer " + key + " is offline")
|
||||
}
|
||||
go tools.NewNATSCaller().SetNATSPub(tools.CREATE_RESOURCE, tools.NATSResponse{
|
||||
FromApp: "oc-discovery",
|
||||
Datatype: tools.PEER,
|
||||
Method: int(tools.CREATE_RESOURCE),
|
||||
SearchAttr: "peer_id",
|
||||
Payload: b,
|
||||
})
|
||||
|
||||
return pp.SELF == p.Relation, p, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -5,19 +5,17 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"oc-discovery/daemons/node/common"
|
||||
"oc-discovery/daemons/node/stream"
|
||||
|
||||
oclib "cloud.o-forge.io/core/oc-lib"
|
||||
"cloud.o-forge.io/core/oc-lib/config"
|
||||
"cloud.o-forge.io/core/oc-lib/models/peer"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
pp "github.com/libp2p/go-libp2p/core/peer"
|
||||
)
|
||||
|
||||
func ListenNATS(n *Node) {
|
||||
tools.NewNATSCaller().ListenNats(map[tools.NATSMethod]func(tools.NATSResponse){
|
||||
tools.VERIFY_RESOURCE: func(resp tools.NATSResponse) {
|
||||
/*tools.VERIFY_RESOURCE: func(resp tools.NATSResponse) {
|
||||
if resp.FromApp == config.GetAppName() {
|
||||
return
|
||||
}
|
||||
@@ -46,9 +44,9 @@ func ListenNATS(n *Node) {
|
||||
n.StreamService.PublishVerifyResources(&resp.Datatype, resp.User, realP.PeerID, resp.Payload)
|
||||
}
|
||||
}
|
||||
},
|
||||
tools.CREATE_PEER: func(resp tools.NATSResponse) {
|
||||
if resp.FromApp == config.GetAppName() {
|
||||
},*/
|
||||
tools.CREATE_RESOURCE: func(resp tools.NATSResponse) {
|
||||
if resp.FromApp == config.GetAppName() && resp.Datatype != tools.PEER {
|
||||
return
|
||||
}
|
||||
logger := oclib.GetLogger()
|
||||
@@ -68,10 +66,6 @@ func ListenNATS(n *Node) {
|
||||
n.StreamService.Mu.Lock()
|
||||
defer n.StreamService.Mu.Unlock()
|
||||
|
||||
n.Mu.Lock()
|
||||
n.Peers[ad.ID] = p.State == peer.ONLINE
|
||||
n.Mu.Unlock()
|
||||
|
||||
if p.Relation == peer.PARTNER {
|
||||
n.StreamService.ConnectToPartner(p.StreamAddress)
|
||||
} else {
|
||||
|
||||
@@ -33,8 +33,7 @@ type Node struct {
|
||||
PeerID pp.ID
|
||||
isIndexer bool
|
||||
|
||||
Mu sync.RWMutex
|
||||
Peers map[pp.ID]bool
|
||||
Mu sync.RWMutex
|
||||
}
|
||||
|
||||
func InitNode(isNode bool, isIndexer bool, isNativeIndexer bool) (*Node, error) {
|
||||
@@ -65,7 +64,6 @@ func InitNode(isNode bool, isIndexer bool, isNativeIndexer bool) (*Node, error)
|
||||
return nil, errors.New("no host no node")
|
||||
}
|
||||
node := &Node{
|
||||
Peers: map[pp.ID]bool{},
|
||||
PeerID: h.ID(),
|
||||
isIndexer: isIndexer,
|
||||
LongLivedStreamRecordedService: common.NewStreamRecordedService[interface{}](h, 1000, false),
|
||||
@@ -101,13 +99,6 @@ func InitNode(isNode bool, isIndexer bool, isNativeIndexer bool) (*Node, error)
|
||||
}
|
||||
}
|
||||
node.SubscribeToSearch(node.PS, &f)
|
||||
access := oclib.NewRequestAdmin(oclib.LibDataEnum(oclib.PEER), nil)
|
||||
peers := access.LoadAll(false)
|
||||
for _, p := range peers.Data { // fill cache.
|
||||
if pid, err := pp.Decode(p.(*peer.Peer).PeerID); err == nil {
|
||||
node.Peers[pid] = p.(*peer.Peer).State == peer.ONLINE
|
||||
}
|
||||
}
|
||||
}
|
||||
if isIndexer {
|
||||
logger.Info().Msg("generate opencloud indexer...")
|
||||
@@ -274,3 +265,19 @@ func (d *Node) claimInfo(
|
||||
return p, err
|
||||
//}
|
||||
}
|
||||
|
||||
/*
|
||||
TODO:
|
||||
- Le booking est un flow neuf décentralisé :
|
||||
On check on attend une réponse, on valide, il passe par discovery, on relais.
|
||||
- Le shared workspace est une affaire de décentralisation,
|
||||
on communique avec les shared les mouvements
|
||||
- Un shared remplace la notion de partnership à l'échelle de partnershipping
|
||||
-> quand on share un workspace on devient partenaire temporaire
|
||||
qu'on le soit originellement ou non.
|
||||
-> on a alors les mêmes privilèges.
|
||||
- Les orchestrations admiralty ont le même fonctionnement.
|
||||
Un evenement provoque alors une création de clé de service.
|
||||
|
||||
On doit pouvoir crud avec verification de signature un DBobject.
|
||||
*/
|
||||
|
||||
@@ -19,7 +19,7 @@ type Verify struct {
|
||||
|
||||
func (ps *StreamService) handleEvent(protocol string, evt *common.Event) error {
|
||||
ps.handleEventFromPartner(evt, protocol)
|
||||
if protocol == ProtocolVerifyResource {
|
||||
/*if protocol == ProtocolVerifyResource {
|
||||
if evt.DataType == -1 {
|
||||
tools.NewNATSCaller().SetNATSPub(tools.VERIFY_RESOURCE, tools.NATSResponse{
|
||||
FromApp: "oc-discovery",
|
||||
@@ -29,7 +29,7 @@ func (ps *StreamService) handleEvent(protocol string, evt *common.Event) error {
|
||||
} else if err := ps.verifyResponse(evt); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}*/
|
||||
if protocol == ProtocolSearchResource && evt.DataType > -1 {
|
||||
if err := ps.retrieveResponse(evt); err != nil {
|
||||
return err
|
||||
|
||||
@@ -169,7 +169,6 @@ func (s *StreamService) searchPeer(search string) ([]*peer.Peer, error) {
|
||||
},
|
||||
PeerID: ppID[len(ppID)-1],
|
||||
StreamAddress: peerID,
|
||||
State: peer.ONLINE,
|
||||
Relation: peer.PARTNER,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user