Files
pubky-core/pubky-homeserver/README.md
Severin Alexander Bühler 55d52ec4b8 chore(homeserver): Refactor Core (#96)
* first draft

* config2 for the time being

* more refactoring

* write default config if it doesnt exist

* added relays to config

* some refactor

* proper bootstrap nodes and relay config validation

* small comments

* rename module

* renamings

* turn listen_ports to listen_socket

* connected config with homeserver

* cleaned up old config

* cleaned up config_old

* removed old config.example.toml

* cleanup tryfrom conversions

* removed dirs-next

* review cleanup

* extracted default config to its own toml file

* use hostname_validator for rfc1123 domain verification

* Domain struct

* fmt

* small config restructure

* use SignupMode in config and moved it to config dir

* moved and simplified lmdb

* save to switch branches

* lots done already

* missin lock file

* pkarr config

* constants

* app context

* used context in more places

* made homeserver independant

* testing feature

* added datadirmock

* getting the hang about testing

* fixed homeserver core tests

* added HandleHolder

* make the homeserver tasks stop when its dropped

* make server handles optional

* properly cleanup all background tasks

* moved logs

* fixed config default toml

* fmt, clippy

* moved stuff around

* lots of moving and readme

* fixed pkarr republisher tests

* removed docs from include

* fixed and refactored testnet

* make simple_testnet work

* httprelay shutdown

* different testnets

* fixing tests1

* fixing tests

* fixing more tests

* unified pkarr versions

* fixed config with bootstrap nodes and relays

* split up test_republish_on_signin to prevent timing issues

* fixed all tests in e2e?

* fixed multi publisher tests

* fixed pubky-client readme

* fixed testnet readme

* added better errors

* admin error

* fixed tests

* format

* clippy

* cllippy

* fixed testnet ports

* fixed client future issue

* improved testnet

* fixed cache_size pkarr relay issue

* small improvements

* fixed low prio dns record

* removed fixed testnet test due to port conflicts

* fixed browserify issues

* fmt

* clippy

* changed wait for testnet hs admin

* fixed docs clippy issues

* added comments

* moved icann_domain

* renamed datadirs

* implemented default for MockDataDir

* renamed run() to start()

* removed unwraps

* fmt

* fixed rename test

* cleaned up admin trace

* added santity values for periodic backup conf and user keys republisher

* fmt

* fmt

* fixed readme lint

* removed println

* fixed admin server edge to anyhow

* added ipv6 support

* removed unnecessary expects

* renamed testnet

* fmt

* renamed me

* changed import

* fmt
2025-04-18 10:00:43 +03:00

3.1 KiB

Pubky Homeserver

Pubky homeserver that acts as user's agent on the Internet, providing data availability and more.

Usage

Library

Use the Homeserver as a library in other crates/binaries or for testing purposes. The HomeserverSuite is all bells and wistles included.

use anyhow::Result;
use pubky_homeserver::HomeserverSuite;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
  let suite = HomeserverSuite::run_with_data_dir_path(PathBuf::from("~/.pubky")).await?;
  println!(
      "Homeserver HTTP listening on {}",
      server.core().icann_http_url()
  );
  println!(
      "Homeserver Pubky TLS listening on {} and {}",
      server.core().pubky_tls_dns_url(),
      server.core().pubky_tls_ip_url()
  );
  println!(
      "Admin server listening on http://{}",
      server.admin().listen_socket()
  );
  tokio::signal::ctrl_c().await?;

  println!("Shutting down Homeserver");
  Ok(())
}

Run the suite with a temporary directory and your custom config. This is a good way to test the server.

use anyhow::Result;
use pubky_homeserver::{HomeserverSuite, DataDirMock};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
  let mut config = ConfigToml::default(); // Use ConfigToml::test() for random ports.
  // Set config values however you like
  config.admin.admin_password = "alternative_password".to_string();
  // Creates a temporary directory that gets cleaned up 
  // as soon as the suite is dropped.
  let mock_dir = DataDirMock::new(config, None).unwrap(); 
  let suite = HomeserverSuite::run_with_data_dir_mock(mock_dir).await.unwrap();
}


Run the `HomeserverCore` only without the admin server.

```rust
use anyhow::Result;
use pubky_homeserver::HomeserverCore;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let mut core = HomeserverCore::from_data_dir_path(PathBuf::from("~/.pubky")).await?;
    core.listen().await?;
    println!(
        "Homeserver HTTP listening on {}",
        core().icann_http_url()
    );
    println!(
        "Homeserver Pubky TLS listening on {} and {}",
        core().pubky_tls_dns_url(),
        core().pubky_tls_ip_url()
    );
}

Binary

Use cargo run -- --data-dir=~/.pubky.

Signup Token

If homeserver is set to require signup tokens, you can create a new signup token using the admin endpoint:

let response = pubky_client
    .get(&format!("https://127.0.0.1:6288/admin/generate_signup_token"))
    .header("X-Admin-Password", "admin") // Use your admin password. This is testnet default pwd.
    .send()
    .await
    .unwrap();
let signup_token = response.text().await.unwrap();

via CLI with curl

curl -X GET "https://127.0.0.1:6288/admin/generate_signup_token" \
     -H "X-Admin-Password: admin"
     # Use your admin password. This is testnet default pwd.

or from JS

const url = "http://127.0.0.1:6288/admin/generate_signup_token";
const response = await client.fetch(url, {
  method: "GET",
  headers: {
    "X-Admin-Password": "admin", // use your admin password, defaults to testnet password.
  },
});
const signupToken = await response.text();