defaults.rs
Overview
This file defines a collection of constant values used as default configuration parameters related to network communication within the system. These constants primarily specify default URL paths, protocols, ports, and timeout durations for API requests or messaging endpoints. The values serve as standardized defaults across the application, ensuring consistency and simplifying configuration management.
Constants
DEFAULT_NODE_URL_PATH: &str
Type:
&str(string slice)Description: Represents the default URL path appended to the node's base URL for accessing messaging endpoints.
Value: "/v2/messages"
Usage: Used when constructing HTTP requests to nodes, this path targets the version 2 messages endpoint.
Example:
let full_url = format!("{}{}", node_base_url, DEFAULT_NODE_URL_PATH); // full_url might be "http://node.example.com/v2/messages"
DEFAULT_NODE_URL_PROTO: &str (crate-private)
Type:
&strVisibility:
pub(crate)(accessible within the current crate)Description: Defines the default protocol to use when connecting to a node.
Value:
"http"Usage: Used as the default scheme in URL construction when no specific protocol is provided.
Example:
let url = format!("{}://{}{}", DEFAULT_NODE_URL_PROTO, host, DEFAULT_NODE_URL_PATH);
DEFAULT_NODE_URL_PORT: u16
Type:
u16(unsigned 16-bit integer)Description: Specifies the default port number for node connections.
Value:
8600Usage: Used as the default port when establishing connections to nodes.
Example:
let socket_addr = format!("{}:{}", host, DEFAULT_NODE_URL_PORT);
DEFAULT_URL_PATH: &str
Type:
&strDescription: Represents a default URL path for a different messaging API endpoint.
Value:
"/bm/v2/messages"Usage: Used in contexts where the "bm" (possibly "benchmark" or another subsystem) API endpoint is targeted.
Example:
let bm_url = format!("{}{}", base_url, DEFAULT_URL_PATH);
DEFAULT_BK_API_TIMEOUT: u64 (crate-private)
Type:
u64(64-bit unsigned integer)Visibility:
pub(crate)Description: Default timeout duration for the BK API in seconds.
Value:
5Usage: Used to determine how long the system should wait for a response from the BK API before timing out.
Example:
let timeout = Duration::from_secs(DEFAULT_BK_API_TIMEOUT);
Implementation Details
All constants are immutable and static, enabling compile-time assignment and efficient reuse.
Constants use Rust's built-in types for strings and numeric values.
The use of
pub(crate)visibility modifier restricts access of some constants to the crate scope only, enhancing encapsulation and preventing external misuse.These defaults help reduce hard-coded literals throughout the codebase, improving maintainability and enabling centralized configuration changes.
The naming convention clearly distinguishes between node-specific settings (
DEFAULT_NODE_*) and more general or subsystem-specific defaults (DEFAULT_URL_PATH,DEFAULT_BK_API_TIMEOUT).
Interaction with the System
These constants are utilized by networking modules responsible for constructing HTTP requests to nodes or APIs.
They provide fallback values when explicit configuration parameters are not specified.
Modules that perform message dispatching or API communication reference these constants to ensure correct and consistent endpoints and protocols.
Timeout constant is likely used in asynchronous request handling or client configuration to avoid indefinite waiting periods.
This file acts as a foundational configuration layer supporting higher-level networking and messaging logic.
Diagram
flowchart TD
A[defaults.rs] --> B[DEFAULT_NODE_URL_PATH]
A --> C[DEFAULT_NODE_URL_PROTO]
A --> D[DEFAULT_NODE_URL_PORT]
A --> E[DEFAULT_URL_PATH]
A --> F[DEFAULT_BK_API_TIMEOUT]
B --> G[Used in constructing node URLs]
C --> G
D --> G
E --> H[Used in BM API endpoint URLs]
F --> I[Used for BK API request timeout]
This diagram illustrates the constants defined in the file and their primary usage contexts within the system.