ouisync/network/
peer_source.rs1use num_enum::{IntoPrimitive, TryFromPrimitive};
2use ouisync_macros::api;
3use serde::{Deserialize, Serialize};
4use std::fmt;
5
6#[derive(
8 Clone,
9 Copy,
10 Debug,
11 Eq,
12 PartialEq,
13 Ord,
14 PartialOrd,
15 Serialize,
16 Deserialize,
17 IntoPrimitive,
18 TryFromPrimitive,
19)]
20#[repr(u8)]
21#[serde(into = "u8", try_from = "u8")]
22#[api]
23pub enum PeerSource {
24 UserProvided = 0,
26 Listener = 1,
28 LocalDiscovery = 2,
30 Dht = 3,
32 PeerExchange = 4,
34}
35
36impl fmt::Display for PeerSource {
37 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
38 match self {
39 PeerSource::Listener => write!(f, "incoming"),
40 PeerSource::UserProvided => write!(f, "outgoing (user provided)"),
41 PeerSource::LocalDiscovery => write!(f, "outgoing (locally discovered)"),
42 PeerSource::Dht => write!(f, "outgoing (found on DHT)"),
43 PeerSource::PeerExchange => write!(f, "outgoing (found on peer exchange)"),
44 }
45 }
46}