#p2p #peer-to-peer #networking

spectre

A lightweight toolkit for analysing p2p network topologies

7 releases (4 breaking)

0.5.2 Jan 23, 2023
0.5.1 Jan 23, 2023
0.4.0 May 22, 2022
0.3.0 Mar 10, 2022
0.1.0 Feb 7, 2022

#271 in Algorithms

Download history 10/week @ 2022-10-12 50/week @ 2022-10-19 75/week @ 2022-10-26 79/week @ 2022-11-02 64/week @ 2022-11-09 67/week @ 2022-11-16 72/week @ 2022-11-23 67/week @ 2022-11-30 75/week @ 2022-12-07 64/week @ 2022-12-14 47/week @ 2022-12-21 44/week @ 2022-12-28 43/week @ 2023-01-04 35/week @ 2023-01-11 106/week @ 2023-01-18 103/week @ 2023-01-25

294 downloads per month

MIT license

54KB
913 lines

Spectre

crates.io docs.rs

In French, the spectrum of a matrix is called "spectre".

This micro-library contains a small toolkit helpful in analysing network topologies. Namely:

  • Degree, adjacency and Laplacian matrices for a graph.
  • Various centrality measures for a graph.
  • The algebraic connectivity of a graph (Fiedler).

Basic usage

The library is centered around the Graph structure which can be constructed from one or more Edge instances. Once constructed, various measurements and matrix representations of the graph can be computed.

use std::net::SocketAddr;

use spectre::edge::Edge;
use spectre::graph::Graph;

// Construct the graph instance.
let mut graph = Graph::new();

// Create some addresses to be part of a network topology.
let addrs: Vec<SocketAddr> = (0..3)
    .map(|i| format!("127.0.0.1:{i}").parse().unwrap())
    .collect();
let (a, b, c) = (addrs[0], addrs[1], addrs[2]);

// Insert some edges, note the IDs can be any type that is `Copy + Eq + Hash + Ord`.
graph.insert(Edge::new(a, b));
graph.insert(Edge::new(a, c));

// Compute some metrics on that state of the graph.
let density = graph.density();
let degree_centrality_delta = graph.degree_centrality_delta();

// Matrices can be pretty printed...
println!("{}", graph.laplacian_matrix());
// ...outputs:
//  ┌          ┐
//  │  2 -1 -1 │
//  │ -1  1  0 │
//  │ -1  0  1 │
//  └          ┘

Dependencies

~3MB
~57K SLoC