1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//! Configure the transports for of your [`Ditto`] instance.

use_prelude!();

use tracing::debug;

pub(crate) mod connection_request_handler;
pub(crate) mod presence;
pub(crate) mod presence_observer;
pub(crate) mod sync;
pub(crate) mod sync_state;
pub(crate) mod transport_config;
pub(crate) mod v2;
pub(crate) mod v3;

pub use presence::Presence;
pub use presence_observer::PresenceObserver;
pub use sync::TransportSync;
pub use transport_config::{
    BluetoothLEConfig, Connect, Global, HttpListenConfig, LanConfig, Listen, PeerToPeer,
    TcpListenConfig, TransportConfig,
};
#[doc(hidden)]
#[allow(deprecated)]
pub use v3::ConnectionType as V3ConnectionType;
pub use v3::{Connection, Peer, PresenceGraph, PresenceOs};

/// Defines a simplified connection type between peers for reporting presence
/// info.
///
/// These connections indicate P2P connections _only_. A connection to the Big Peer
/// is recorded by a simple boolean flag on the [`Peer`] type.
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum ConnectionType {
    Bluetooth,
    AccessPoint,
    P2PWiFi,
    WebSocket,
    #[doc(hidden)]
    Unknown,
}

impl ConnectionType {
    fn from_ffi(ffi: ::ffi_sdk::ConnectionType) -> Self {
        match ffi {
            ::ffi_sdk::ConnectionType::Bluetooth => Self::Bluetooth,
            ::ffi_sdk::ConnectionType::AccessPoint => Self::AccessPoint,
            ::ffi_sdk::ConnectionType::P2PWiFi => Self::P2PWiFi,
            ::ffi_sdk::ConnectionType::WebSocket => Self::WebSocket,
            #[allow(unreachable_patterns)]
            _ => {
                debug!(connection_type = ?ffi, "got unknown `ConnectionType`");
                Self::Unknown
            }
        }
    }
}