diff --git a/Cargo.lock b/Cargo.lock index af098ab..a68e4ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -77,11 +77,12 @@ dependencies = [ [[package]] name = "anstyle-wincon" -version = "3.0.6" +version = "3.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125" +checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e" dependencies = [ "anstyle", + "once_cell", "windows-sys 0.59.0", ] @@ -123,9 +124,9 @@ checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "async-trait" -version = "0.1.84" +version = "0.1.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b1244b10dcd56c92219da4e14caa97e312079e185f04ba3eea25061561dc0a0" +checksum = "3f934833b4b7233644e5848f235df3f57ed8c80f1528a26c3dfa13d2147fa056" dependencies = [ "proc-macro2", "quote", @@ -336,9 +337,9 @@ dependencies = [ [[package]] name = "bitflags" -version = "2.6.0" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36" dependencies = [ "serde", ] @@ -394,9 +395,9 @@ checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b" [[package]] name = "cc" -version = "1.2.7" +version = "1.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a012a0df96dd6d06ba9a1b29d6402d1a5d77c6befd2566afdc26e10603dc93d7" +checksum = "c8293772165d9345bdaaa39b45b2109591e63fe5e6fbc23c6ff930a048aa310b" dependencies = [ "shlex", ] @@ -426,9 +427,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.23" +version = "4.5.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84" +checksum = "a8eb5e908ef3a6efbe1ed62520fb7287959888c88485abe072543190ecc66783" dependencies = [ "clap_builder", "clap_derive", @@ -436,9 +437,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.23" +version = "4.5.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838" +checksum = "96b01801b5fc6a0a232407abc821660c9c6d25a1cafc0d4f85f29fb8d9afc121" dependencies = [ "anstream", "anstyle", @@ -448,9 +449,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.18" +version = "4.5.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" +checksum = "54b755194d6389280185988721fffba69495eed5ee9feeee9a599b53db80318c" dependencies = [ "heck", "proc-macro2", @@ -918,9 +919,9 @@ checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" [[package]] name = "futures-lite" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cef40d21ae2c515b51041df9ed313ed21e572df340ea58a922a0aefe7e8891a1" +checksum = "f5edaec856126859abb19ed65f39e90fea3a9574b9707f13539acf4abf7eb532" dependencies = [ "fastrand", "futures-core", @@ -1509,9 +1510,9 @@ checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" [[package]] name = "js-sys" -version = "0.3.76" +version = "0.3.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6717b6b5b077764fb5966237269cb3c64edddde4b14ce42647430a78ced9e7b7" +checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" dependencies = [ "once_cell", "wasm-bindgen", @@ -1541,9 +1542,9 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.4.14" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" +checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" [[package]] name = "litemap" @@ -1580,9 +1581,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.22" +version = "0.4.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +checksum = "04cbf5b083de1c7e0222a7a51dbfdba1cbe1c6ab0b15e29fff3f6c077fd9cd9f" [[package]] name = "lru" @@ -1605,7 +1606,7 @@ dependencies = [ "serde_bencode", "serde_bytes", "sha1_smol", - "thiserror 2.0.9", + "thiserror 2.0.11", "tracing", ] @@ -1638,9 +1639,9 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "miniz_oxide" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ffbe83022cedc1d264172192511ae958937694cd57ce297164951b8b3568394" +checksum = "b8402cab7aefae129c6977bb0ff1b8fd9a04eb5b51efc50a70bea51cda0c7924" dependencies = [ "adler2", ] @@ -1862,9 +1863,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "phf" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +checksum = "1fd6780a80ae0c52cc120a26a1a42c1ae51b247a253e4e06113d23d2c2edd078" dependencies = [ "phf_macros", "phf_shared", @@ -1872,9 +1873,9 @@ dependencies = [ [[package]] name = "phf_generator" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d" dependencies = [ "phf_shared", "rand", @@ -1882,9 +1883,9 @@ dependencies = [ [[package]] name = "phf_macros" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +checksum = "f84ac04429c13a7ff43785d75ad27569f2951ce0ffd30a3321230db2fc727216" dependencies = [ "phf_generator", "phf_shared", @@ -1895,27 +1896,27 @@ dependencies = [ [[package]] name = "phf_shared" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5" dependencies = [ "siphasher", ] [[package]] name = "pin-project" -version = "1.1.7" +version = "1.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be57f64e946e500c8ee36ef6331845d40a93055567ec57e8fae13efd33759b95" +checksum = "1e2ec53ad785f4d35dac0adea7f7dc6f1bb277ad84a680c7afefeae05d1f5916" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.7" +version = "1.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c0f5fad0874fc7abcd4d750e76917eaebbecaa2c20bde22e1dbeeba8beb758c" +checksum = "d56a66c0c55993aa927429d0f8a0abfd74f084e4d9c192cffed01e418d83eefb" dependencies = [ "proc-macro2", "quote", @@ -1924,9 +1925,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" [[package]] name = "pin-utils" @@ -1964,7 +1965,7 @@ dependencies = [ "serde", "sha1_smol", "simple-dns", - "thiserror 2.0.9", + "thiserror 2.0.11", "tokio", "tracing", "url", @@ -1990,7 +1991,7 @@ dependencies = [ "pubky-timestamp", "rustls", "serde", - "thiserror 2.0.9", + "thiserror 2.0.11", "tokio", "toml", "tower-http", @@ -2062,9 +2063,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.92" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" +checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" dependencies = [ "unicode-ident", ] @@ -2097,7 +2098,7 @@ dependencies = [ "pubky-common", "pubky-homeserver", "reqwest", - "thiserror 2.0.9", + "thiserror 2.0.11", "tokio", "tracing", "url", @@ -2122,7 +2123,7 @@ dependencies = [ "pubky-timestamp", "rand", "serde", - "thiserror 2.0.9", + "thiserror 2.0.11", ] [[package]] @@ -2213,7 +2214,7 @@ dependencies = [ "rustc-hash", "rustls", "socket2", - "thiserror 2.0.9", + "thiserror 2.0.11", "tokio", "tracing", ] @@ -2232,7 +2233,7 @@ dependencies = [ "rustls", "rustls-pki-types", "slab", - "thiserror 2.0.9", + "thiserror 2.0.11", "tinyvec", "tracing", "web-time", @@ -2293,9 +2294,9 @@ dependencies = [ [[package]] name = "raw-cpuid" -version = "11.2.0" +version = "11.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ab240315c661615f2ee9f0f2cd32d5a7343a84d5ebcccb99d46e6637565e7b0" +checksum = "c6928fa44c097620b706542d428957635951bade7143269085389d42c8a4927e" dependencies = [ "bitflags", ] @@ -2474,9 +2475,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.42" +version = "0.38.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93dc38ecbab2eb790ff964bb77fa94faf256fd3e73285fd7ba0903b76bedb85" +checksum = "a78891ee6bf2340288408954ac787aa063d8e8817e9f53abb37c695c6d834ef6" dependencies = [ "bitflags", "errno", @@ -2487,9 +2488,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.20" +version = "0.23.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5065c3f250cbd332cd894be57c40fa52387247659b14a2d6041d121547903b1b" +checksum = "8f287924602bf649d949c63dc8ac8b235fa5387d394020705b80c4eb597ce5b8" dependencies = [ "once_cell", "ring", @@ -2579,9 +2580,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.13.0" +version = "2.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1863fd3768cd83c56a7f60faa4dc0d403f1b6df0a38c3c25f44b7894e45370d5" +checksum = "49db231d56a190491cb4aeda9527f1ad45345af50b0851622a7adb8c03b01c32" dependencies = [ "core-foundation-sys", "libc", @@ -2640,9 +2641,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.134" +version = "1.0.135" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d00f4175c42ee48b15416f6193a959ba3a0d67fc699a0db9ad12df9f83991c7d" +checksum = "2b0d7ba2887406110130a978386c4e1befb98c674b4fba677954e4db976630d9" dependencies = [ "itoa", "memchr", @@ -2744,18 +2745,18 @@ dependencies = [ [[package]] name = "simple-dns" -version = "0.9.1" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8f1740a36513fc97c5309eb1b8e8f108b0e95899c66c23fd7259625d4fdb686" +checksum = "84330be8d9f218c15b4583c74d809643fb82bdcbbd48302a36469ea5b63a1d69" dependencies = [ "bitflags", ] [[package]] name = "siphasher" -version = "0.3.11" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" +checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" [[package]] name = "slab" @@ -2830,9 +2831,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.95" +version = "2.0.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46f71c0377baf4ef1cc3e3402ded576dccc315800fbc62dfc7fe04b009773b4a" +checksum = "d5d0adab1ae378d7f53bdebc67a39f1f151407ef230f0ce2883572f5d8985c80" dependencies = [ "proc-macro2", "quote", @@ -2914,11 +2915,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.9" +version = "2.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f072643fd0190df67a8bab670c20ef5d8737177d6ac6b2e9a236cb096206b2cc" +checksum = "d452f284b73e6d76dd36758a0c8684b1d5be31f92b89d07fd5822175732206fc" dependencies = [ - "thiserror-impl 2.0.9", + "thiserror-impl 2.0.11", ] [[package]] @@ -2934,9 +2935,9 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "2.0.9" +version = "2.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b50fa271071aae2e6ee85f842e2e28ba8cd2c5fb67f11fcb1fd70b276f9e7d4" +checksum = "26afc1baea8a989337eeb52b6e72a039780ce45c3edfcc9c5b9d112feeb173c2" dependencies = [ "proc-macro2", "quote", @@ -3011,9 +3012,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.42.0" +version = "1.43.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cec9b21b0450273377fc97bd4c33a8acffc8c996c987a7c5b319a0083707551" +checksum = "3d61fa4ffa3de412bfea335c6ecff681de2b609ba3c77ef3e00e521813a9ed9e" dependencies = [ "backtrace", "bytes", @@ -3029,9 +3030,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" +checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" dependencies = [ "proc-macro2", "quote", @@ -3357,20 +3358,21 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.99" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a474f6281d1d70c17ae7aa6a613c87fce69a127e2624002df63dcb39d6cf6396" +checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" dependencies = [ "cfg-if", "once_cell", + "rustversion", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.99" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f89bb38646b4f81674e8f5c3fb81b562be1fd936d84320f3264486418519c79" +checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" dependencies = [ "bumpalo", "log", @@ -3382,9 +3384,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.49" +version = "0.4.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38176d9b44ea84e9184eff0bc34cc167ed044f816accfe5922e54d84cf48eca2" +checksum = "555d470ec0bc3bb57890405e5d4322cc9ea83cebb085523ced7be4144dac1e61" dependencies = [ "cfg-if", "js-sys", @@ -3395,9 +3397,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.99" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cc6181fd9a7492eef6fef1f33961e3695e4579b9872a6f7c83aee556666d4fe" +checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3405,9 +3407,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.99" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2" +checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" dependencies = [ "proc-macro2", "quote", @@ -3418,15 +3420,18 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.99" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6" +checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +dependencies = [ + "unicode-ident", +] [[package]] name = "web-sys" -version = "0.3.76" +version = "0.3.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04dd7223427d52553d3702c004d3b2fe07c148165faa56313cb00211e31c12bc" +checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2" dependencies = [ "js-sys", "wasm-bindgen", @@ -3653,9 +3658,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.6.22" +version = "0.6.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39281189af81c07ec09db316b302a3e67bf9bd7cbf6c820b50e35fee9c2fa980" +checksum = "c8d71a593cc5c42ad7876e2c1fda56f314f3754c084128833e64f1345ff8a03a" dependencies = [ "memchr", ] diff --git a/pubky-homeserver/src/config.example.toml b/pubky-homeserver/src/config.example.toml index 9584bcb..2c93f00 100644 --- a/pubky-homeserver/src/config.example.toml +++ b/pubky-homeserver/src/config.example.toml @@ -1,11 +1,39 @@ # Secret key (in hex) to generate the Homeserver's Keypair # secret_key = "0000000000000000000000000000000000000000000000000000000000000000" -# ICANN domain pointing to this server to allow browsers to connect to it. -# domain = "example.com" - -# Port for the Homeserver to listen on. -port = 6287 - +[database] # Storage directory Defaults to # storage = "" + +[io] +# The port number to run an HTTP (clear text) server on. +http_port = 6286 +# The port number to run an HTTPs (Pkarr TLS) server on. +https_port = 6287 + +# The public IP of this server. +# +# This address will be mentioned in the Pkarr records of this +# Homeserver that is published on its public key (derivde from `secret_key`) +public_ip = "127.0.0.1" + +# If you are running this server behind a reverse proxy, +# you need to provide some extra configurations. +[io.reverse_proxy] +# The public port should be mapped to the `io::https_port` +# and you should setup tcp forwarding (don't terminate TLS on that port). +public_port = 6287 + +# If you want your server to be accessible from legacy browsers, +# you need to provide some extra configurations. +[io.legacy_browsers] +# An ICANN domain name is necessary to support legacy browsers +# +# Make sure to setup a domain name and point it the IP +# address of this machine where you are running this server. +# +# This domain should point to the `:`. +# +# Currently we don't support ICANN TLS, so you should be runing +# a reverse proxy and managing certifcates there for this endpoint. +domain = "example.com" diff --git a/pubky-homeserver/src/core/config.rs b/pubky-homeserver/src/core/config.rs index a5c9149..ff3494a 100644 --- a/pubky-homeserver/src/core/config.rs +++ b/pubky-homeserver/src/core/config.rs @@ -5,10 +5,14 @@ use pkarr::Keypair; use serde::{Deserialize, Serialize}; use std::{ fmt::Debug, + net::{IpAddr, SocketAddr}, path::{Path, PathBuf}, time::Duration, }; +const DEFAULT_HTTP_PORT: u16 = 6286; +const DEFAULT_HTTPS_PORT: u16 = 6287; + // === Database === const DEFAULT_STORAGE_DIR: &str = "pubky"; pub const DEFAULT_MAP_SIZE: usize = 10995116277760; // 10TB (not = disk-space used) @@ -17,17 +21,45 @@ pub const DEFAULT_MAP_SIZE: usize = 10995116277760; // 10TB (not = disk-space us pub const DEFAULT_LIST_LIMIT: u16 = 100; pub const DEFAULT_MAX_LIST_LIMIT: u16 = 1000; -#[derive(Serialize, Deserialize, Clone, PartialEq)] -struct ConfigToml { - port: Option, - bootstrap: Option>, - domain: Option, +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] +struct DatabaseToml { storage: Option, +} + +#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq, Eq)] +struct ReverseProxyToml { + pub public_port: Option, +} + +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] +struct LegacyBrowsersTompl { + pub domain: Option, +} + +#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)] +struct IoToml { + pub http_port: Option, + pub https_port: Option, + pub public_ip: Option, + + pub reverse_proxy: Option, + pub legacy_browsers: Option, +} + +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] +struct ConfigToml { secret_key: Option, - dht_request_timeout: Option, - default_list_limit: Option, - max_list_limit: Option, - db_map_size: Option, + + database: Option, + io: Option, +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct IoConfig { + pub http_port: u16, + pub https_port: u16, + pub public_addr: Option, + pub domain: Option, } /// Server configuration @@ -35,15 +67,10 @@ struct ConfigToml { pub struct Config { /// Run in [testnet](crate::Homeserver::start_testnet) mode. pub testnet: bool, - /// The configured port for this server. - pub port: u16, /// Bootstrapping DHT nodes. /// /// Helpful to run the server locally or in testnet. pub bootstrap: Option>, - /// A public domain for this server - /// necessary for web browsers running in https environment. - pub domain: Option, /// Path to the storage directory. /// /// Defaults to a directory in the OS data directory @@ -64,6 +91,8 @@ pub struct Config { // === Database params === pub db_map_size: usize, + + pub io: IoConfig, } impl Config { @@ -92,8 +121,13 @@ impl Config { Self { bootstrap, storage, - domain: Some("localhost".to_string()), db_map_size: 10485760, + io: IoConfig { + http_port: 0, + https_port: 0, + public_addr: None, + domain: None, + }, ..Default::default() } } @@ -103,16 +137,20 @@ impl Default for Config { fn default() -> Self { Self { testnet: false, - port: 0, + keypair: Keypair::random(), bootstrap: None, - domain: None, storage: storage(None) .expect("operating environment provides no directory for application data"), - keypair: Keypair::random(), dht_request_timeout: None, default_list_limit: DEFAULT_LIST_LIMIT, max_list_limit: DEFAULT_MAX_LIST_LIMIT, db_map_size: DEFAULT_MAP_SIZE, + io: IoConfig { + https_port: DEFAULT_HTTPS_PORT, + http_port: DEFAULT_HTTP_PORT, + domain: None, + public_addr: None, + }, } } } @@ -129,29 +167,54 @@ impl TryFrom for Config { }; let storage = { - let dir = if let Some(storage) = value.storage { - storage - } else { - let path = dirs_next::data_dir().ok_or_else(|| { - anyhow!("operating environment provides no directory for application data") - })?; - path.join(DEFAULT_STORAGE_DIR) - }; + let dir = + if let Some(storage) = value.database.as_ref().and_then(|db| db.storage.clone()) { + storage + } else { + let path = dirs_next::data_dir().ok_or_else(|| { + anyhow!("operating environment provides no directory for application data") + })?; + path.join(DEFAULT_STORAGE_DIR) + }; dir.join("homeserver") }; + let io = if let Some(io) = value.io { + IoConfig { + http_port: io.http_port.unwrap_or(DEFAULT_HTTP_PORT), + https_port: io.https_port.unwrap_or(DEFAULT_HTTPS_PORT), + domain: io.legacy_browsers.and_then(|l| l.domain), + public_addr: io.public_ip.map(|ip| { + SocketAddr::from(( + ip, + io.reverse_proxy + .and_then(|r| r.public_port) + .unwrap_or(io.https_port.unwrap_or(0)), + )) + }), + } + } else { + IoConfig { + http_port: DEFAULT_HTTP_PORT, + https_port: DEFAULT_HTTPS_PORT, + domain: None, + public_addr: None, + } + }; + Ok(Config { testnet: false, - port: value.port.unwrap_or(0), - bootstrap: value.bootstrap, - domain: value.domain, keypair, + storage, - dht_request_timeout: value.dht_request_timeout, - default_list_limit: value.default_list_limit.unwrap_or(DEFAULT_LIST_LIMIT), - max_list_limit: value.default_list_limit.unwrap_or(DEFAULT_MAX_LIST_LIMIT), - db_map_size: value.db_map_size.unwrap_or(DEFAULT_MAP_SIZE), + dht_request_timeout: None, + bootstrap: None, + default_list_limit: DEFAULT_LIST_LIMIT, + max_list_limit: DEFAULT_MAX_LIST_LIMIT, + db_map_size: DEFAULT_MAP_SIZE, + + io, }) } } @@ -219,8 +282,12 @@ mod tests { storage: config.storage.clone(), keypair: config.keypair.clone(), - domain: Some("localhost".to_string()), - + io: IoConfig { + http_port: 0, + https_port: 0, + public_addr: None, + domain: None + }, ..Default::default() } ) @@ -230,29 +297,55 @@ mod tests { fn parse() { let config = Config::try_from_str( r#" - # 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. - domain = "localhost" - # Port for the Homeserver to listen on. - port = 6287 - # Storage directory Defaults to - storage = "/homeserver" +# Secret key (in hex) to generate the Homeserver's Keypair +secret_key = "0000000000000000000000000000000000000000000000000000000000000000" - bootstrap = ["foo", "bar"] +[database] +# Storage directory Defaults to +# storage = "" - # event stream - default_list_limit = 500 - max_list_limit = 10000 +[io] +# The port number to run an HTTP (clear text) server on. +http_port = 6286 +# The port number to run an HTTPs (Pkarr TLS) server on. +https_port = 6287 + +# The public IP of this server. +# +# This address will be mentioned in the Pkarr records of this +# Homeserver that is published on its public key (derivde from `secret_key`) +public_ip = "127.0.0.1" + +# If you are running this server behind a reverse proxy, +# you need to provide some extra configurations. +[io.reverse_proxy] +# The public port should be mapped to the `io::https_port` +# and you should setup tcp forwarding (don't terminate TLS on that port). +public_port = 6287 + +# If you want your server to be accessible from legacy browsers, +# you need to provide some extra configurations. +[io.legacy_browsers] +# An ICANN domain name is necessary to support legacy browsers +# +# Make sure to setup a domain name and point it the IP +# address of this machine where you are running this server. +# +# This domain should point to the `:`. +# +# Currently we don't support ICANN TLS, so you should be runing +# a reverse proxy and managing certifcates there for this endpoint. +domain = "example.com" "#, ) .unwrap(); assert_eq!(config.keypair, Keypair::from_secret_key(&[0; 32])); - assert_eq!(config.port, 6287); + assert_eq!(config.io.https_port, 6287); assert_eq!( - config.bootstrap, - Some(vec!["foo".to_string(), "bar".to_string()]) + config.io.public_addr, + Some(SocketAddr::from(([127, 0, 0, 1], 6287))) ); + assert_eq!(config.io.domain, Some("example.com".to_string())); } } diff --git a/pubky-homeserver/src/io/http.rs b/pubky-homeserver/src/io/http.rs index 65c0242..7a27499 100644 --- a/pubky-homeserver/src/io/http.rs +++ b/pubky-homeserver/src/io/http.rs @@ -28,8 +28,7 @@ pub struct HttpServers { impl HttpServers { pub async fn start(core: &HomeserverCore) -> Result { let http_listener = - // TODO: add config to http port - TcpListener::bind(SocketAddr::from(([0, 0, 0, 0], 0)))?; + TcpListener::bind(SocketAddr::from(([0, 0, 0, 0], core.config().io.http_port)))?; let http_address = http_listener.local_addr()?; let http_handle = Handle::new(); @@ -45,8 +44,10 @@ impl HttpServers { .map_err(|error| tracing::error!(?error, "Homeserver http server error")), ); - let https_listener = - TcpListener::bind(SocketAddr::from(([0, 0, 0, 0], core.config().port)))?; + let https_listener = TcpListener::bind(SocketAddr::from(( + [0, 0, 0, 0], + core.config().io.https_port, + )))?; let https_address = https_listener.local_addr()?; let https_handle = Handle::new(); diff --git a/pubky-homeserver/src/io/pkarr.rs b/pubky-homeserver/src/io/pkarr.rs index 296649d..0d11947 100644 --- a/pubky-homeserver/src/io/pkarr.rs +++ b/pubky-homeserver/src/io/pkarr.rs @@ -41,43 +41,58 @@ impl PkarrServer { } } -pub fn create_signed_packet(config: &Config, port: u16, http_port: u16) -> Result { +pub fn create_signed_packet( + config: &Config, + https_port: u16, + http_port: u16, +) -> Result { // TODO: Try to resolve first before publishing. - let default = ".".to_string(); - let target = config.domain.clone().unwrap_or(default); - let mut svcb = SVCB::new(0, target.as_str().try_into()?); + let mut signed_packet_builder = SignedPacket::builder(); - svcb.priority = 1; - svcb.set_port(port); + let mut svcb = SVCB::new(0, ".".try_into()?); - let http_port_be_bytes = http_port.to_be_bytes(); + // Set the public Ip or the loclahost + signed_packet_builder = signed_packet_builder.address( + ".".try_into().unwrap(), + config + .io + .public_addr + .map(|addr| addr.ip()) + .unwrap_or("127.0.0.1".parse().expect("localhost is valid ip")), + 60 * 60, + ); - svcb.set_param( - pubky_common::constants::reserved_param_keys::HTTP_PORT, - &http_port_be_bytes, - )?; + // Set the public port or the local https_port + svcb.set_port( + config + .io + .public_addr + .map(|addr| addr.port()) + .unwrap_or(https_port), + ); - let mut signed_packet_builder = - SignedPacket::builder().https(".".try_into().unwrap(), svcb.clone(), 60 * 60); + signed_packet_builder = signed_packet_builder.https(".".try_into().unwrap(), svcb, 60 * 60); + // Set low priority https record for legacy browsers support if config.testnet { + let mut svcb = SVCB::new(10, ".".try_into()?); + + let http_port_be_bytes = http_port.to_be_bytes(); + svcb.set_param( + pubky_common::constants::reserved_param_keys::HTTP_PORT, + &http_port_be_bytes, + )?; + svcb.target = "localhost".try_into().expect("localhost is valid dns name"); - signed_packet_builder = signed_packet_builder - .https(".".try_into().unwrap(), svcb, 60 * 60) - .address( - ".".try_into().unwrap(), - "127.0.0.1".parse().unwrap(), - 60 * 60, - ); - } else if let Some(ref domain) = config.domain { + signed_packet_builder = signed_packet_builder.https(".".try_into().unwrap(), svcb, 60 * 60) + } else if let Some(ref domain) = config.io.domain { + let mut svcb = SVCB::new(10, ".".try_into()?); svcb.target = domain.as_str().try_into()?; signed_packet_builder = signed_packet_builder.https(".".try_into().unwrap(), svcb, 60 * 60); } - // TODO: announce public IP with A/AAAA records (need to add options in config) - Ok(signed_packet_builder.build(&config.keypair)?) }