lumina_node_wasm/wrapper/
libp2p.rs1use libp2p::swarm::{
2 ConnectionCounters as SwarmConnectionCounters, NetworkInfo as SwarmNetworkInfo,
3};
4use serde::{Deserialize, Serialize};
5use wasm_bindgen::prelude::*;
6
7#[wasm_bindgen(inspectable)]
8#[derive(Debug, Serialize, Deserialize)]
9pub struct NetworkInfoSnapshot {
11 pub num_peers: usize,
13 pub connection_counters: ConnectionCountersSnapshot,
15}
16
17#[wasm_bindgen(inspectable)]
19#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
20pub struct ConnectionCountersSnapshot {
21 pub num_connections: u32,
23 pub num_pending: u32,
25 pub num_pending_incoming: u32,
27 pub num_pending_outgoing: u32,
29 pub num_established: u32,
31 pub num_established_incoming: u32,
33 pub num_established_outgoing: u32,
35}
36
37impl From<SwarmNetworkInfo> for NetworkInfoSnapshot {
38 fn from(info: SwarmNetworkInfo) -> Self {
39 Self {
40 num_peers: info.num_peers(),
41 connection_counters: ConnectionCountersSnapshot::from(info.connection_counters()),
42 }
43 }
44}
45
46impl From<&SwarmConnectionCounters> for ConnectionCountersSnapshot {
47 fn from(counters: &SwarmConnectionCounters) -> Self {
48 Self {
49 num_connections: counters.num_connections(),
50 num_pending: counters.num_pending(),
51 num_pending_incoming: counters.num_pending_incoming(),
52 num_pending_outgoing: counters.num_pending_outgoing(),
53 num_established: counters.num_established(),
54 num_established_incoming: counters.num_established_incoming(),
55 num_established_outgoing: counters.num_established_outgoing(),
56 }
57 }
58}