-/// `sync_path`: Path to the file where the gossip update data is located
-///
-pub fn sync_network_graph_with_file_path(
- network_graph: &network_graph::NetworkGraph,
- sync_path: &str,
-) -> Result<u32, GraphSyncError> {
- let mut file = File::open(sync_path)?;
- processing::update_network_graph_from_byte_stream(&network_graph, &mut file)
+/// [crate-level documentation]: crate
+pub struct RapidGossipSync<NG: Deref<Target=NetworkGraph<L>>, L: Deref>
+where L::Target: Logger {
+ network_graph: NG,
+ is_initial_sync_complete: AtomicBool
+}
+
+impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L::Target: Logger {
+ /// Instantiate a new [`RapidGossipSync`] instance
+ pub fn new(network_graph: NG) -> Self {
+ Self {
+ network_graph,
+ is_initial_sync_complete: AtomicBool::new(false)
+ }
+ }
+
+ /// Sync gossip data from a file
+ /// Returns the last sync timestamp to be used the next time rapid sync data is queried.
+ ///
+ /// `network_graph`: The network graph to apply the updates to
+ ///
+ /// `sync_path`: Path to the file where the gossip update data is located
+ ///
+ pub fn sync_network_graph_with_file_path(
+ &self,
+ sync_path: &str,
+ ) -> Result<u32, GraphSyncError> {
+ let mut file = File::open(sync_path)?;
+ self.update_network_graph_from_byte_stream(&mut file)
+ }
+
+ /// Gets a reference to the underlying [`NetworkGraph`] which was provided in
+ /// [`RapidGossipSync::new`].
+ ///
+ /// (C-not exported) as bindings don't support a reference-to-a-reference yet
+ pub fn network_graph(&self) -> &NG {
+ &self.network_graph
+ }
+
+ /// Returns whether a rapid gossip sync has completed at least once
+ pub fn is_initial_sync_complete(&self) -> bool {
+ self.is_initial_sync_complete.load(Ordering::Acquire)
+ }