File size: 1,177 Bytes
c01b922 5e41c19 c01b922 5e41c19 c01b922 5e41c19 c01b922 5e41c19 c01b922 5e41c19 c01b922 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | """
Federation Node : squelette minimal pour un réseau de Spaces ATYPIK.
"""
import json
from typing import Dict, Any, List
class FederationNode:
def __init__(self, node_id: str = "node-001"):
self.node_id = node_id
self.peers: List[str] = []
self.pending_proposals: List[Dict[str, Any]] = []
def register_peer(self, peer_url: str):
if peer_url and peer_url not in self.peers:
self.peers.append(peer_url)
def propose_patch(self, instance_id: str, patch: str, review_score: float):
proposal = {
"node_id": self.node_id,
"instance_id": instance_id,
"patch": patch[:500] + "..." if len(patch) > 500 else patch,
"review_score": review_score,
"votes": 0
}
self.pending_proposals.append(proposal)
def get_consensus_patches(self, threshold: int = 1) -> List[Dict[str, Any]]:
return [p for p in self.pending_proposals if p["votes"] >= threshold]
_federation = None
def get_federation(node_id="node-001"):
global _federation
if _federation is None:
_federation = FederationNode(node_id)
return _federation |