Skip to content

Commit

Permalink
feat(homeserver): add testnet option to config.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuhvi committed Aug 23, 2024
1 parent 190d384 commit 7eecfb3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pubky-homeserver/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const DEFAULT_STORAGE_DIR: &str = "pubky";
/// Server configuration
#[derive(Serialize, Deserialize, Clone)]
pub struct Config {
testnet: bool,
port: Option<u16>,
bootstrap: Option<Vec<String>>,
domain: String,
Expand All @@ -39,13 +40,23 @@ impl Config {
.with_context(|| format!("failed to read {}", path.as_ref().to_string_lossy()))?;

let config: Config = toml::from_str(&s)?;

if config.testnet {
let testnet_config = Config::testnet();

return Ok(Config {
bootstrap: testnet_config.bootstrap,
..config
});
}

Ok(config)
}

/// Testnet configurations
pub fn testnet() -> Self {
let testnet = pkarr::mainline::Testnet::new(10);
info!(?testnet.bootstrap, "Testnet Config");
info!(?testnet.bootstrap, "Testnet bootstrap nodes");

let bootstrap = Some(testnet.bootstrap.to_owned());
let storage = Some(
Expand Down Expand Up @@ -117,6 +128,7 @@ impl Config {
impl Default for Config {
fn default() -> Self {
Self {
testnet: false,
port: Some(0),
bootstrap: None,
domain: "localhost".to_string(),
Expand Down Expand Up @@ -152,6 +164,7 @@ where
impl Debug for Config {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_map()
.entry(&"testnet", &self.testnet)
.entry(&"port", &self.port())
.entry(&"storage", &self.storage())
.entry(&"public_key", &self.keypair().public_key())
Expand Down
2 changes: 2 additions & 0 deletions pubky-homeserver/src/config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Use testnet network (local DHT) for testing.
testnet = false
# Secret key (in hex) to generate the Homeserver's Keypair
secret_key = "0000000000000000000000000000000000000000000000000000000000000000"
# Domain to be published in Pkarr records for this server to be accessible by.
Expand Down

0 comments on commit 7eecfb3

Please sign in to comment.