changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > demo / obj/src/network.rs

changeset 11: d8f806f1d327
author: ellis <ellis@rwest.io>
date: Sun, 14 May 2023 21:27:04 -0400
permissions: -rw-r--r--
description: obj updates
1 //! cfg::config::network
2 //!
3 //! Network configuration primitives
4 use serde::{Deserialize, Serialize};
5 use std::{fmt, net::SocketAddr};
6 
7 /// Network configuration
8 #[derive(Serialize, Deserialize, Hash, Debug, PartialEq, Clone)]
9 pub struct NetworkConfig {
10  /// a socket to bind
11  pub socket: SocketAddr,
12  /// a proxy to forward packets from
13  pub proxy: Option<SocketAddr>,
14  /// tunnel to use
15  pub tunnel: Option<String>,
16  /// network engine to attach
17  pub engine: EngineType,
18  /// peers to register AOT
19  pub peers: Option<Vec<SocketAddr>>,
20 }
21 
22 impl Default for NetworkConfig {
23  fn default() -> Self {
24  NetworkConfig {
25  socket: "127.0.0.1:0".parse().unwrap(),
26  proxy: None,
27  tunnel: None,
28  engine: EngineType::default(),
29  peers: None,
30  }
31  }
32 }
33 
34 #[derive(Serialize, Deserialize, Hash, Debug, PartialEq, Clone)]
35 pub enum EngineType {
36  Quic,
37  Http,
38  Dns,
39  Ssh,
40  Uds,
41 }
42 
43 impl Default for EngineType {
44  fn default() -> Self {
45  Self::Http
46  }
47 }
48 
49 impl std::fmt::Display for EngineType {
50  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
51  match self {
52  EngineType::Quic => write!(f, "quic"),
53  EngineType::Http => write!(f, "http"),
54  EngineType::Dns => write!(f, "dns"),
55  EngineType::Ssh => write!(f, "ssh"),
56  EngineType::Uds => write!(f, "uds"),
57  }
58  }
59 }