mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-18 16:21:24 +01:00
include graphviz of state and auth events
This commit is contained in:
parent
052ab6dddd
commit
3afa1ccf8a
3 changed files with 25 additions and 1 deletions
|
|
@ -26,6 +26,9 @@ struct Value {
|
||||||
|
|
||||||
/// The edges in the state events' auth chains
|
/// The edges in the state events' auth chains
|
||||||
edges: BTreeSet<Edge>,
|
edges: BTreeSet<Edge>,
|
||||||
|
|
||||||
|
/// A graphviz representation of the resolved state and auth events
|
||||||
|
graphviz: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An edge in the graph of `auth_events` of the resolved state
|
/// An edge in the graph of `auth_events` of the resolved state
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ use std::{
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use petgraph::dot::Dot;
|
||||||
use ruma::{OwnedRoomId, RoomId};
|
use ruma::{OwnedRoomId, RoomId};
|
||||||
use tracing as t;
|
use tracing as t;
|
||||||
|
|
||||||
|
|
@ -132,9 +133,12 @@ async fn get_room_value(
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
let graphviz = Dot::new(&graph).to_string();
|
||||||
|
|
||||||
Some(Value {
|
Some(Value {
|
||||||
resolved_state,
|
resolved_state,
|
||||||
pdus,
|
pdus,
|
||||||
edges,
|
edges,
|
||||||
|
graphviz,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
use std::{
|
use std::{
|
||||||
collections::{BTreeMap, BTreeSet, HashMap, HashSet},
|
collections::{BTreeMap, BTreeSet, HashMap, HashSet},
|
||||||
error::Error,
|
error::Error,
|
||||||
|
fmt,
|
||||||
sync::{
|
sync::{
|
||||||
atomic::{AtomicUsize, Ordering},
|
atomic::{AtomicUsize, Ordering},
|
||||||
Arc,
|
Arc,
|
||||||
|
|
@ -10,6 +11,7 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use petgraph::{
|
use petgraph::{
|
||||||
|
dot::Dot,
|
||||||
graph::NodeIndex,
|
graph::NodeIndex,
|
||||||
visit::{depth_first_search, DfsEvent, Reversed},
|
visit::{depth_first_search, DfsEvent, Reversed},
|
||||||
Direction,
|
Direction,
|
||||||
|
|
@ -29,6 +31,12 @@ use crate::{database::KeyValueDatabase, utils, PduEvent};
|
||||||
/// A weightless unit type to use for graphs with unweighted edges
|
/// A weightless unit type to use for graphs with unweighted edges
|
||||||
pub(crate) struct WeightlessEdge;
|
pub(crate) struct WeightlessEdge;
|
||||||
|
|
||||||
|
impl fmt::Display for WeightlessEdge {
|
||||||
|
fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A directed graph with unweighted edges
|
/// A directed graph with unweighted edges
|
||||||
pub(crate) type DiGraph<T> = petgraph::graph::DiGraph<T, WeightlessEdge>;
|
pub(crate) type DiGraph<T> = petgraph::graph::DiGraph<T, WeightlessEdge>;
|
||||||
|
|
||||||
|
|
@ -40,7 +48,7 @@ struct ExtractRoomVersion {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Information about a state event node for state resolution
|
/// Information about a state event node for state resolution
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
pub(crate) struct StateResolutionNode {
|
pub(crate) struct StateResolutionNode {
|
||||||
/// This event's ID
|
/// This event's ID
|
||||||
pub(crate) event_id: Arc<EventId>,
|
pub(crate) event_id: Arc<EventId>,
|
||||||
|
|
@ -52,6 +60,12 @@ pub(crate) struct StateResolutionNode {
|
||||||
pub(crate) state_key: String,
|
pub(crate) state_key: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for StateResolutionNode {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
write!(f, "{self:#?}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Information about a state event's edges for state resolution
|
/// Information about a state event's edges for state resolution
|
||||||
pub(crate) struct StateResolutionEdges {
|
pub(crate) struct StateResolutionEdges {
|
||||||
/// This event's ID
|
/// This event's ID
|
||||||
|
|
@ -306,10 +320,13 @@ fn resolve_room_state(
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
let graphviz = Dot::new(&graph).to_string();
|
||||||
|
|
||||||
Some(Value {
|
Some(Value {
|
||||||
resolved_state,
|
resolved_state,
|
||||||
pdus,
|
pdus,
|
||||||
edges,
|
edges,
|
||||||
|
graphviz,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue