mirror of
https://git.asonix.dog/asonix/relay.git
synced 2024-11-25 11:01:11 +00:00
pub -> pub(crate)
This commit is contained in:
parent
50d2b5b21c
commit
2c275e441b
31 changed files with 86 additions and 104 deletions
1
.env
1
.env
|
@ -1 +0,0 @@
|
|||
DATABASE_URL=postgres://ap_actix:ap_actix@localhost:5432/ap_actix
|
10
src/args.rs
10
src/args.rs
|
@ -2,7 +2,7 @@ use structopt::StructOpt;
|
|||
|
||||
#[derive(Debug, StructOpt)]
|
||||
#[structopt(name = "relay", about = "An activitypub relay")]
|
||||
pub struct Args {
|
||||
pub(crate) struct Args {
|
||||
#[structopt(short, help = "A list of domains that should be blocked")]
|
||||
blocks: Vec<String>,
|
||||
|
||||
|
@ -14,19 +14,19 @@ pub struct Args {
|
|||
}
|
||||
|
||||
impl Args {
|
||||
pub fn new() -> Self {
|
||||
pub(crate) fn new() -> Self {
|
||||
Self::from_args()
|
||||
}
|
||||
|
||||
pub fn blocks(&self) -> &[String] {
|
||||
pub(crate) fn blocks(&self) -> &[String] {
|
||||
&self.blocks
|
||||
}
|
||||
|
||||
pub fn allowed(&self) -> &[String] {
|
||||
pub(crate) fn allowed(&self) -> &[String] {
|
||||
&self.allowed
|
||||
}
|
||||
|
||||
pub fn undo(&self) -> bool {
|
||||
pub(crate) fn undo(&self) -> bool {
|
||||
self.undo
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ use std::{net::IpAddr, path::PathBuf};
|
|||
use uuid::Uuid;
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize)]
|
||||
pub struct ParsedConfig {
|
||||
pub(crate) struct ParsedConfig {
|
||||
hostname: String,
|
||||
addr: IpAddr,
|
||||
port: u16,
|
||||
|
@ -20,10 +20,8 @@ pub struct ParsedConfig {
|
|||
restricted_mode: bool,
|
||||
validate_signatures: bool,
|
||||
https: bool,
|
||||
database_url: String,
|
||||
pretty_log: bool,
|
||||
publish_blocks: bool,
|
||||
max_connections: usize,
|
||||
sled_path: PathBuf,
|
||||
}
|
||||
|
||||
|
@ -35,10 +33,8 @@ pub struct Config {
|
|||
debug: bool,
|
||||
restricted_mode: bool,
|
||||
validate_signatures: bool,
|
||||
database_url: String,
|
||||
pretty_log: bool,
|
||||
publish_blocks: bool,
|
||||
max_connections: usize,
|
||||
base_uri: Url,
|
||||
sled_path: PathBuf,
|
||||
}
|
||||
|
@ -57,7 +53,7 @@ pub enum UrlKind {
|
|||
}
|
||||
|
||||
impl Config {
|
||||
pub fn build() -> Result<Self, MyError> {
|
||||
pub(crate) fn build() -> Result<Self, MyError> {
|
||||
let mut config = config::Config::new();
|
||||
config
|
||||
.set_default("hostname", "localhost:8080")?
|
||||
|
@ -69,7 +65,6 @@ impl Config {
|
|||
.set_default("https", false)?
|
||||
.set_default("pretty_log", true)?
|
||||
.set_default("publish_blocks", false)?
|
||||
.set_default("max_connections", 2)?
|
||||
.set_default("sled_path", "./sled/db-0-34")?
|
||||
.merge(Environment::new())?;
|
||||
|
||||
|
@ -85,32 +80,26 @@ impl Config {
|
|||
debug: config.debug,
|
||||
restricted_mode: config.restricted_mode,
|
||||
validate_signatures: config.validate_signatures,
|
||||
database_url: config.database_url,
|
||||
pretty_log: config.pretty_log,
|
||||
publish_blocks: config.publish_blocks,
|
||||
max_connections: config.max_connections,
|
||||
base_uri,
|
||||
sled_path: config.sled_path,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn sled_path(&self) -> &PathBuf {
|
||||
pub(crate) fn sled_path(&self) -> &PathBuf {
|
||||
&self.sled_path
|
||||
}
|
||||
|
||||
pub fn pretty_log(&self) -> bool {
|
||||
pub(crate) fn pretty_log(&self) -> bool {
|
||||
self.pretty_log
|
||||
}
|
||||
|
||||
pub fn max_connections(&self) -> usize {
|
||||
self.max_connections
|
||||
}
|
||||
|
||||
pub fn validate_signatures(&self) -> bool {
|
||||
pub(crate) fn validate_signatures(&self) -> bool {
|
||||
self.validate_signatures
|
||||
}
|
||||
|
||||
pub fn digest_middleware(&self) -> VerifyDigest<Sha256> {
|
||||
pub(crate) fn digest_middleware(&self) -> VerifyDigest<Sha256> {
|
||||
if self.validate_signatures {
|
||||
VerifyDigest::new(Sha256::new())
|
||||
} else {
|
||||
|
@ -118,7 +107,7 @@ impl Config {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn signature_middleware(
|
||||
pub(crate) fn signature_middleware(
|
||||
&self,
|
||||
requests: Requests,
|
||||
actors: ActorCache,
|
||||
|
@ -131,47 +120,43 @@ impl Config {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn bind_address(&self) -> (IpAddr, u16) {
|
||||
pub(crate) fn bind_address(&self) -> (IpAddr, u16) {
|
||||
(self.addr, self.port)
|
||||
}
|
||||
|
||||
pub fn debug(&self) -> bool {
|
||||
pub(crate) fn debug(&self) -> bool {
|
||||
self.debug
|
||||
}
|
||||
|
||||
pub fn publish_blocks(&self) -> bool {
|
||||
pub(crate) fn publish_blocks(&self) -> bool {
|
||||
self.publish_blocks
|
||||
}
|
||||
|
||||
pub fn restricted_mode(&self) -> bool {
|
||||
pub(crate) fn restricted_mode(&self) -> bool {
|
||||
self.restricted_mode
|
||||
}
|
||||
|
||||
pub fn database_url(&self) -> &str {
|
||||
&self.database_url
|
||||
}
|
||||
|
||||
pub fn hostname(&self) -> &str {
|
||||
pub(crate) fn hostname(&self) -> &str {
|
||||
&self.hostname
|
||||
}
|
||||
|
||||
pub fn generate_resource(&self) -> String {
|
||||
pub(crate) fn generate_resource(&self) -> String {
|
||||
format!("relay@{}", self.hostname)
|
||||
}
|
||||
|
||||
pub fn software_name(&self) -> String {
|
||||
pub(crate) fn software_name(&self) -> String {
|
||||
"AodeRelay".to_owned()
|
||||
}
|
||||
|
||||
pub fn software_version(&self) -> String {
|
||||
pub(crate) fn software_version(&self) -> String {
|
||||
"v0.2.0-main".to_owned()
|
||||
}
|
||||
|
||||
pub fn source_code(&self) -> String {
|
||||
pub(crate) fn source_code(&self) -> String {
|
||||
"https://git.asonix.dog/asonix/ap-relay".to_owned()
|
||||
}
|
||||
|
||||
pub fn generate_url(&self, kind: UrlKind) -> Url {
|
||||
pub(crate) fn generate_url(&self, kind: UrlKind) -> Url {
|
||||
let mut url = self.base_uri.clone();
|
||||
|
||||
match kind {
|
||||
|
|
|
@ -15,19 +15,19 @@ pub struct MediaCache {
|
|||
}
|
||||
|
||||
impl MediaCache {
|
||||
pub fn new(db: Db) -> Self {
|
||||
pub(crate) fn new(db: Db) -> Self {
|
||||
MediaCache { db }
|
||||
}
|
||||
|
||||
pub async fn get_uuid(&self, url: Url) -> Result<Option<Uuid>, MyError> {
|
||||
pub(crate) async fn get_uuid(&self, url: Url) -> Result<Option<Uuid>, MyError> {
|
||||
self.db.media_id(url).await
|
||||
}
|
||||
|
||||
pub async fn get_url(&self, uuid: Uuid) -> Result<Option<Url>, MyError> {
|
||||
pub(crate) async fn get_url(&self, uuid: Uuid) -> Result<Option<Url>, MyError> {
|
||||
self.db.media_url(uuid).await
|
||||
}
|
||||
|
||||
pub async fn is_outdated(&self, uuid: Uuid) -> Result<bool, MyError> {
|
||||
pub(crate) async fn is_outdated(&self, uuid: Uuid) -> Result<bool, MyError> {
|
||||
if let Some(meta) = self.db.media_meta(uuid).await? {
|
||||
if meta.saved_at + MEDIA_DURATION > SystemTime::now() {
|
||||
return Ok(false);
|
||||
|
@ -37,7 +37,7 @@ impl MediaCache {
|
|||
Ok(true)
|
||||
}
|
||||
|
||||
pub async fn get_bytes(&self, uuid: Uuid) -> Result<Option<(String, Bytes)>, MyError> {
|
||||
pub(crate) async fn get_bytes(&self, uuid: Uuid) -> Result<Option<(String, Bytes)>, MyError> {
|
||||
if let Some(meta) = self.db.media_meta(uuid).await? {
|
||||
if meta.saved_at + MEDIA_DURATION > SystemTime::now() {
|
||||
return self
|
||||
|
@ -51,7 +51,7 @@ impl MediaCache {
|
|||
Ok(None)
|
||||
}
|
||||
|
||||
pub async fn store_url(&self, url: Url) -> Result<Uuid, MyError> {
|
||||
pub(crate) async fn store_url(&self, url: Url) -> Result<Uuid, MyError> {
|
||||
let uuid = Uuid::new_v4();
|
||||
|
||||
self.db.save_url(url, uuid).await?;
|
||||
|
@ -59,7 +59,7 @@ impl MediaCache {
|
|||
Ok(uuid)
|
||||
}
|
||||
|
||||
pub async fn store_bytes(
|
||||
pub(crate) async fn store_bytes(
|
||||
&self,
|
||||
uuid: Uuid,
|
||||
media_type: String,
|
||||
|
|
|
@ -8,7 +8,7 @@ use std::{collections::HashMap, sync::Arc, time::SystemTime};
|
|||
use uuid::Uuid;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Db {
|
||||
pub(crate) struct Db {
|
||||
inner: Arc<Inner>,
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ pub struct Actor {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct MediaMeta {
|
||||
pub(crate) struct MediaMeta {
|
||||
pub(crate) media_type: String,
|
||||
pub(crate) saved_at: SystemTime,
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ use rsa_pem::KeyError;
|
|||
use std::{convert::Infallible, fmt::Debug, io::Error};
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum MyError {
|
||||
pub(crate) enum MyError {
|
||||
#[error("Error queueing job, {0}")]
|
||||
Queue(anyhow::Error),
|
||||
|
||||
|
@ -89,9 +89,6 @@ pub enum MyError {
|
|||
#[error("Response from {0} has invalid status code, {1}")]
|
||||
Status(String, StatusCode),
|
||||
|
||||
#[error("Uri {0} is missing host")]
|
||||
Host(String),
|
||||
|
||||
#[error("Expected an Object, found something else")]
|
||||
ObjectFormat,
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ use background_jobs::ActixJob;
|
|||
use std::{future::Future, pin::Pin};
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct Announce {
|
||||
pub(crate) struct Announce {
|
||||
object_id: Url,
|
||||
actor: Actor,
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ use background_jobs::ActixJob;
|
|||
use std::{future::Future, pin::Pin};
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct Follow {
|
||||
pub(crate) struct Follow {
|
||||
is_listener: bool,
|
||||
input: AcceptedActivities,
|
||||
actor: Actor,
|
||||
|
|
|
@ -9,7 +9,7 @@ use background_jobs::ActixJob;
|
|||
use std::{future::Future, pin::Pin};
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct Forward {
|
||||
pub(crate) struct Forward {
|
||||
input: AcceptedActivities,
|
||||
actor: Actor,
|
||||
}
|
||||
|
|
|
@ -19,7 +19,9 @@ mod forward;
|
|||
mod reject;
|
||||
mod undo;
|
||||
|
||||
pub use self::{announce::Announce, follow::Follow, forward::Forward, reject::Reject, undo::Undo};
|
||||
pub(crate) use self::{
|
||||
announce::Announce, follow::Follow, forward::Forward, reject::Reject, undo::Undo,
|
||||
};
|
||||
|
||||
async fn get_inboxes(state: &State, actor: &Actor, object_id: &Url) -> Result<Vec<Url>, MyError> {
|
||||
let domain = object_id.host().ok_or(MyError::Domain)?.to_string();
|
||||
|
|
|
@ -7,7 +7,7 @@ use background_jobs::ActixJob;
|
|||
use std::{future::Future, pin::Pin};
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct Reject(pub Actor);
|
||||
pub(crate) struct Reject(pub(crate) Actor);
|
||||
|
||||
impl Reject {
|
||||
async fn perform(self, state: JobState) -> Result<(), anyhow::Error> {
|
||||
|
|
|
@ -8,13 +8,13 @@ use background_jobs::ActixJob;
|
|||
use std::{future::Future, pin::Pin};
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct Undo {
|
||||
pub(crate) struct Undo {
|
||||
input: AcceptedActivities,
|
||||
actor: Actor,
|
||||
}
|
||||
|
||||
impl Undo {
|
||||
pub fn new(input: AcceptedActivities, actor: Actor) -> Self {
|
||||
pub(crate) fn new(input: AcceptedActivities, actor: Actor) -> Self {
|
||||
Undo { input, actor }
|
||||
}
|
||||
|
||||
|
|
|
@ -5,12 +5,12 @@ use std::{future::Future, pin::Pin};
|
|||
use uuid::Uuid;
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct CacheMedia {
|
||||
pub(crate) struct CacheMedia {
|
||||
uuid: Uuid,
|
||||
}
|
||||
|
||||
impl CacheMedia {
|
||||
pub fn new(uuid: Uuid) -> Self {
|
||||
pub(crate) fn new(uuid: Uuid) -> Self {
|
||||
CacheMedia { uuid }
|
||||
}
|
||||
|
||||
|
|
|
@ -5,13 +5,13 @@ use background_jobs::{ActixJob, Backoff};
|
|||
use std::{future::Future, pin::Pin};
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct Deliver {
|
||||
pub(crate) struct Deliver {
|
||||
to: Url,
|
||||
data: serde_json::Value,
|
||||
}
|
||||
|
||||
impl Deliver {
|
||||
pub fn new<T>(to: Url, data: T) -> Result<Self, MyError>
|
||||
pub(crate) fn new<T>(to: Url, data: T) -> Result<Self, MyError>
|
||||
where
|
||||
T: serde::ser::Serialize,
|
||||
{
|
||||
|
|
|
@ -8,13 +8,13 @@ use background_jobs::ActixJob;
|
|||
use futures::future::{ready, Ready};
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct DeliverMany {
|
||||
pub(crate) struct DeliverMany {
|
||||
to: Vec<Url>,
|
||||
data: serde_json::Value,
|
||||
}
|
||||
|
||||
impl DeliverMany {
|
||||
pub fn new<T>(to: Vec<Url>, data: T) -> Result<Self, MyError>
|
||||
pub(crate) fn new<T>(to: Vec<Url>, data: T) -> Result<Self, MyError>
|
||||
where
|
||||
T: serde::ser::Serialize,
|
||||
{
|
||||
|
|
|
@ -8,12 +8,12 @@ use background_jobs::ActixJob;
|
|||
use std::{future::Future, pin::Pin};
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct QueryInstance {
|
||||
pub(crate) struct QueryInstance {
|
||||
actor_id: Url,
|
||||
}
|
||||
|
||||
impl QueryInstance {
|
||||
pub fn new(actor_id: Url) -> Self {
|
||||
pub(crate) fn new(actor_id: Url) -> Self {
|
||||
QueryInstance {
|
||||
actor_id: actor_id.into(),
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ mod instance;
|
|||
mod nodeinfo;
|
||||
mod process_listeners;
|
||||
|
||||
pub use self::{
|
||||
pub(crate) use self::{
|
||||
cache_media::CacheMedia, deliver::Deliver, deliver_many::DeliverMany, instance::QueryInstance,
|
||||
nodeinfo::QueryNodeinfo,
|
||||
};
|
||||
|
@ -22,7 +22,7 @@ use crate::{
|
|||
use background_jobs::{memory_storage::Storage, Job, QueueHandle, WorkerConfig};
|
||||
use std::time::Duration;
|
||||
|
||||
pub fn create_server() -> JobServer {
|
||||
pub(crate) fn create_server() -> JobServer {
|
||||
let shared = background_jobs::create_server(Storage::new());
|
||||
|
||||
shared.every(Duration::from_secs(60 * 5), Listeners);
|
||||
|
@ -30,7 +30,7 @@ pub fn create_server() -> JobServer {
|
|||
JobServer::new(shared)
|
||||
}
|
||||
|
||||
pub fn create_workers(
|
||||
pub(crate) fn create_workers(
|
||||
db: Db,
|
||||
state: State,
|
||||
actors: ActorCache,
|
||||
|
@ -66,7 +66,7 @@ pub fn create_workers(
|
|||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct JobState {
|
||||
pub(crate) struct JobState {
|
||||
db: Db,
|
||||
requests: Requests,
|
||||
state: State,
|
||||
|
@ -78,7 +78,7 @@ pub struct JobState {
|
|||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct JobServer {
|
||||
pub(crate) struct JobServer {
|
||||
remote: QueueHandle,
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ impl JobServer {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn queue<J>(&self, job: J) -> Result<(), MyError>
|
||||
pub(crate) fn queue<J>(&self, job: J) -> Result<(), MyError>
|
||||
where
|
||||
J: Job,
|
||||
{
|
||||
|
|
|
@ -5,12 +5,12 @@ use background_jobs::ActixJob;
|
|||
use std::{future::Future, pin::Pin};
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct QueryNodeinfo {
|
||||
pub(crate) struct QueryNodeinfo {
|
||||
actor_id: Url,
|
||||
}
|
||||
|
||||
impl QueryNodeinfo {
|
||||
pub fn new(actor_id: Url) -> Self {
|
||||
pub(crate) fn new(actor_id: Url) -> Self {
|
||||
QueryNodeinfo { actor_id }
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ use background_jobs::ActixJob;
|
|||
use std::{future::Future, pin::Pin};
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct Listeners;
|
||||
pub(crate) struct Listeners;
|
||||
|
||||
impl Listeners {
|
||||
async fn perform(self, state: JobState) -> Result<(), Error> {
|
||||
|
|
|
@ -2,6 +2,6 @@ mod payload;
|
|||
mod verifier;
|
||||
mod webfinger;
|
||||
|
||||
pub use payload::DebugPayload;
|
||||
pub use verifier::MyVerify;
|
||||
pub use webfinger::RelayResolver;
|
||||
pub(crate) use payload::DebugPayload;
|
||||
pub(crate) use verifier::MyVerify;
|
||||
pub(crate) use webfinger::RelayResolver;
|
||||
|
|
|
@ -14,15 +14,15 @@ use log::{error, info};
|
|||
use std::task::{Context, Poll};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct DebugPayload(pub bool);
|
||||
pub(crate) struct DebugPayload(pub bool);
|
||||
|
||||
#[doc(hidden)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct DebugPayloadMiddleware<S>(bool, S);
|
||||
pub(crate) struct DebugPayloadMiddleware<S>(bool, S);
|
||||
|
||||
#[derive(Clone, Debug, thiserror::Error)]
|
||||
#[error("Failed to read payload")]
|
||||
pub struct DebugError;
|
||||
pub(crate) struct DebugError;
|
||||
|
||||
impl ResponseError for DebugError {
|
||||
fn status_code(&self) -> StatusCode {
|
||||
|
|
|
@ -14,7 +14,7 @@ use sha2::{Digest, Sha256};
|
|||
use std::{future::Future, pin::Pin};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct MyVerify(pub Requests, pub ActorCache, pub State);
|
||||
pub(crate) struct MyVerify(pub Requests, pub ActorCache, pub State);
|
||||
|
||||
impl MyVerify {
|
||||
async fn verify(
|
||||
|
|
|
@ -7,11 +7,11 @@ use actix_webfinger::{Resolver, Webfinger};
|
|||
use rsa_magic_public_key::AsMagicPublicKey;
|
||||
use std::{future::Future, pin::Pin};
|
||||
|
||||
pub struct RelayResolver;
|
||||
pub(crate) struct RelayResolver;
|
||||
|
||||
#[derive(Clone, Debug, thiserror::Error)]
|
||||
#[error("Error resolving webfinger data")]
|
||||
pub struct RelayError;
|
||||
pub(crate) struct RelayError;
|
||||
|
||||
type FutResult<T, E> = dyn Future<Output = Result<T, E>>;
|
||||
|
||||
|
|
|
@ -20,15 +20,11 @@ use std::{
|
|||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Breakers {
|
||||
pub(crate) struct Breakers {
|
||||
inner: Arc<RwLock<HashMap<String, Arc<Mutex<Breaker>>>>>,
|
||||
}
|
||||
|
||||
impl Breakers {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
async fn should_try(&self, url: &Url) -> bool {
|
||||
if let Some(domain) = url.domain() {
|
||||
if let Some(breaker) = self.inner.read().await.get(domain) {
|
||||
|
@ -127,7 +123,7 @@ impl Default for Breaker {
|
|||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Requests {
|
||||
pub(crate) struct Requests {
|
||||
client: Rc<RefCell<Client>>,
|
||||
consecutive_errors: Rc<AtomicUsize>,
|
||||
error_limit: usize,
|
||||
|
@ -139,7 +135,7 @@ pub struct Requests {
|
|||
}
|
||||
|
||||
impl Requests {
|
||||
pub fn new(
|
||||
pub(crate) fn new(
|
||||
key_id: String,
|
||||
private_key: RSAPrivateKey,
|
||||
user_agent: String,
|
||||
|
@ -176,14 +172,14 @@ impl Requests {
|
|||
self.consecutive_errors.swap(0, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
pub async fn fetch_json<T>(&self, url: &str) -> Result<T, MyError>
|
||||
pub(crate) async fn fetch_json<T>(&self, url: &str) -> Result<T, MyError>
|
||||
where
|
||||
T: serde::de::DeserializeOwned,
|
||||
{
|
||||
self.do_fetch(url, "application/json").await
|
||||
}
|
||||
|
||||
pub async fn fetch<T>(&self, url: &str) -> Result<T, MyError>
|
||||
pub(crate) async fn fetch<T>(&self, url: &str) -> Result<T, MyError>
|
||||
where
|
||||
T: serde::de::DeserializeOwned,
|
||||
{
|
||||
|
@ -249,7 +245,7 @@ impl Requests {
|
|||
Ok(serde_json::from_slice(body.as_ref())?)
|
||||
}
|
||||
|
||||
pub async fn fetch_bytes(&self, url: &str) -> Result<(String, Bytes), MyError> {
|
||||
pub(crate) async fn fetch_bytes(&self, url: &str) -> Result<(String, Bytes), MyError> {
|
||||
let parsed_url = url.parse::<Url>()?;
|
||||
|
||||
if !self.breakers.should_try(&parsed_url).await {
|
||||
|
@ -318,7 +314,7 @@ impl Requests {
|
|||
Ok((content_type, bytes))
|
||||
}
|
||||
|
||||
pub async fn deliver<T>(&self, inbox: Url, item: &T) -> Result<(), MyError>
|
||||
pub(crate) async fn deliver<T>(&self, inbox: Url, item: &T) -> Result<(), MyError>
|
||||
where
|
||||
T: serde::ser::Serialize,
|
||||
{
|
||||
|
|
|
@ -5,17 +5,17 @@ use crate::{
|
|||
error::MyError,
|
||||
routes::ok,
|
||||
};
|
||||
use activitystreams_ext::Ext1;
|
||||
use activitystreams::{
|
||||
actor::{ApActor, Application, Endpoints},
|
||||
context,
|
||||
prelude::*,
|
||||
security,
|
||||
};
|
||||
use activitystreams_ext::Ext1;
|
||||
use actix_web::{web, Responder};
|
||||
use rsa_pem::KeyExt;
|
||||
|
||||
pub async fn route(
|
||||
pub(crate) async fn route(
|
||||
state: web::Data<State>,
|
||||
config: web::Data<Config>,
|
||||
) -> Result<impl Responder, MyError> {
|
||||
|
|
|
@ -16,7 +16,7 @@ use actix_web::{web, HttpResponse};
|
|||
use http_signature_normalization_actix::prelude::{DigestVerified, SignatureVerified};
|
||||
use log::error;
|
||||
|
||||
pub async fn route(
|
||||
pub(crate) async fn route(
|
||||
state: web::Data<State>,
|
||||
actors: web::Data<ActorCache>,
|
||||
config: web::Data<Config>,
|
||||
|
|
|
@ -4,7 +4,7 @@ use log::error;
|
|||
use rand::{seq::SliceRandom, thread_rng};
|
||||
use std::io::BufWriter;
|
||||
|
||||
pub async fn route(
|
||||
pub(crate) async fn route(
|
||||
state: web::Data<State>,
|
||||
config: web::Data<Config>,
|
||||
) -> Result<HttpResponse, MyError> {
|
||||
|
|
|
@ -5,7 +5,7 @@ use actix_web::{
|
|||
};
|
||||
use uuid::Uuid;
|
||||
|
||||
pub async fn route(
|
||||
pub(crate) async fn route(
|
||||
media: web::Data<MediaCache>,
|
||||
requests: web::Data<Requests>,
|
||||
uuid: web::Path<Uuid>,
|
||||
|
|
|
@ -5,7 +5,7 @@ mod media;
|
|||
mod nodeinfo;
|
||||
mod statics;
|
||||
|
||||
pub use self::{
|
||||
pub(crate) use self::{
|
||||
actor::route as actor,
|
||||
inbox::route as inbox,
|
||||
index::route as index,
|
||||
|
|
|
@ -5,7 +5,7 @@ use crate::{
|
|||
use actix_web::{web, Responder};
|
||||
use actix_webfinger::Link;
|
||||
|
||||
pub async fn well_known(config: web::Data<Config>) -> impl Responder {
|
||||
pub(crate) async fn well_known(config: web::Data<Config>) -> impl Responder {
|
||||
web::Json(Links {
|
||||
links: vec![Link {
|
||||
rel: "http://nodeinfo.diaspora.software/ns/schema/2.0".to_owned(),
|
||||
|
@ -22,7 +22,10 @@ struct Links {
|
|||
links: Vec<Link>,
|
||||
}
|
||||
|
||||
pub async fn route(config: web::Data<Config>, state: web::Data<State>) -> web::Json<NodeInfo> {
|
||||
pub(crate) async fn route(
|
||||
config: web::Data<Config>,
|
||||
state: web::Data<State>,
|
||||
) -> web::Json<NodeInfo> {
|
||||
web::Json(NodeInfo {
|
||||
version: NodeInfoVersion,
|
||||
software: Software {
|
||||
|
|
|
@ -4,7 +4,7 @@ use actix_web::{
|
|||
web, HttpResponse,
|
||||
};
|
||||
|
||||
pub async fn route(filename: web::Path<String>) -> HttpResponse {
|
||||
pub(crate) async fn route(filename: web::Path<String>) -> HttpResponse {
|
||||
if let Some(data) = StaticFile::get(&filename.into_inner()) {
|
||||
HttpResponse::Ok()
|
||||
.set(CacheControl(vec![
|
||||
|
|
Loading…
Reference in a new issue