mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-05-17 21:31:20 +00:00
Moves https://github.com/mxinden/rust-libp2p-server to the rust-libp2p monorepository. > # Rust libp2p Server > > A rust-libp2p based server implementation running: > > - the [Kademlia protocol](https://github.com/libp2p/specs/tree/master/kad-dht) > > - the [Circuit Relay v2 protocol](https://github.com/libp2p/specs/blob/master/relay/circuit-v2.md) > > - the [AutoNAT protocol](https://github.com/libp2p/specs/blob/master/autonat/README.md) Pull-Request: #4311.
40 lines
966 B
Rust
40 lines
966 B
Rust
use libp2p::Multiaddr;
|
|
use serde_derive::Deserialize;
|
|
use std::error::Error;
|
|
use std::path::Path;
|
|
|
|
#[derive(Clone, Deserialize)]
|
|
#[serde(rename_all = "PascalCase")]
|
|
pub(crate) struct Config {
|
|
pub(crate) identity: Identity,
|
|
pub(crate) addresses: Addresses,
|
|
}
|
|
|
|
impl Config {
|
|
pub(crate) fn from_file(path: &Path) -> Result<Self, Box<dyn Error>> {
|
|
Ok(serde_json::from_str(&std::fs::read_to_string(path)?)?)
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Deserialize)]
|
|
#[serde(rename_all = "PascalCase")]
|
|
pub(crate) struct Identity {
|
|
#[serde(rename = "PeerID")]
|
|
pub(crate) peer_id: String,
|
|
pub(crate) priv_key: String,
|
|
}
|
|
|
|
#[derive(Clone, Deserialize)]
|
|
#[serde(rename_all = "PascalCase")]
|
|
pub(crate) struct Addresses {
|
|
pub(crate) swarm: Vec<Multiaddr>,
|
|
pub(crate) append_announce: Vec<Multiaddr>,
|
|
}
|
|
|
|
impl zeroize::Zeroize for Config {
|
|
fn zeroize(&mut self) {
|
|
self.identity.peer_id.zeroize();
|
|
self.identity.priv_key.zeroize();
|
|
}
|
|
}
|