diff --git a/pubky-homeserver/src/config.rs b/pubky-homeserver/src/config.rs index 25fbc66..22686cf 100644 --- a/pubky-homeserver/src/config.rs +++ b/pubky-homeserver/src/config.rs @@ -24,6 +24,8 @@ pub struct Config { /// Defaults to a directory in the OS data directory storage: Option, keypair: Keypair, + + dht_request_timeout: Option, } impl Config { @@ -52,6 +54,7 @@ impl Config { storage, port: Some(15411), keypair: Keypair::from_secret_key(&[0_u8; 32]), + dht_request_timeout: Some(Duration::from_millis(10)), ..Default::default() } } @@ -101,6 +104,10 @@ impl Config { pub fn keypair(&self) -> &Keypair { &self.keypair } + + pub(crate) fn dht_request_timeout(&self) -> Option { + self.dht_request_timeout + } } impl Default for Config { @@ -111,6 +118,7 @@ impl Default for Config { domain: "localhost".to_string(), storage: None, keypair: Keypair::random(), + dht_request_timeout: None, } } } diff --git a/pubky-homeserver/src/server.rs b/pubky-homeserver/src/server.rs index 9837ed9..2863317 100644 --- a/pubky-homeserver/src/server.rs +++ b/pubky-homeserver/src/server.rs @@ -39,6 +39,7 @@ impl Homeserver { let pkarr_client = PkarrClient::new(Settings { dht: DhtSettings { bootstrap: config.bootstsrap(), + request_timeout: config.dht_request_timeout(), ..Default::default() }, ..Default::default() diff --git a/pubky/pkg/package.json b/pubky/pkg/package.json index 0c66d29..ad5c858 100644 --- a/pubky/pkg/package.json +++ b/pubky/pkg/package.json @@ -2,7 +2,7 @@ "name": "@synonymdev/pubky", "type": "module", "description": "Pubky client", - "version": "0.0.3", + "version": "0.1.1", "license": "MIT", "repository": { "type": "git", diff --git a/pubky/pkg/test/auth.js b/pubky/pkg/test/auth.js index cd54e06..d738c99 100644 --- a/pubky/pkg/test/auth.js +++ b/pubky/pkg/test/auth.js @@ -3,7 +3,7 @@ import test from 'tape' import { PubkyClient, Keypair, PublicKey } from '../index.js' test('auth', async (t) => { - const client = new PubkyClient().setPkarrRelays(["http://localhost:15411/pkarr"]) + const client = PubkyClient.testnet(); const keypair = Keypair.random() const publicKey = keypair.public_key() diff --git a/pubky/pkg/test/public.js b/pubky/pkg/test/public.js index ddf02a4..624f7dc 100644 --- a/pubky/pkg/test/public.js +++ b/pubky/pkg/test/public.js @@ -3,7 +3,7 @@ import test from 'tape' import { PubkyClient, Keypair, PublicKey } from '../index.js' test('public: put/get', async (t) => { - const client = new PubkyClient().setPkarrRelays(["http://localhost:15411/pkarr"]) + const client = PubkyClient.testnet(); const keypair = Keypair.random(); @@ -20,7 +20,7 @@ test('public: put/get', async (t) => { // GET public data without signup or signin { - const client = new PubkyClient().setPkarrRelays(["http://localhost:15411/pkarr"]) + const client = PubkyClient.testnet(); let response = await client.get(publicKey, "/pub/example.com/arbitrary"); diff --git a/pubky/src/wasm.rs b/pubky/src/wasm.rs index b04de3b..d22a6ed 100644 --- a/pubky/src/wasm.rs +++ b/pubky/src/wasm.rs @@ -25,6 +25,7 @@ impl Default for PubkyClient { } static DEFAULT_RELAYS: [&str; 1] = ["https://relay.pkarr.org"]; +static TESTNET_RELAYS: [&str; 1] = ["http://localhost:15411/pkarr"]; #[wasm_bindgen] impl PubkyClient { @@ -37,7 +38,18 @@ impl PubkyClient { } } - /// Set the relays used for publishing and resolving Pkarr packets. + /// Create a client with with configurations appropriate for local testing: + /// - set Pkarr relays to `["http://localhost:15411/pkarr"]` instead of default relay. + #[wasm_bindgen] + pub fn testnet() -> Self { + Self { + http: reqwest::Client::builder().build().unwrap(), + session_cookies: Arc::new(RwLock::new(HashSet::new())), + pkarr_relays: TESTNET_RELAYS.into_iter().map(|s| s.to_string()).collect(), + } + } + + /// Set Pkarr relays used for publishing and resolving Pkarr packets. /// /// By default, [PubkyClient] will use `["https://relay.pkarr.org"]` #[wasm_bindgen(js_name = "setPkarrRelays")] @@ -51,6 +63,7 @@ impl PubkyClient { self } + // Read the set of pkarr relays used by this client. #[wasm_bindgen(js_name = "getPkarrRelays")] pub fn get_pkarr_relays(&self) -> Vec { self.pkarr_relays