changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > core / rust/lib/obj/src/config/network.rs

changeset 698: 96958d3eb5b0
parent: 0ccbbd142694
author: Richard Westhaver <ellis@rwest.io>
date: Fri, 04 Oct 2024 22:04:59 -0400
permissions: -rw-r--r--
description: fixes
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  Raw,
42 }
43 
44 impl Default for EngineType {
45  fn default() -> Self {
46  Self::Raw
47  }
48 }
49 
50 impl std::fmt::Display for EngineType {
51  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
52  match self {
53  EngineType::Quic => write!(f, "quic"),
54  EngineType::Http => write!(f, "http"),
55  EngineType::Dns => write!(f, "dns"),
56  EngineType::Ssh => write!(f, "ssh"),
57  EngineType::Uds => write!(f, "uds"),
58  EngineType::Raw => write!(f, "raw"),
59  }
60  }
61 }