Module peer_selector

Module peer_selector 

Source
Expand description

Intelligent peer selection combining geographic proximity and connection quality

This module provides a smart peer selector that combines multiple factors:

  • Geographic proximity (via geo_routing)
  • Connection quality prediction (via quality_predictor)
  • Network topology optimization

§Features

  • Multi-factor scoring: Combines distance, latency, bandwidth, reliability
  • Configurable weights: Adjust importance of each factor
  • Smart caching: Cache selection decisions to reduce overhead
  • Adaptive scoring: Learn from connection outcomes

§Example

use ipfrs_network::peer_selector::{PeerSelector, PeerSelectorConfig, SelectionCriteria};
use ipfrs_network::geo_routing::GeoLocation;
use libp2p::PeerId;

let config = PeerSelectorConfig::balanced();
let mut selector = PeerSelector::new(config);

// Add peer with location and quality metrics
let peer = PeerId::random();
selector.add_peer_location(peer, GeoLocation::new(40.7128, -74.0060));

// Select best peers based on criteria
let my_location = GeoLocation::new(37.7749, -122.4194);
let criteria = SelectionCriteria {
    reference_location: Some(my_location),
    min_quality_score: 0.5,
    max_distance_km: Some(5000.0),
    max_results: 10,
};

let selected = selector.select_peers(&criteria);
println!("Selected {} peers", selected.len());

Structs§

PeerSelector
Intelligent peer selector
PeerSelectorConfig
Configuration for peer selector
PeerSelectorStats
Statistics for peer selector
SelectedPeer
Selected peer with score details
SelectionCriteria
Criteria for peer selection