Configuration pour dev3.4nkweb.com - mise à jour des types de synchronisation
This commit is contained in:
parent
a4c2fd2090
commit
729120e7bc
285
src/network.rs
285
src/network.rs
@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize};
|
||||
use sp_client::bitcoin::hex::DisplayHex;
|
||||
use sp_client::bitcoin::OutPoint;
|
||||
use tsify::Tsify;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::error::AnkError;
|
||||
use crate::pcd::{Pcd, PcdCommitments, Roles};
|
||||
@ -68,6 +69,24 @@ impl AnkFlag {
|
||||
}
|
||||
}
|
||||
|
||||
impl SyncType {
|
||||
pub fn as_str(&self) -> &str {
|
||||
match self {
|
||||
Self::StateSync => "StateSync",
|
||||
Self::ProcessSync => "ProcessSync",
|
||||
Self::MemberSync => "MemberSync",
|
||||
Self::TxSync => "TxSync",
|
||||
Self::BlockSync => "BlockSync",
|
||||
Self::PeerSync => "PeerSync",
|
||||
Self::RelaySync => "RelaySync",
|
||||
Self::HealthSync => "HealthSync",
|
||||
Self::MetricsSync => "MetricsSync",
|
||||
Self::ConfigSync => "ConfigSync",
|
||||
Self::CapabilitySync => "CapabilitySync",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Message sent to the server to commit some state in a transaction
|
||||
/// Client must first send a commit message with empty validation_tokens
|
||||
/// Relay will ignore a commit message for an update he's not aware of that also bears validation_tokens
|
||||
@ -214,3 +233,269 @@ impl Envelope {
|
||||
serde_json::to_string(self).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
// ===== SYNC MESSAGES =====
|
||||
|
||||
/// Message de synchronisation pour le réseau mesh des relais
|
||||
#[derive(Debug, Serialize, Deserialize, Tsify)]
|
||||
#[tsify(into_wasm_abi, from_wasm_abi)]
|
||||
pub struct SyncMessage {
|
||||
pub sync_type: SyncType,
|
||||
pub relay_id: String, // Identifiant unique du relais
|
||||
pub timestamp: u64, // Timestamp de création
|
||||
pub sequence_number: u64, // Numéro de séquence pour l'ordre
|
||||
pub payload: SyncPayload, // Contenu de la synchronisation
|
||||
pub signature: Option<String>, // Signature du relais émetteur
|
||||
}
|
||||
|
||||
impl SyncMessage {
|
||||
pub fn new(sync_type: SyncType, relay_id: String, payload: SyncPayload) -> Self {
|
||||
Self {
|
||||
sync_type,
|
||||
relay_id,
|
||||
timestamp: std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_secs(),
|
||||
sequence_number: 0, // Sera incrémenté par le système
|
||||
payload,
|
||||
signature: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_string(&self) -> String {
|
||||
serde_json::to_string(self).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
/// Types de synchronisation
|
||||
#[derive(Debug, Serialize, Deserialize, Tsify)]
|
||||
#[tsify(into_wasm_abi, from_wasm_abi)]
|
||||
pub enum SyncType {
|
||||
// Synchronisation d'état
|
||||
StateSync, // Synchronisation de l'état global
|
||||
ProcessSync, // Synchronisation des processus
|
||||
MemberSync, // Synchronisation des membres
|
||||
|
||||
// Synchronisation de transactions
|
||||
TxSync, // Synchronisation des transactions
|
||||
BlockSync, // Synchronisation des blocs
|
||||
|
||||
// Synchronisation de réseau
|
||||
PeerSync, // Synchronisation des pairs
|
||||
RelaySync, // Synchronisation des relais
|
||||
|
||||
// Synchronisation de santé
|
||||
HealthSync, // État de santé du relais
|
||||
MetricsSync, // Métriques de performance
|
||||
|
||||
// Synchronisation de configuration
|
||||
ConfigSync, // Synchronisation de configuration
|
||||
CapabilitySync, // Synchronisation des capacités
|
||||
}
|
||||
|
||||
/// Contenu des messages de synchronisation
|
||||
#[derive(Debug, Serialize, Deserialize, Tsify)]
|
||||
#[tsify(into_wasm_abi, from_wasm_abi)]
|
||||
pub enum SyncPayload {
|
||||
// État global
|
||||
StateData {
|
||||
chain_tip: u32,
|
||||
wallet_balance: u64,
|
||||
active_processes: u32,
|
||||
connected_peers: u32,
|
||||
},
|
||||
|
||||
// Données de processus
|
||||
ProcessData {
|
||||
processes: OutPointProcessMap,
|
||||
last_update: u64,
|
||||
},
|
||||
|
||||
// Données de membres
|
||||
MemberData {
|
||||
members: OutPointMemberMap,
|
||||
last_update: u64,
|
||||
},
|
||||
|
||||
// Données de transactions
|
||||
TransactionData {
|
||||
txid: String,
|
||||
height: Option<u32>,
|
||||
confirmed: bool,
|
||||
sp_outputs: Vec<String>,
|
||||
},
|
||||
|
||||
// Données de bloc
|
||||
BlockData {
|
||||
height: u32,
|
||||
hash: String,
|
||||
timestamp: u64,
|
||||
tx_count: u32,
|
||||
},
|
||||
|
||||
// Données de pairs
|
||||
PeerData {
|
||||
peers: Vec<PeerInfo>,
|
||||
last_seen: u64,
|
||||
},
|
||||
|
||||
// Données de relais
|
||||
RelayData {
|
||||
relays: Vec<RelayInfo>,
|
||||
network_topology: NetworkTopology,
|
||||
},
|
||||
|
||||
// Données de santé
|
||||
HealthData {
|
||||
uptime: u64,
|
||||
memory_usage: u64,
|
||||
cpu_usage: f64,
|
||||
active_connections: u32,
|
||||
last_block_time: u64,
|
||||
},
|
||||
|
||||
// Données de métriques
|
||||
MetricsData {
|
||||
messages_processed: u64,
|
||||
transactions_broadcast: u64,
|
||||
blocks_scanned: u32,
|
||||
errors_count: u32,
|
||||
avg_response_time: f64,
|
||||
},
|
||||
|
||||
// Données de configuration
|
||||
ConfigData {
|
||||
config_hash: String,
|
||||
features: Vec<String>,
|
||||
version: String,
|
||||
},
|
||||
|
||||
// Données de capacités
|
||||
CapabilityData {
|
||||
capabilities: Vec<Capability>,
|
||||
supported_networks: Vec<String>,
|
||||
},
|
||||
}
|
||||
|
||||
/// Informations sur un pair
|
||||
#[derive(Debug, Serialize, Deserialize, Tsify)]
|
||||
#[tsify(into_wasm_abi, from_wasm_abi)]
|
||||
pub struct PeerInfo {
|
||||
pub address: String,
|
||||
pub sp_address: String,
|
||||
pub connected_since: u64,
|
||||
pub last_activity: u64,
|
||||
pub message_count: u64,
|
||||
pub capabilities: Vec<String>,
|
||||
}
|
||||
|
||||
/// Informations sur un relais
|
||||
#[derive(Debug, Serialize, Deserialize, Tsify)]
|
||||
#[tsify(into_wasm_abi, from_wasm_abi)]
|
||||
pub struct RelayInfo {
|
||||
pub relay_id: String,
|
||||
pub address: String,
|
||||
pub sp_address: String,
|
||||
pub version: String,
|
||||
pub uptime: u64,
|
||||
pub last_seen: u64,
|
||||
pub capabilities: Vec<String>,
|
||||
pub health_status: HealthStatus,
|
||||
}
|
||||
|
||||
/// Statut de santé d'un relais
|
||||
#[derive(Debug, Serialize, Deserialize, Tsify)]
|
||||
#[tsify(into_wasm_abi, from_wasm_abi)]
|
||||
pub enum HealthStatus {
|
||||
Healthy,
|
||||
Warning,
|
||||
Critical,
|
||||
Offline,
|
||||
}
|
||||
|
||||
/// Topologie du réseau
|
||||
#[derive(Debug, Serialize, Deserialize, Tsify)]
|
||||
#[tsify(into_wasm_abi, from_wasm_abi)]
|
||||
pub struct NetworkTopology {
|
||||
pub total_relays: u32,
|
||||
pub connected_relays: u32,
|
||||
pub mesh_connections: Vec<MeshConnection>,
|
||||
pub network_diameter: u32,
|
||||
pub avg_latency: f64,
|
||||
}
|
||||
|
||||
/// Connexion mesh entre relais
|
||||
#[derive(Debug, Serialize, Deserialize, Tsify)]
|
||||
#[tsify(into_wasm_abi, from_wasm_abi)]
|
||||
pub struct MeshConnection {
|
||||
pub from_relay: String,
|
||||
pub to_relay: String,
|
||||
pub latency: f64,
|
||||
pub bandwidth: u64,
|
||||
pub last_heartbeat: u64,
|
||||
}
|
||||
|
||||
/// Capacité d'un relais
|
||||
#[derive(Debug, Serialize, Deserialize, Tsify)]
|
||||
#[tsify(into_wasm_abi, from_wasm_abi)]
|
||||
pub struct Capability {
|
||||
pub name: String,
|
||||
pub version: String,
|
||||
pub enabled: bool,
|
||||
pub parameters: HashMap<String, String>,
|
||||
}
|
||||
|
||||
/// Requête de synchronisation
|
||||
#[derive(Debug, Serialize, Deserialize, Tsify)]
|
||||
#[tsify(into_wasm_abi, from_wasm_abi)]
|
||||
pub struct SyncRequest {
|
||||
pub request_id: String,
|
||||
pub relay_id: String,
|
||||
pub sync_types: Vec<SyncType>,
|
||||
pub since_timestamp: Option<u64>,
|
||||
pub max_items: Option<u32>,
|
||||
}
|
||||
|
||||
impl SyncRequest {
|
||||
pub fn new(request_id: String, relay_id: String, sync_types: Vec<SyncType>) -> Self {
|
||||
Self {
|
||||
request_id,
|
||||
relay_id,
|
||||
sync_types,
|
||||
since_timestamp: None,
|
||||
max_items: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_string(&self) -> String {
|
||||
serde_json::to_string(self).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
/// Réponse de synchronisation
|
||||
#[derive(Debug, Serialize, Deserialize, Tsify)]
|
||||
#[tsify(into_wasm_abi, from_wasm_abi)]
|
||||
pub struct SyncResponse {
|
||||
pub request_id: String,
|
||||
pub relay_id: String,
|
||||
pub success: bool,
|
||||
pub messages: Vec<SyncMessage>,
|
||||
pub error: Option<String>,
|
||||
}
|
||||
|
||||
impl SyncResponse {
|
||||
pub fn new(request_id: String, relay_id: String, success: bool) -> Self {
|
||||
Self {
|
||||
request_id,
|
||||
relay_id,
|
||||
success,
|
||||
messages: Vec::new(),
|
||||
error: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_string(&self) -> String {
|
||||
serde_json::to_string(self).unwrap()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user