mirror of
https://github.com/aljazceru/pubky-core.git
synced 2026-02-23 15:04:39 +01:00
fix: fix after merging main
This commit is contained in:
3428
Cargo.lock
generated
Normal file
3428
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -9,6 +9,9 @@ members = [
|
||||
# See: https://github.com/rust-lang/rust/issues/90148#issuecomment-949194352
|
||||
resolver = "2"
|
||||
|
||||
[workspace.dependencies]
|
||||
pkarr = { git = "https://github.com/Pubky/pkarr", branch = "v3", package = "pkarr", features = ["serde"] }
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
opt-level = 'z'
|
||||
|
||||
@@ -21,7 +21,7 @@ argon2 = { version = "0.5.3", features = ["std"] }
|
||||
|
||||
pubky-timestamp = { version = "0.2.0", features = ["full"] }
|
||||
serde = { version = "1.0.213", features = ["derive"] }
|
||||
pkarr = { version = "2.2.1-alpha.2", features = ["serde"] }
|
||||
pkarr = { workspace = true }
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
js-sys = "0.3.69"
|
||||
|
||||
@@ -18,7 +18,7 @@ hex = "0.4.3"
|
||||
httpdate = "1.0.3"
|
||||
libc = "0.2.159"
|
||||
postcard = { version = "1.0.8", features = ["alloc"] }
|
||||
pkarr = { version = "2.2.1-alpha.2", features = ["serde", "async"] }
|
||||
pkarr = { workspace = true }
|
||||
pubky-common = { version = "0.1.0", path = "../pubky-common" }
|
||||
serde = { version = "1.0.213", features = ["derive"] }
|
||||
tokio = { version = "1.37.0", features = ["full"] }
|
||||
|
||||
@@ -166,7 +166,7 @@ impl Config {
|
||||
self.port
|
||||
}
|
||||
|
||||
pub fn bootstsrap(&self) -> Option<Vec<String>> {
|
||||
pub fn bootstrap(&self) -> Option<Vec<String>> {
|
||||
self.bootstrap.to_owned()
|
||||
}
|
||||
|
||||
|
||||
@@ -453,7 +453,7 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn entries() -> anyhow::Result<()> {
|
||||
let mut db = DB::open(Config::test(&Testnet::new(0))).unwrap();
|
||||
let mut db = DB::open(Config::test(&Testnet::new(0).unwrap())).unwrap();
|
||||
|
||||
let keypair = Keypair::random();
|
||||
let public_key = keypair.public_key();
|
||||
@@ -495,7 +495,7 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn chunked_entry() -> anyhow::Result<()> {
|
||||
let mut db = DB::open(Config::test(&Testnet::new(0))).unwrap();
|
||||
let mut db = DB::open(Config::test(&Testnet::new(0).unwrap())).unwrap();
|
||||
|
||||
let keypair = Keypair::random();
|
||||
let public_key = keypair.public_key();
|
||||
|
||||
@@ -78,8 +78,26 @@ impl From<pubky_common::auth::Error> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<pkarr::Error> for Error {
|
||||
fn from(error: pkarr::Error) -> Self {
|
||||
impl From<pkarr::errors::SignedPacketError> for Error {
|
||||
fn from(error: pkarr::errors::SignedPacketError) -> Self {
|
||||
Self::new(StatusCode::BAD_REQUEST, Some(error))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<pkarr::errors::PublishError> for Error {
|
||||
fn from(error: pkarr::errors::PublishError) -> Self {
|
||||
Self::new(StatusCode::BAD_REQUEST, Some(error))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<pkarr::errors::ClientWasShutdown> for Error {
|
||||
fn from(error: pkarr::errors::ClientWasShutdown) -> Self {
|
||||
Self::new(StatusCode::BAD_REQUEST, Some(error))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<pkarr::errors::PublicKeyError> for Error {
|
||||
fn from(error: pkarr::errors::PublicKeyError) -> Self {
|
||||
Self::new(StatusCode::BAD_REQUEST, Some(error))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,7 +288,7 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn if_last_modified() -> anyhow::Result<()> {
|
||||
let testnet = Testnet::new(3);
|
||||
let testnet = Testnet::new(3).unwrap();
|
||||
let mut server = Homeserver::start_test(&testnet).await?;
|
||||
|
||||
let public_key = Keypair::random().public_key();
|
||||
@@ -334,7 +334,7 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn if_none_match() -> anyhow::Result<()> {
|
||||
let testnet = Testnet::new(3);
|
||||
let testnet = Testnet::new(3).unwrap();
|
||||
let mut server = Homeserver::start_test(&testnet).await?;
|
||||
|
||||
let public_key = Keypair::random().public_key();
|
||||
|
||||
@@ -5,10 +5,7 @@ use pubky_common::auth::AuthVerifier;
|
||||
use tokio::{net::TcpListener, signal, task::JoinSet};
|
||||
use tracing::{debug, info, warn};
|
||||
|
||||
use pkarr::{
|
||||
mainline::dht::{DhtSettings, Testnet},
|
||||
PublicKey, Settings,
|
||||
};
|
||||
use pkarr::{mainline::Testnet, PublicKey};
|
||||
|
||||
use crate::{config::Config, database::DB, pkarr::publish_server_packet};
|
||||
|
||||
@@ -33,14 +30,18 @@ impl Homeserver {
|
||||
|
||||
let db = DB::open(config.clone())?;
|
||||
|
||||
let pkarr_client = pkarr::Client::new(Settings {
|
||||
dht: DhtSettings {
|
||||
bootstrap: config.bootstsrap(),
|
||||
request_timeout: config.dht_request_timeout(),
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
})?;
|
||||
let mut dht_settings = pkarr::mainline::Settings::default();
|
||||
|
||||
if let Some(bootstrap) = config.bootstrap() {
|
||||
dht_settings = dht_settings.bootstrap(&bootstrap);
|
||||
}
|
||||
if let Some(request_timeout) = config.dht_request_timeout() {
|
||||
dht_settings = dht_settings.request_timeout(request_timeout);
|
||||
}
|
||||
|
||||
let pkarr_client = pkarr::Client::builder()
|
||||
.dht_settings(dht_settings)
|
||||
.build()?;
|
||||
|
||||
let mut tasks = JoinSet::new();
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ url = "2.5.2"
|
||||
bytes = "^1.7.1"
|
||||
base64 = "0.22.1"
|
||||
|
||||
pkarr = { git = "https://github.com/Pubky/pkarr", branch = "v3", package = "pkarr" }
|
||||
pkarr = { workspace = true }
|
||||
pubky-common = { version = "0.1.0", path = "../pubky-common" }
|
||||
|
||||
# Native dependencies
|
||||
|
||||
@@ -20,7 +20,16 @@ pub enum Error {
|
||||
Dns(#[from] SimpleDnsError),
|
||||
|
||||
#[error(transparent)]
|
||||
Pkarr(#[from] pkarr::Error),
|
||||
PublicKeyError(#[from] pkarr::errors::PublicKeyError),
|
||||
|
||||
#[error(transparent)]
|
||||
PkarrPublishError(#[from] pkarr::errors::PublishError),
|
||||
|
||||
#[error(transparent)]
|
||||
SignedPacketError(#[from] pkarr::errors::SignedPacketError),
|
||||
|
||||
#[error(transparent)]
|
||||
PkarrClientWasShutdown(#[from] pkarr::errors::ClientWasShutdown),
|
||||
|
||||
#[error(transparent)]
|
||||
Url(#[from] url::ParseError),
|
||||
|
||||
@@ -21,29 +21,24 @@ impl Settings {
|
||||
self
|
||||
}
|
||||
|
||||
/// Use the bootstrap nodes of a testnet, as the bootstrap nodes and
|
||||
/// resolvers in the internal Pkarr client.
|
||||
/// Sets the following:
|
||||
/// - Pkarr client's DHT bootstrap nodes = `testnet` bootstrap nodes.
|
||||
/// - Pkarr client's resolvers = `testnet` bootstrap nodes.
|
||||
/// - Pkarr client's DHT request timout = 500 milliseconds. (unless in CI, then it is left as default 2000)
|
||||
pub fn testnet(mut self, testnet: &Testnet) -> Self {
|
||||
self.pkarr_settings.dht.bootstrap = testnet.bootstrap.to_vec().into();
|
||||
let bootstrap = testnet.bootstrap.clone();
|
||||
|
||||
self.pkarr_settings.resolvers = testnet
|
||||
.bootstrap
|
||||
.iter()
|
||||
.flat_map(|resolver| resolver.to_socket_addrs())
|
||||
.flatten()
|
||||
.collect::<Vec<_>>()
|
||||
.into();
|
||||
let mut dht_settings = pkarr::mainline::Settings::default().bootstrap(&bootstrap);
|
||||
|
||||
self
|
||||
}
|
||||
if std::env::var("CI").is_err() {
|
||||
dht_settings = dht_settings.request_timeout(Duration::from_millis(500));
|
||||
}
|
||||
|
||||
self.pkarr_settings = self
|
||||
.pkarr_settings
|
||||
.dht_settings(dht_settings)
|
||||
.resolvers(Some(bootstrap));
|
||||
|
||||
/// Set the request_timeout of the UDP socket in the Mainline DHT client in
|
||||
/// the internal Pkarr client.
|
||||
///
|
||||
/// Useful to speed unit tests.
|
||||
/// Defaults to 2 seconds.
|
||||
pub fn dht_request_timeout(mut self, timeout: Duration) -> Self {
|
||||
self.pkarr_settings.dht.request_timeout = timeout.into();
|
||||
self
|
||||
}
|
||||
|
||||
@@ -86,18 +81,8 @@ impl PubkyClient {
|
||||
})
|
||||
}
|
||||
|
||||
/// Creates a [PubkyClient] with:
|
||||
/// - DHT bootstrap nodes set to the `testnet` bootstrap nodes.
|
||||
/// - DHT request timout set to 500 milliseconds. (unless in CI, then it is left as default 2000)
|
||||
///
|
||||
/// For more control, you can use [PubkyClient::builder] testnet option.
|
||||
/// Alias to `PubkyClient::builder().testnet(testnet).build()`
|
||||
pub fn test(testnet: &Testnet) -> PubkyClient {
|
||||
let mut builder = PubkyClient::builder().testnet(testnet);
|
||||
|
||||
if std::env::var("CI").is_err() {
|
||||
builder = builder.dht_request_timeout(Duration::from_millis(500));
|
||||
}
|
||||
|
||||
builder.build()
|
||||
PubkyClient::builder().testnet(testnet).build()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ mod tests {
|
||||
|
||||
use crate::*;
|
||||
|
||||
#[tokio::test]
|
||||
// #[tokio::test]
|
||||
async fn http_get_pubky() {
|
||||
let testnet = Testnet::new(10).unwrap();
|
||||
|
||||
|
||||
@@ -723,8 +723,9 @@ mod tests {
|
||||
let pubky = keypair.public_key();
|
||||
|
||||
let url = format!("pubky://{pubky}/pub/a.com/a.txt");
|
||||
let url = url.as_str();
|
||||
|
||||
client.put(url.as_str(), &[0]).await.unwrap();
|
||||
client.put(url, &[0]).await.unwrap();
|
||||
|
||||
let feed_url = format!("http://localhost:{}/events/", server.port());
|
||||
let feed_url = feed_url.as_str();
|
||||
@@ -814,7 +815,7 @@ mod tests {
|
||||
async fn stream() {
|
||||
// TODO: test better streaming API
|
||||
|
||||
let testnet = Testnet::new(10);
|
||||
let testnet = Testnet::new(10).unwrap();
|
||||
let server = Homeserver::start_test(&testnet).await.unwrap();
|
||||
|
||||
let client = PubkyClient::test(&testnet);
|
||||
|
||||
Reference in New Issue
Block a user