mirror of
https://git.asonix.dog/asonix/relay.git
synced 2025-03-14 05:22:40 +00:00
Compare commits
17 commits
Author | SHA1 | Date | |
---|---|---|---|
|
6ff7b59778 | ||
|
d9da352558 | ||
|
aea64c726a | ||
|
e243bd4600 | ||
|
a452fb91ba | ||
|
35acc916f2 | ||
|
752067ffb7 | ||
|
b308e080af | ||
|
6ab37dc06f | ||
|
a23b30cc91 | ||
|
1b58a50d44 | ||
|
308a945283 | ||
|
86cab5d2d9 | ||
|
a70e75665b | ||
|
f1792c8eb3 | ||
|
d918ef1495 | ||
|
2870789e1f |
13 changed files with 1409 additions and 687 deletions
1955
Cargo.lock
generated
1955
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
46
Cargo.toml
46
Cargo.toml
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "ap-relay"
|
name = "ap-relay"
|
||||||
description = "A simple activitypub relay"
|
description = "A simple activitypub relay"
|
||||||
version = "0.3.114"
|
version = "0.3.116"
|
||||||
authors = ["asonix <asonix@asonix.dog>"]
|
authors = ["asonix <asonix@asonix.dog>"]
|
||||||
license = "AGPL-3.0"
|
license = "AGPL-3.0"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
@ -24,60 +24,60 @@ default = []
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = { version = "4.4.0", default-features = false, features = ["compress-brotli", "compress-gzip", "rustls-0_22"] }
|
actix-web = { version = "4.4.0", default-features = false, features = ["compress-brotli", "compress-gzip", "rustls-0_23"] }
|
||||||
actix-webfinger = { version = "0.5.0", default-features = false }
|
actix-webfinger = { version = "0.5.0", default-features = false }
|
||||||
activitystreams = "0.7.0-alpha.25"
|
activitystreams = "0.7.0-alpha.25"
|
||||||
activitystreams-ext = "0.1.0-alpha.3"
|
activitystreams-ext = "0.1.0-alpha.3"
|
||||||
ammonia = "4.0.0"
|
ammonia = "4.0.0"
|
||||||
async-cpupool = "0.2.2"
|
async-cpupool = "0.3.0"
|
||||||
bcrypt = "0.15"
|
bcrypt = "0.16"
|
||||||
base64 = "0.22"
|
base64 = "0.22"
|
||||||
clap = { version = "4.0.0", features = ["derive"] }
|
clap = { version = "4.0.0", features = ["derive"] }
|
||||||
color-eyre = "0.6.2"
|
color-eyre = "0.6.2"
|
||||||
config = { version = "0.14.0", default-features = false, features = ["toml", "json", "yaml"] }
|
config = { version = "0.14.0", default-features = false, features = ["toml", "json", "yaml"] }
|
||||||
console-subscriber = { version = "0.2", optional = true }
|
console-subscriber = { version = "0.4", optional = true }
|
||||||
dashmap = "5.1.0"
|
dashmap = "6.0.1"
|
||||||
dotenv = "0.15.0"
|
dotenv = "0.15.0"
|
||||||
futures-core = "0.3.30"
|
futures-core = "0.3.30"
|
||||||
lru = "0.12.0"
|
lru = "0.12.0"
|
||||||
metrics = "0.22.0"
|
metrics = "0.23.0"
|
||||||
metrics-exporter-prometheus = { version = "0.13.0", default-features = false, features = [
|
metrics-exporter-prometheus = { version = "0.15.0", default-features = false, features = [
|
||||||
"http-listener",
|
"http-listener",
|
||||||
] }
|
] }
|
||||||
metrics-util = "0.16.0"
|
metrics-util = "0.17.0"
|
||||||
mime = "0.3.16"
|
mime = "0.3.16"
|
||||||
minify-html = "0.15.0"
|
minify-html = "0.15.0"
|
||||||
opentelemetry = "0.22"
|
opentelemetry = "0.27.1"
|
||||||
opentelemetry_sdk = { version = "0.22", features = ["rt-tokio"] }
|
opentelemetry_sdk = { version = "0.27", features = ["rt-tokio"] }
|
||||||
opentelemetry-otlp = "0.15"
|
opentelemetry-otlp = { version = "0.27", features = ["grpc-tonic"] }
|
||||||
pin-project-lite = "0.2.9"
|
pin-project-lite = "0.2.9"
|
||||||
# pinned to metrics-util
|
# pinned to metrics-util
|
||||||
quanta = "0.12.0"
|
quanta = "0.12.0"
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
reqwest = { version = "0.11", default-features = false, features = ["rustls-tls", "stream"]}
|
reqwest = { version = "0.12", default-features = false, features = ["rustls-tls", "stream"]}
|
||||||
reqwest-middleware = "0.2"
|
reqwest-middleware = { version = "0.4", default-features = false, features = ["json"] }
|
||||||
reqwest-tracing = "0.4.5"
|
reqwest-tracing = "0.5.0"
|
||||||
ring = "0.17.5"
|
ring = "0.17.5"
|
||||||
rsa = "0.9"
|
rsa = "0.9"
|
||||||
rsa-magic-public-key = "0.8.0"
|
rsa-magic-public-key = "0.8.0"
|
||||||
rustls = "0.22.0"
|
rustls = { version = "0.23.0", default-features = false, features = ["ring", "logging", "std", "tls12"] }
|
||||||
rustls-channel-resolver = "0.2.0"
|
rustls-channel-resolver = "0.3.0"
|
||||||
rustls-pemfile = "2"
|
rustls-pemfile = "2"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
sled = "0.34.7"
|
sled = "0.34.7"
|
||||||
streem = "0.2.0"
|
streem = "0.2.0"
|
||||||
teloxide = { version = "0.12.0", default-features = false, features = [
|
teloxide = { version = "0.13.0", default-features = false, features = [
|
||||||
"ctrlc_handler",
|
"ctrlc_handler",
|
||||||
"macros",
|
"macros",
|
||||||
"rustls",
|
"rustls",
|
||||||
] }
|
] }
|
||||||
thiserror = "1.0"
|
thiserror = "2.0"
|
||||||
time = { version = "0.3.17", features = ["serde"] }
|
time = { version = "0.3.17", features = ["serde"] }
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tracing-error = "0.2"
|
tracing-error = "0.2"
|
||||||
tracing-log = "0.2"
|
tracing-log = "0.2"
|
||||||
tracing-opentelemetry = "0.23"
|
tracing-opentelemetry = "0.28"
|
||||||
tracing-subscriber = { version = "0.3", features = [
|
tracing-subscriber = { version = "0.3", features = [
|
||||||
"ansi",
|
"ansi",
|
||||||
"env-filter",
|
"env-filter",
|
||||||
|
@ -87,17 +87,17 @@ tokio = { version = "1", features = ["full", "tracing"] }
|
||||||
uuid = { version = "1", features = ["v4", "serde"] }
|
uuid = { version = "1", features = ["v4", "serde"] }
|
||||||
|
|
||||||
[dependencies.background-jobs]
|
[dependencies.background-jobs]
|
||||||
version = "0.18.0"
|
version = "0.19.0"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["error-logging", "metrics", "tokio"]
|
features = ["error-logging", "metrics", "tokio"]
|
||||||
|
|
||||||
[dependencies.http-signature-normalization-actix]
|
[dependencies.http-signature-normalization-actix]
|
||||||
version = "0.11.0"
|
version = "0.11.1"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["server", "ring"]
|
features = ["server", "ring"]
|
||||||
|
|
||||||
[dependencies.http-signature-normalization-reqwest]
|
[dependencies.http-signature-normalization-reqwest]
|
||||||
version = "0.11.0"
|
version = "0.13.0"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["middleware", "ring"]
|
features = ["middleware", "ring"]
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ version: '3.3'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
relay:
|
relay:
|
||||||
image: asonix/relay:0.3.108
|
image: asonix/relay:0.3.115
|
||||||
ports:
|
ports:
|
||||||
- "8079:8079"
|
- "8079:8079"
|
||||||
restart: always
|
restart: always
|
||||||
|
|
|
@ -20,16 +20,16 @@
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1719075281,
|
"lastModified": 1733550349,
|
||||||
"narHash": "sha256-CyyxvOwFf12I91PBWz43iGT1kjsf5oi6ax7CrvaMyAo=",
|
"narHash": "sha256-NcGumB4Lr6KSDq+nIqXtNA8QwAQKDSZT7N9OTGWbTrs=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "a71e967ef3694799d0c418c98332f7ff4cc5f6af",
|
"rev": "e2605d0744c2417b09f8bf850dfca42fcf537d34",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"ref": "nixos-unstable",
|
"ref": "nixos-24.11",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
description = "relay";
|
description = "relay";
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
|
||||||
flake-utils.url = "github:numtide/flake-utils";
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
rustPlatform.buildRustPackage {
|
rustPlatform.buildRustPackage {
|
||||||
pname = "relay";
|
pname = "relay";
|
||||||
version = "0.3.114";
|
version = "0.3.116";
|
||||||
src = ./.;
|
src = ./.;
|
||||||
cargoLock.lockFile = ./Cargo.lock;
|
cargoLock.lockFile = ./Cargo.lock;
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ use crate::{
|
||||||
error::{Error, ErrorKind},
|
error::{Error, ErrorKind},
|
||||||
extractors::XApiToken,
|
extractors::XApiToken,
|
||||||
};
|
};
|
||||||
use actix_web::http::header::Header;
|
|
||||||
use reqwest_middleware::ClientWithMiddleware;
|
use reqwest_middleware::ClientWithMiddleware;
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
|
|
||||||
|
@ -87,13 +86,17 @@ async fn get_results<T: DeserializeOwned>(
|
||||||
|
|
||||||
let res = client
|
let res = client
|
||||||
.get(iri.as_str())
|
.get(iri.as_str())
|
||||||
.header(XApiToken::name(), x_api_token.to_string())
|
.header(XApiToken::http1_name(), x_api_token.to_string())
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
.map_err(|e| ErrorKind::SendRequest(iri.to_string(), e.to_string()))?;
|
.map_err(|e| ErrorKind::SendRequest(iri.to_string(), e.to_string()))?;
|
||||||
|
|
||||||
if !res.status().is_success() {
|
if !res.status().is_success() {
|
||||||
return Err(ErrorKind::Status(iri.to_string(), res.status()).into());
|
return Err(ErrorKind::Status(
|
||||||
|
iri.to_string(),
|
||||||
|
crate::http1::status_to_http02(res.status()),
|
||||||
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let t = res
|
let t = res
|
||||||
|
@ -116,7 +119,7 @@ async fn post_domains(
|
||||||
|
|
||||||
let res = client
|
let res = client
|
||||||
.post(iri.as_str())
|
.post(iri.as_str())
|
||||||
.header(XApiToken::name(), x_api_token.to_string())
|
.header(XApiToken::http1_name(), x_api_token.to_string())
|
||||||
.json(&Domains { domains })
|
.json(&Domains { domains })
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -163,6 +163,10 @@ impl XApiToken {
|
||||||
pub(crate) fn new(token: String) -> Self {
|
pub(crate) fn new(token: String) -> Self {
|
||||||
Self(token)
|
Self(token)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) const fn http1_name() -> reqwest::header::HeaderName {
|
||||||
|
reqwest::header::HeaderName::from_static("x-api-token")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Header for XApiToken {
|
impl Header for XApiToken {
|
||||||
|
|
18
src/http1.rs
Normal file
18
src/http1.rs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
pub(crate) fn name_to_http02(
|
||||||
|
name: &reqwest::header::HeaderName,
|
||||||
|
) -> actix_web::http::header::HeaderName {
|
||||||
|
actix_web::http::header::HeaderName::from_bytes(name.as_ref())
|
||||||
|
.expect("headername conversions always work")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn value_to_http02(
|
||||||
|
value: &reqwest::header::HeaderValue,
|
||||||
|
) -> actix_web::http::header::HeaderValue {
|
||||||
|
actix_web::http::header::HeaderValue::from_bytes(value.as_bytes())
|
||||||
|
.expect("headervalue conversions always work")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn status_to_http02(status: reqwest::StatusCode) -> actix_web::http::StatusCode {
|
||||||
|
actix_web::http::StatusCode::from_u16(status.as_u16())
|
||||||
|
.expect("statuscode conversions always work")
|
||||||
|
}
|
32
src/main.rs
32
src/main.rs
|
@ -12,7 +12,7 @@ use error::Error;
|
||||||
use http_signature_normalization_actix::middleware::VerifySignature;
|
use http_signature_normalization_actix::middleware::VerifySignature;
|
||||||
use metrics_exporter_prometheus::PrometheusBuilder;
|
use metrics_exporter_prometheus::PrometheusBuilder;
|
||||||
use metrics_util::layers::FanoutBuilder;
|
use metrics_util::layers::FanoutBuilder;
|
||||||
use opentelemetry::KeyValue;
|
use opentelemetry::{trace::TracerProvider, KeyValue};
|
||||||
use opentelemetry_otlp::WithExportConfig;
|
use opentelemetry_otlp::WithExportConfig;
|
||||||
use opentelemetry_sdk::Resource;
|
use opentelemetry_sdk::Resource;
|
||||||
use reqwest_middleware::ClientWithMiddleware;
|
use reqwest_middleware::ClientWithMiddleware;
|
||||||
|
@ -33,6 +33,7 @@ mod db;
|
||||||
mod error;
|
mod error;
|
||||||
mod extractors;
|
mod extractors;
|
||||||
mod future;
|
mod future;
|
||||||
|
mod http1;
|
||||||
mod jobs;
|
mod jobs;
|
||||||
mod middleware;
|
mod middleware;
|
||||||
mod requests;
|
mod requests;
|
||||||
|
@ -82,22 +83,21 @@ fn init_subscriber(
|
||||||
let subscriber = subscriber.with(console_layer);
|
let subscriber = subscriber.with(console_layer);
|
||||||
|
|
||||||
if let Some(url) = opentelemetry_url {
|
if let Some(url) = opentelemetry_url {
|
||||||
let tracer = opentelemetry_otlp::new_pipeline()
|
let exporter = opentelemetry_otlp::SpanExporter::builder()
|
||||||
.tracing()
|
.with_tonic()
|
||||||
.with_trace_config(
|
.with_endpoint(url.as_str())
|
||||||
opentelemetry_sdk::trace::config().with_resource(Resource::new(vec![
|
.build()?;
|
||||||
KeyValue::new("service.name", software_name),
|
|
||||||
])),
|
let tracer_provider = opentelemetry_sdk::trace::TracerProvider::builder()
|
||||||
)
|
.with_resource(Resource::new(vec![KeyValue::new(
|
||||||
.with_exporter(
|
"service.name",
|
||||||
opentelemetry_otlp::new_exporter()
|
software_name,
|
||||||
.tonic()
|
)]))
|
||||||
.with_endpoint(url.as_str()),
|
.with_batch_exporter(exporter, opentelemetry_sdk::runtime::Tokio)
|
||||||
)
|
.build();
|
||||||
.install_batch(opentelemetry_sdk::runtime::Tokio)?;
|
|
||||||
|
|
||||||
let otel_layer = tracing_opentelemetry::layer()
|
let otel_layer = tracing_opentelemetry::layer()
|
||||||
.with_tracer(tracer)
|
.with_tracer(tracer_provider.tracer(software_name))
|
||||||
.with_filter(targets);
|
.with_filter(targets);
|
||||||
|
|
||||||
let subscriber = subscriber.with(otel_layer);
|
let subscriber = subscriber.with(otel_layer);
|
||||||
|
@ -418,7 +418,7 @@ async fn server_main(
|
||||||
.with_no_client_auth()
|
.with_no_client_auth()
|
||||||
.with_cert_resolver(cert_rx);
|
.with_cert_resolver(cert_rx);
|
||||||
server
|
server
|
||||||
.bind_rustls_0_22(bind_address, server_config)?
|
.bind_rustls_0_23(bind_address, server_config)?
|
||||||
.run()
|
.run()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|
|
@ -233,7 +233,11 @@ impl Requests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Err(ErrorKind::Status(parsed_url.to_string(), status).into());
|
return Err(ErrorKind::Status(
|
||||||
|
parsed_url.to_string(),
|
||||||
|
crate::http1::status_to_http02(status),
|
||||||
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
// only actually succeed a breaker on 2xx response
|
// only actually succeed a breaker on 2xx response
|
||||||
|
|
|
@ -23,10 +23,13 @@ pub(crate) async fn route(
|
||||||
.fetch_response(&url, BreakerStrategy::Allow404AndBelow)
|
.fetch_response(&url, BreakerStrategy::Allow404AndBelow)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let mut response = HttpResponse::build(res.status());
|
let mut response = HttpResponse::build(crate::http1::status_to_http02(res.status()));
|
||||||
|
|
||||||
for (name, value) in res.headers().iter().filter(|(h, _)| *h != "connection") {
|
for (name, value) in res.headers().iter().filter(|(h, _)| *h != "connection") {
|
||||||
response.insert_header((name.clone(), value.clone()));
|
response.insert_header((
|
||||||
|
crate::http1::name_to_http02(name),
|
||||||
|
crate::http1::value_to_http02(value),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(response.body(BodyStream::new(limit_stream(
|
return Ok(response.body(BodyStream::new(limit_stream(
|
||||||
|
|
|
@ -75,7 +75,8 @@ pub(crate) fn start(admin_handle: String, db: Db, token: &str) {
|
||||||
|
|
||||||
fn is_admin(admin_handle: &str, message: &Message) -> bool {
|
fn is_admin(admin_handle: &str, message: &Message) -> bool {
|
||||||
message
|
message
|
||||||
.from()
|
.from
|
||||||
|
.as_ref()
|
||||||
.and_then(|user| user.username.as_deref())
|
.and_then(|user| user.username.as_deref())
|
||||||
.map(|username| username == admin_handle)
|
.map(|username| username == admin_handle)
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
|
|
Loading…
Reference in a new issue