refactor: extract node runtime state
This commit is contained in:
parent
cad4bc0e74
commit
87fe47fd7f
3 changed files with 91 additions and 72 deletions
|
|
@ -1,3 +1,4 @@
|
|||
mod runtime;
|
||||
pub mod service;
|
||||
|
||||
use base64::Engine;
|
||||
|
|
@ -54,7 +55,11 @@ use geth_types::{
|
|||
};
|
||||
use iroh::protocol::ProtocolHandler;
|
||||
use iroh_docs::api::protocol::{AddrInfoOptions, ShareMode};
|
||||
use std::collections::{BTreeMap, BTreeSet, VecDeque};
|
||||
use runtime::{
|
||||
KvDocsState, LiveSyncCursor, LiveSyncHealth, NodeRuntime, OverlayTunCounters,
|
||||
OverlayTunRuntime, PipeRuntime, PubsubGossipTopicRuntime, PubsubRuntime,
|
||||
};
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::path::{Component, Path, PathBuf};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Duration;
|
||||
|
|
@ -178,79 +183,11 @@ pub struct LocalNode {
|
|||
runtime: Arc<NodeRuntime>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct NodeRuntime {
|
||||
pubsub: Mutex<PubsubRuntime>,
|
||||
pipes: Mutex<PipeRuntime>,
|
||||
overlays: Mutex<BTreeMap<String, OverlayTunRuntime>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
struct PubsubRuntime {
|
||||
messages: VecDeque<PubsubMessage>,
|
||||
gossip_topics: BTreeMap<String, PubsubGossipTopicRuntime>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct PubsubGossipTopicRuntime {
|
||||
sender: iroh_gossip::api::GossipSender,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
struct PipeRuntime {
|
||||
listeners: BTreeMap<String, PipeListener>,
|
||||
connections: VecDeque<PipeConnection>,
|
||||
messages: VecDeque<PipeMessage>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct OverlayTunRuntime {
|
||||
name: String,
|
||||
interface_name: String,
|
||||
virtual_ip: String,
|
||||
cidr: String,
|
||||
mtu: u16,
|
||||
started_at_ms: i64,
|
||||
inject_tx: mpsc::Sender<Vec<u8>>,
|
||||
stop_tx: Option<oneshot::Sender<()>>,
|
||||
counters: Arc<Mutex<OverlayTunCounters>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
struct OverlayTunCounters {
|
||||
packets_from_tun: u64,
|
||||
packets_to_tun: u64,
|
||||
packets_to_peers: u64,
|
||||
last_error: Option<String>,
|
||||
}
|
||||
|
||||
const PUBSUB_RING_LIMIT: usize = 256;
|
||||
const PIPE_CONNECTION_RING_LIMIT: usize = 256;
|
||||
const PIPE_MESSAGE_RING_LIMIT: usize = 1024;
|
||||
const LIVE_SYNC_STALE_AFTER_MS: i64 = 120_000;
|
||||
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||
struct LiveSyncCursor {
|
||||
cursor_ms: i64,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||
struct LiveSyncHealth {
|
||||
last_attempt_ms: i64,
|
||||
last_success_ms: Option<i64>,
|
||||
last_error: Option<String>,
|
||||
last_imported: usize,
|
||||
last_rejected: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||
struct KvDocsState {
|
||||
name: String,
|
||||
namespace_id: String,
|
||||
read_ticket: String,
|
||||
updated_at_ms: i64,
|
||||
}
|
||||
|
||||
struct PipeTcpConnectWire {
|
||||
peer_card: PeerCard,
|
||||
target_addr: String,
|
||||
|
|
|
|||
Loading…
Reference in a new issue