-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
78ece46
commit 0cfa379
Showing
22 changed files
with
3,927 additions
and
309 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[package] | ||
name = "atoma-p2p" | ||
version.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
|
||
[dependencies] | ||
blake3 = { workspace = true } | ||
ciborium = { workspace = true } | ||
config = { workspace = true } | ||
libp2p = { workspace = true, features = [ "tokio", "identify", "gossipsub", "mdns", "kad", "noise", "macros", "tcp", "yamux", "quic"] } | ||
fastcrypto = { workspace = true } | ||
flume = { workspace = true } | ||
futures = { workspace = true } | ||
serde = { workspace = true, features = ["derive"] } | ||
sui-keys = { workspace = true } | ||
sui-sdk = { workspace = true } | ||
thiserror = { workspace = true } | ||
tokio = { workspace = true, features = ["full"] } | ||
tracing = { workspace = true } | ||
url = { workspace = true } | ||
|
||
[dev-dependencies] | ||
rand = { workspace = true } | ||
tempfile = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
use config::{Config, File}; | ||
use serde::{Deserialize, Serialize}; | ||
use std::path::Path; | ||
use std::time::Duration; | ||
|
||
/// Configuration settings for a P2P Atoma Node. | ||
/// | ||
/// This struct holds timing-related configuration parameters that control | ||
/// the behavior of peer-to-peer connections in an Atoma node. | ||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub struct AtomaP2pNodeConfig { | ||
/// Country of origin of the node | ||
pub country: String, | ||
|
||
/// The interval at which heartbeat messages are sent to peers. | ||
/// | ||
/// Heartbeats are used to verify that connections are still alive and | ||
/// to maintain the connection state with peers. | ||
pub heartbeat_interval: Duration, | ||
|
||
/// The maximum duration a connection can remain idle before it is closed. | ||
/// | ||
/// If no messages are exchanged within this duration, the connection | ||
/// will be terminated to free up resources. | ||
pub idle_connection_timeout: Duration, | ||
|
||
/// The address to listen on for incoming tcp connections. | ||
/// | ||
/// This is the address that the node will use to listen for incoming connections. | ||
/// It is a string in the format of "/ip4/x.x.x.x/tcp/x". | ||
pub listen_addr: String, | ||
|
||
/// The public URL of the node. | ||
/// | ||
/// This is the URL that the node will use to send requests to the network. | ||
/// It is a string in the format of "https://x.x.x.x:x". | ||
pub public_url: String, | ||
|
||
/// The node's small id (assigned by the Atoma smart contract) | ||
pub node_small_id: u64, | ||
|
||
/// The list of bootstrap nodes to connect to. | ||
/// | ||
/// Bootstrap nodes are nodes that the node will use to bootstrap its network connection. | ||
/// They are a list of strings in the format of "/ip4/x.x.x.x/tcp/x". | ||
pub bootstrap_nodes: Vec<String>, | ||
} | ||
|
||
impl AtomaP2pNodeConfig { | ||
/// Creates a new `AtomaP2pNodeConfig` instance from a configuration file. | ||
/// | ||
/// This method loads configuration settings from both a file and environment variables: | ||
/// - File: Reads the specified configuration file | ||
/// - Environment: Reads variables prefixed with `ATOMA_P2P__` | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `config_file_path` - Path to the configuration file | ||
/// | ||
/// # Returns | ||
/// | ||
/// Returns a new `AtomaP2pNodeConfig` instance with the loaded configuration. | ||
/// | ||
/// # Panics | ||
/// | ||
/// This method will panic if: | ||
/// - The configuration file cannot be read or parsed | ||
/// - Required configuration values are missing | ||
/// - The configuration format is invalid | ||
/// | ||
/// # Example | ||
/// | ||
/// ```rust,ignore | ||
/// use atoma_p2p::config::AtomaP2pNodeConfig; | ||
/// | ||
/// let config = AtomaP2pNodeConfig::from_file_path("config/atoma.toml"); | ||
/// ``` | ||
pub fn from_file_path<P: AsRef<Path>>(config_file_path: P) -> Self { | ||
let builder = Config::builder() | ||
.add_source(File::with_name(config_file_path.as_ref().to_str().unwrap())) | ||
.add_source( | ||
config::Environment::with_prefix("ATOMA_P2P") | ||
.keep_prefix(true) | ||
.separator("__"), | ||
); | ||
let config = builder | ||
.build() | ||
.expect("Failed to generate atoma-p2p configuration file"); | ||
config | ||
.get::<Self>("atoma_p2p") | ||
.expect("Failed to generate configuration instance") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
pub mod config; | ||
pub mod service; | ||
pub mod timer; | ||
pub mod types; | ||
|
||
pub use config::AtomaP2pNodeConfig; | ||
pub use service::AtomaP2pNode; | ||
pub use types::AtomaP2pEvent; |
Oops, something went wrong.