pub struct DAGSyncer<S: DAGStore> {
store: S,
config: SyncConfig,
}Expand description
DAG synchronizer for gap-repair and reconciliation.
The syncer uses a pull-based approach:
- Compare heads with a peer
- Identify missing nodes
- Fetch missing nodes recursively until reaching common ancestors
Fields§
§store: SThe local DAG store.
config: SyncConfigConfiguration.
Implementations§
Source§impl<S: DAGStore> DAGSyncer<S>
impl<S: DAGStore> DAGSyncer<S>
Sourcepub fn with_config(store: S, config: SyncConfig) -> Self
pub fn with_config(store: S, config: SyncConfig) -> Self
Create a syncer with custom configuration.
Sourcepub fn need(&self, cids: &[Hash]) -> Vec<Hash>
pub fn need(&self, cids: &[Hash]) -> Vec<Hash>
Determine which of the given CIDs we need (don’t have locally).
Sourcepub fn create_request(&self, peer_heads: &[Hash]) -> SyncRequest
pub fn create_request(&self, peer_heads: &[Hash]) -> SyncRequest
Create a sync request for reconciliation with a peer.
Sourcepub fn handle_request(&self, request: &SyncRequest) -> SyncResponse
pub fn handle_request(&self, request: &SyncRequest) -> SyncResponse
Handle an incoming sync request from a peer.
Sourcepub fn apply_response(
&mut self,
response: SyncResponse,
) -> Result<Vec<Hash>, SyncError>
pub fn apply_response( &mut self, response: SyncResponse, ) -> Result<Vec<Hash>, SyncError>
Apply a sync response, storing received nodes.
Returns the CIDs of successfully stored nodes.
Sourcepub fn apply_nodes_unchecked(
&mut self,
nodes: Vec<MerkleNode>,
) -> Result<Vec<Hash>, SyncError>
pub fn apply_nodes_unchecked( &mut self, nodes: Vec<MerkleNode>, ) -> Result<Vec<Hash>, SyncError>
Apply nodes without strict parent checking.
Used when nodes may arrive out of order.
Sourcefn collect_known(&self, heads: &[Hash]) -> HashSet<Hash>
fn collect_known(&self, heads: &[Hash]) -> HashSet<Hash>
Collect all CIDs reachable from the given heads (including the heads).
Sourcepub fn find_missing_ancestors(&self, cids: &[Hash]) -> Vec<Hash>
pub fn find_missing_ancestors(&self, cids: &[Hash]) -> Vec<Hash>
Find the missing ancestors of the given CIDs.
This performs gap detection by traversing backwards from the given CIDs and identifying nodes that aren’t in our store.
Sourcepub fn is_synced_with(&self, peer_heads: &[Hash]) -> bool
pub fn is_synced_with(&self, peer_heads: &[Hash]) -> bool
Check if we’re synchronized with a peer (have all their nodes).
Sourcepub fn sync_status(&self) -> SyncStatus
pub fn sync_status(&self) -> SyncStatus
Get statistics about sync status.