config.rs

Overview

This file defines the configuration management for a proxy service component. It primarily focuses on loading, saving, and handling dynamic reloading of proxy configurations, as well as providing conversion to network-specific configuration structures. The ProxyConfig struct encapsulates all relevant configuration parameters such as network bindings, cryptographic certificates, peer addresses, and gossip protocol settings. The file also includes asynchronous signal handling for runtime configuration reloads triggered by Unix SIGHUP signals.

Detailed Components

Struct: ProxyConfig

Represents the main configuration for the proxy service.

Fields

Methods

Function: default_broadcast_buffer_len() -> usize

Returns the default value for the broadcast buffer length, which is 2000.

Async Function: config_reload_handler

pub(crate) async fn config_reload_handler(
    config_updates: tokio::sync::watch::Sender<ProxyConfig>,
    config_path: PathBuf,
) -> anyhow::Result<()>

Parameters:

Usage:

This function is intended to be run in a Tokio runtime environment to enable hot-reloading of proxy configurations without restarting the service.

Module: addr_serde

Custom serialization and deserialization helpers for handling Option<Vec<SocketAddr>> types that may be represented as either a single address or a list of addresses in the configuration YAML.

Test Module

Contains a basic test verifying that the configuration file at config.yaml (in the project directory) can be successfully loaded into a ProxyConfig instance.

#[test]
fn config_file_match_test() {
    let config_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("config.yaml");
    _ = ProxyConfig::from_file(config_path).unwrap();
}

Important Implementation Details

Interaction with Other System Components


Diagram: ProxyConfig Structure and Workflow

classDiagram
class ProxyConfig {
+bind: SocketAddr
+gossip: GossipConfig
+my_addr: Option<Vec<SocketAddr>>
+my_cert: CertFile
+my_key: PrivateKeyFile
+peer_certs: CertStore
+peer_ed_pubkeys: Vec<VerifyingKey>
+bk_addrs: Vec<SocketAddr>
+subscribe: Vec<Vec<SocketAddr>>
+broadcast_buffer_len: usize
+from_file()
+save()
+network_config()
}
class addr_serde {
+opt_vec_deser()
+opt_vec_ser()
}
class config_reload_handler {
+async run()
}
ProxyConfig ..> GossipConfig : uses
ProxyConfig ..> CertFile : contains
ProxyConfig ..> PrivateKeyFile : contains
ProxyConfig ..> CertStore : contains
ProxyConfig ..> VerifyingKey : contains
ProxyConfig ..> NetworkConfig : converts to
config_reload_handler ..> ProxyConfig : reloads config
ProxyConfig ..> addr_serde : serialization helpers

This diagram illustrates the key entities in this file, their primary fields and methods, and the relationships between them, highlighting how configuration data flows from file to runtime usage and reload handling.