pub -> pub(crate)

This commit is contained in:
asonix 2021-02-09 22:17:20 -06:00
parent 50d2b5b21c
commit 2c275e441b
31 changed files with 86 additions and 104 deletions

1
.env
View file

@ -1 +0,0 @@
DATABASE_URL=postgres://ap_actix:ap_actix@localhost:5432/ap_actix

View file

@ -2,7 +2,7 @@ use structopt::StructOpt;
#[derive(Debug, StructOpt)] #[derive(Debug, StructOpt)]
#[structopt(name = "relay", about = "An activitypub relay")] #[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")] #[structopt(short, help = "A list of domains that should be blocked")]
blocks: Vec<String>, blocks: Vec<String>,
@ -14,19 +14,19 @@ pub struct Args {
} }
impl Args { impl Args {
pub fn new() -> Self { pub(crate) fn new() -> Self {
Self::from_args() Self::from_args()
} }
pub fn blocks(&self) -> &[String] { pub(crate) fn blocks(&self) -> &[String] {
&self.blocks &self.blocks
} }
pub fn allowed(&self) -> &[String] { pub(crate) fn allowed(&self) -> &[String] {
&self.allowed &self.allowed
} }
pub fn undo(&self) -> bool { pub(crate) fn undo(&self) -> bool {
self.undo self.undo
} }
} }

View file

@ -12,7 +12,7 @@ use std::{net::IpAddr, path::PathBuf};
use uuid::Uuid; use uuid::Uuid;
#[derive(Clone, Debug, serde::Deserialize)] #[derive(Clone, Debug, serde::Deserialize)]
pub struct ParsedConfig { pub(crate) struct ParsedConfig {
hostname: String, hostname: String,
addr: IpAddr, addr: IpAddr,
port: u16, port: u16,
@ -20,10 +20,8 @@ pub struct ParsedConfig {
restricted_mode: bool, restricted_mode: bool,
validate_signatures: bool, validate_signatures: bool,
https: bool, https: bool,
database_url: String,
pretty_log: bool, pretty_log: bool,
publish_blocks: bool, publish_blocks: bool,
max_connections: usize,
sled_path: PathBuf, sled_path: PathBuf,
} }
@ -35,10 +33,8 @@ pub struct Config {
debug: bool, debug: bool,
restricted_mode: bool, restricted_mode: bool,
validate_signatures: bool, validate_signatures: bool,
database_url: String,
pretty_log: bool, pretty_log: bool,
publish_blocks: bool, publish_blocks: bool,
max_connections: usize,
base_uri: Url, base_uri: Url,
sled_path: PathBuf, sled_path: PathBuf,
} }
@ -57,7 +53,7 @@ pub enum UrlKind {
} }
impl Config { impl Config {
pub fn build() -> Result<Self, MyError> { pub(crate) fn build() -> Result<Self, MyError> {
let mut config = config::Config::new(); let mut config = config::Config::new();
config config
.set_default("hostname", "localhost:8080")? .set_default("hostname", "localhost:8080")?
@ -69,7 +65,6 @@ impl Config {
.set_default("https", false)? .set_default("https", false)?
.set_default("pretty_log", true)? .set_default("pretty_log", true)?
.set_default("publish_blocks", false)? .set_default("publish_blocks", false)?
.set_default("max_connections", 2)?
.set_default("sled_path", "./sled/db-0-34")? .set_default("sled_path", "./sled/db-0-34")?
.merge(Environment::new())?; .merge(Environment::new())?;
@ -85,32 +80,26 @@ impl Config {
debug: config.debug, debug: config.debug,
restricted_mode: config.restricted_mode, restricted_mode: config.restricted_mode,
validate_signatures: config.validate_signatures, validate_signatures: config.validate_signatures,
database_url: config.database_url,
pretty_log: config.pretty_log, pretty_log: config.pretty_log,
publish_blocks: config.publish_blocks, publish_blocks: config.publish_blocks,
max_connections: config.max_connections,
base_uri, base_uri,
sled_path: config.sled_path, sled_path: config.sled_path,
}) })
} }
pub fn sled_path(&self) -> &PathBuf { pub(crate) fn sled_path(&self) -> &PathBuf {
&self.sled_path &self.sled_path
} }
pub fn pretty_log(&self) -> bool { pub(crate) fn pretty_log(&self) -> bool {
self.pretty_log self.pretty_log
} }
pub fn max_connections(&self) -> usize { pub(crate) fn validate_signatures(&self) -> bool {
self.max_connections
}
pub fn validate_signatures(&self) -> bool {
self.validate_signatures self.validate_signatures
} }
pub fn digest_middleware(&self) -> VerifyDigest<Sha256> { pub(crate) fn digest_middleware(&self) -> VerifyDigest<Sha256> {
if self.validate_signatures { if self.validate_signatures {
VerifyDigest::new(Sha256::new()) VerifyDigest::new(Sha256::new())
} else { } else {
@ -118,7 +107,7 @@ impl Config {
} }
} }
pub fn signature_middleware( pub(crate) fn signature_middleware(
&self, &self,
requests: Requests, requests: Requests,
actors: ActorCache, 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) (self.addr, self.port)
} }
pub fn debug(&self) -> bool { pub(crate) fn debug(&self) -> bool {
self.debug self.debug
} }
pub fn publish_blocks(&self) -> bool { pub(crate) fn publish_blocks(&self) -> bool {
self.publish_blocks self.publish_blocks
} }
pub fn restricted_mode(&self) -> bool { pub(crate) fn restricted_mode(&self) -> bool {
self.restricted_mode self.restricted_mode
} }
pub fn database_url(&self) -> &str { pub(crate) fn hostname(&self) -> &str {
&self.database_url
}
pub fn hostname(&self) -> &str {
&self.hostname &self.hostname
} }
pub fn generate_resource(&self) -> String { pub(crate) fn generate_resource(&self) -> String {
format!("relay@{}", self.hostname) format!("relay@{}", self.hostname)
} }
pub fn software_name(&self) -> String { pub(crate) fn software_name(&self) -> String {
"AodeRelay".to_owned() "AodeRelay".to_owned()
} }
pub fn software_version(&self) -> String { pub(crate) fn software_version(&self) -> String {
"v0.2.0-main".to_owned() "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() "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(); let mut url = self.base_uri.clone();
match kind { match kind {

View file

@ -15,19 +15,19 @@ pub struct MediaCache {
} }
impl MediaCache { impl MediaCache {
pub fn new(db: Db) -> Self { pub(crate) fn new(db: Db) -> Self {
MediaCache { db } 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 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 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 let Some(meta) = self.db.media_meta(uuid).await? {
if meta.saved_at + MEDIA_DURATION > SystemTime::now() { if meta.saved_at + MEDIA_DURATION > SystemTime::now() {
return Ok(false); return Ok(false);
@ -37,7 +37,7 @@ impl MediaCache {
Ok(true) 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 let Some(meta) = self.db.media_meta(uuid).await? {
if meta.saved_at + MEDIA_DURATION > SystemTime::now() { if meta.saved_at + MEDIA_DURATION > SystemTime::now() {
return self return self
@ -51,7 +51,7 @@ impl MediaCache {
Ok(None) 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(); let uuid = Uuid::new_v4();
self.db.save_url(url, uuid).await?; self.db.save_url(url, uuid).await?;
@ -59,7 +59,7 @@ impl MediaCache {
Ok(uuid) Ok(uuid)
} }
pub async fn store_bytes( pub(crate) async fn store_bytes(
&self, &self,
uuid: Uuid, uuid: Uuid,
media_type: String, media_type: String,

View file

@ -8,7 +8,7 @@ use std::{collections::HashMap, sync::Arc, time::SystemTime};
use uuid::Uuid; use uuid::Uuid;
#[derive(Clone)] #[derive(Clone)]
pub struct Db { pub(crate) struct Db {
inner: Arc<Inner>, inner: Arc<Inner>,
} }
@ -39,7 +39,7 @@ pub struct Actor {
} }
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct MediaMeta { pub(crate) struct MediaMeta {
pub(crate) media_type: String, pub(crate) media_type: String,
pub(crate) saved_at: SystemTime, pub(crate) saved_at: SystemTime,
} }

View file

@ -10,7 +10,7 @@ use rsa_pem::KeyError;
use std::{convert::Infallible, fmt::Debug, io::Error}; use std::{convert::Infallible, fmt::Debug, io::Error};
#[derive(Debug, thiserror::Error)] #[derive(Debug, thiserror::Error)]
pub enum MyError { pub(crate) enum MyError {
#[error("Error queueing job, {0}")] #[error("Error queueing job, {0}")]
Queue(anyhow::Error), Queue(anyhow::Error),
@ -89,9 +89,6 @@ pub enum MyError {
#[error("Response from {0} has invalid status code, {1}")] #[error("Response from {0} has invalid status code, {1}")]
Status(String, StatusCode), Status(String, StatusCode),
#[error("Uri {0} is missing host")]
Host(String),
#[error("Expected an Object, found something else")] #[error("Expected an Object, found something else")]
ObjectFormat, ObjectFormat,

View file

@ -12,7 +12,7 @@ use background_jobs::ActixJob;
use std::{future::Future, pin::Pin}; use std::{future::Future, pin::Pin};
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct Announce { pub(crate) struct Announce {
object_id: Url, object_id: Url,
actor: Actor, actor: Actor,
} }

View file

@ -14,7 +14,7 @@ use background_jobs::ActixJob;
use std::{future::Future, pin::Pin}; use std::{future::Future, pin::Pin};
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct Follow { pub(crate) struct Follow {
is_listener: bool, is_listener: bool,
input: AcceptedActivities, input: AcceptedActivities,
actor: Actor, actor: Actor,

View file

@ -9,7 +9,7 @@ use background_jobs::ActixJob;
use std::{future::Future, pin::Pin}; use std::{future::Future, pin::Pin};
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct Forward { pub(crate) struct Forward {
input: AcceptedActivities, input: AcceptedActivities,
actor: Actor, actor: Actor,
} }

View file

@ -19,7 +19,9 @@ mod forward;
mod reject; mod reject;
mod undo; 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> { 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(); let domain = object_id.host().ok_or(MyError::Domain)?.to_string();

View file

@ -7,7 +7,7 @@ use background_jobs::ActixJob;
use std::{future::Future, pin::Pin}; use std::{future::Future, pin::Pin};
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct Reject(pub Actor); pub(crate) struct Reject(pub(crate) Actor);
impl Reject { impl Reject {
async fn perform(self, state: JobState) -> Result<(), anyhow::Error> { async fn perform(self, state: JobState) -> Result<(), anyhow::Error> {

View file

@ -8,13 +8,13 @@ use background_jobs::ActixJob;
use std::{future::Future, pin::Pin}; use std::{future::Future, pin::Pin};
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct Undo { pub(crate) struct Undo {
input: AcceptedActivities, input: AcceptedActivities,
actor: Actor, actor: Actor,
} }
impl Undo { impl Undo {
pub fn new(input: AcceptedActivities, actor: Actor) -> Self { pub(crate) fn new(input: AcceptedActivities, actor: Actor) -> Self {
Undo { input, actor } Undo { input, actor }
} }

View file

@ -5,12 +5,12 @@ use std::{future::Future, pin::Pin};
use uuid::Uuid; use uuid::Uuid;
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct CacheMedia { pub(crate) struct CacheMedia {
uuid: Uuid, uuid: Uuid,
} }
impl CacheMedia { impl CacheMedia {
pub fn new(uuid: Uuid) -> Self { pub(crate) fn new(uuid: Uuid) -> Self {
CacheMedia { uuid } CacheMedia { uuid }
} }

View file

@ -5,13 +5,13 @@ use background_jobs::{ActixJob, Backoff};
use std::{future::Future, pin::Pin}; use std::{future::Future, pin::Pin};
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct Deliver { pub(crate) struct Deliver {
to: Url, to: Url,
data: serde_json::Value, data: serde_json::Value,
} }
impl Deliver { 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 where
T: serde::ser::Serialize, T: serde::ser::Serialize,
{ {

View file

@ -8,13 +8,13 @@ use background_jobs::ActixJob;
use futures::future::{ready, Ready}; use futures::future::{ready, Ready};
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct DeliverMany { pub(crate) struct DeliverMany {
to: Vec<Url>, to: Vec<Url>,
data: serde_json::Value, data: serde_json::Value,
} }
impl DeliverMany { 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 where
T: serde::ser::Serialize, T: serde::ser::Serialize,
{ {

View file

@ -8,12 +8,12 @@ use background_jobs::ActixJob;
use std::{future::Future, pin::Pin}; use std::{future::Future, pin::Pin};
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct QueryInstance { pub(crate) struct QueryInstance {
actor_id: Url, actor_id: Url,
} }
impl QueryInstance { impl QueryInstance {
pub fn new(actor_id: Url) -> Self { pub(crate) fn new(actor_id: Url) -> Self {
QueryInstance { QueryInstance {
actor_id: actor_id.into(), actor_id: actor_id.into(),
} }

View file

@ -6,7 +6,7 @@ mod instance;
mod nodeinfo; mod nodeinfo;
mod process_listeners; mod process_listeners;
pub use self::{ pub(crate) use self::{
cache_media::CacheMedia, deliver::Deliver, deliver_many::DeliverMany, instance::QueryInstance, cache_media::CacheMedia, deliver::Deliver, deliver_many::DeliverMany, instance::QueryInstance,
nodeinfo::QueryNodeinfo, nodeinfo::QueryNodeinfo,
}; };
@ -22,7 +22,7 @@ use crate::{
use background_jobs::{memory_storage::Storage, Job, QueueHandle, WorkerConfig}; use background_jobs::{memory_storage::Storage, Job, QueueHandle, WorkerConfig};
use std::time::Duration; use std::time::Duration;
pub fn create_server() -> JobServer { pub(crate) fn create_server() -> JobServer {
let shared = background_jobs::create_server(Storage::new()); let shared = background_jobs::create_server(Storage::new());
shared.every(Duration::from_secs(60 * 5), Listeners); shared.every(Duration::from_secs(60 * 5), Listeners);
@ -30,7 +30,7 @@ pub fn create_server() -> JobServer {
JobServer::new(shared) JobServer::new(shared)
} }
pub fn create_workers( pub(crate) fn create_workers(
db: Db, db: Db,
state: State, state: State,
actors: ActorCache, actors: ActorCache,
@ -66,7 +66,7 @@ pub fn create_workers(
} }
#[derive(Clone)] #[derive(Clone)]
pub struct JobState { pub(crate) struct JobState {
db: Db, db: Db,
requests: Requests, requests: Requests,
state: State, state: State,
@ -78,7 +78,7 @@ pub struct JobState {
} }
#[derive(Clone)] #[derive(Clone)]
pub struct JobServer { pub(crate) struct JobServer {
remote: QueueHandle, 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 where
J: Job, J: Job,
{ {

View file

@ -5,12 +5,12 @@ use background_jobs::ActixJob;
use std::{future::Future, pin::Pin}; use std::{future::Future, pin::Pin};
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct QueryNodeinfo { pub(crate) struct QueryNodeinfo {
actor_id: Url, actor_id: Url,
} }
impl QueryNodeinfo { impl QueryNodeinfo {
pub fn new(actor_id: Url) -> Self { pub(crate) fn new(actor_id: Url) -> Self {
QueryNodeinfo { actor_id } QueryNodeinfo { actor_id }
} }

View file

@ -4,7 +4,7 @@ use background_jobs::ActixJob;
use std::{future::Future, pin::Pin}; use std::{future::Future, pin::Pin};
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct Listeners; pub(crate) struct Listeners;
impl Listeners { impl Listeners {
async fn perform(self, state: JobState) -> Result<(), Error> { async fn perform(self, state: JobState) -> Result<(), Error> {

View file

@ -2,6 +2,6 @@ mod payload;
mod verifier; mod verifier;
mod webfinger; mod webfinger;
pub use payload::DebugPayload; pub(crate) use payload::DebugPayload;
pub use verifier::MyVerify; pub(crate) use verifier::MyVerify;
pub use webfinger::RelayResolver; pub(crate) use webfinger::RelayResolver;

View file

@ -14,15 +14,15 @@ use log::{error, info};
use std::task::{Context, Poll}; use std::task::{Context, Poll};
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct DebugPayload(pub bool); pub(crate) struct DebugPayload(pub bool);
#[doc(hidden)] #[doc(hidden)]
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct DebugPayloadMiddleware<S>(bool, S); pub(crate) struct DebugPayloadMiddleware<S>(bool, S);
#[derive(Clone, Debug, thiserror::Error)] #[derive(Clone, Debug, thiserror::Error)]
#[error("Failed to read payload")] #[error("Failed to read payload")]
pub struct DebugError; pub(crate) struct DebugError;
impl ResponseError for DebugError { impl ResponseError for DebugError {
fn status_code(&self) -> StatusCode { fn status_code(&self) -> StatusCode {

View file

@ -14,7 +14,7 @@ use sha2::{Digest, Sha256};
use std::{future::Future, pin::Pin}; use std::{future::Future, pin::Pin};
#[derive(Clone)] #[derive(Clone)]
pub struct MyVerify(pub Requests, pub ActorCache, pub State); pub(crate) struct MyVerify(pub Requests, pub ActorCache, pub State);
impl MyVerify { impl MyVerify {
async fn verify( async fn verify(

View file

@ -7,11 +7,11 @@ use actix_webfinger::{Resolver, Webfinger};
use rsa_magic_public_key::AsMagicPublicKey; use rsa_magic_public_key::AsMagicPublicKey;
use std::{future::Future, pin::Pin}; use std::{future::Future, pin::Pin};
pub struct RelayResolver; pub(crate) struct RelayResolver;
#[derive(Clone, Debug, thiserror::Error)] #[derive(Clone, Debug, thiserror::Error)]
#[error("Error resolving webfinger data")] #[error("Error resolving webfinger data")]
pub struct RelayError; pub(crate) struct RelayError;
type FutResult<T, E> = dyn Future<Output = Result<T, E>>; type FutResult<T, E> = dyn Future<Output = Result<T, E>>;

View file

@ -20,15 +20,11 @@ use std::{
}; };
#[derive(Clone)] #[derive(Clone)]
pub struct Breakers { pub(crate) struct Breakers {
inner: Arc<RwLock<HashMap<String, Arc<Mutex<Breaker>>>>>, inner: Arc<RwLock<HashMap<String, Arc<Mutex<Breaker>>>>>,
} }
impl Breakers { impl Breakers {
pub fn new() -> Self {
Self::default()
}
async fn should_try(&self, url: &Url) -> bool { async fn should_try(&self, url: &Url) -> bool {
if let Some(domain) = url.domain() { if let Some(domain) = url.domain() {
if let Some(breaker) = self.inner.read().await.get(domain) { if let Some(breaker) = self.inner.read().await.get(domain) {
@ -127,7 +123,7 @@ impl Default for Breaker {
} }
#[derive(Clone)] #[derive(Clone)]
pub struct Requests { pub(crate) struct Requests {
client: Rc<RefCell<Client>>, client: Rc<RefCell<Client>>,
consecutive_errors: Rc<AtomicUsize>, consecutive_errors: Rc<AtomicUsize>,
error_limit: usize, error_limit: usize,
@ -139,7 +135,7 @@ pub struct Requests {
} }
impl Requests { impl Requests {
pub fn new( pub(crate) fn new(
key_id: String, key_id: String,
private_key: RSAPrivateKey, private_key: RSAPrivateKey,
user_agent: String, user_agent: String,
@ -176,14 +172,14 @@ impl Requests {
self.consecutive_errors.swap(0, Ordering::Relaxed); 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 where
T: serde::de::DeserializeOwned, T: serde::de::DeserializeOwned,
{ {
self.do_fetch(url, "application/json").await 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 where
T: serde::de::DeserializeOwned, T: serde::de::DeserializeOwned,
{ {
@ -249,7 +245,7 @@ impl Requests {
Ok(serde_json::from_slice(body.as_ref())?) 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>()?; let parsed_url = url.parse::<Url>()?;
if !self.breakers.should_try(&parsed_url).await { if !self.breakers.should_try(&parsed_url).await {
@ -318,7 +314,7 @@ impl Requests {
Ok((content_type, bytes)) 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 where
T: serde::ser::Serialize, T: serde::ser::Serialize,
{ {

View file

@ -5,17 +5,17 @@ use crate::{
error::MyError, error::MyError,
routes::ok, routes::ok,
}; };
use activitystreams_ext::Ext1;
use activitystreams::{ use activitystreams::{
actor::{ApActor, Application, Endpoints}, actor::{ApActor, Application, Endpoints},
context, context,
prelude::*, prelude::*,
security, security,
}; };
use activitystreams_ext::Ext1;
use actix_web::{web, Responder}; use actix_web::{web, Responder};
use rsa_pem::KeyExt; use rsa_pem::KeyExt;
pub async fn route( pub(crate) async fn route(
state: web::Data<State>, state: web::Data<State>,
config: web::Data<Config>, config: web::Data<Config>,
) -> Result<impl Responder, MyError> { ) -> Result<impl Responder, MyError> {

View file

@ -16,7 +16,7 @@ use actix_web::{web, HttpResponse};
use http_signature_normalization_actix::prelude::{DigestVerified, SignatureVerified}; use http_signature_normalization_actix::prelude::{DigestVerified, SignatureVerified};
use log::error; use log::error;
pub async fn route( pub(crate) async fn route(
state: web::Data<State>, state: web::Data<State>,
actors: web::Data<ActorCache>, actors: web::Data<ActorCache>,
config: web::Data<Config>, config: web::Data<Config>,

View file

@ -4,7 +4,7 @@ use log::error;
use rand::{seq::SliceRandom, thread_rng}; use rand::{seq::SliceRandom, thread_rng};
use std::io::BufWriter; use std::io::BufWriter;
pub async fn route( pub(crate) async fn route(
state: web::Data<State>, state: web::Data<State>,
config: web::Data<Config>, config: web::Data<Config>,
) -> Result<HttpResponse, MyError> { ) -> Result<HttpResponse, MyError> {

View file

@ -5,7 +5,7 @@ use actix_web::{
}; };
use uuid::Uuid; use uuid::Uuid;
pub async fn route( pub(crate) async fn route(
media: web::Data<MediaCache>, media: web::Data<MediaCache>,
requests: web::Data<Requests>, requests: web::Data<Requests>,
uuid: web::Path<Uuid>, uuid: web::Path<Uuid>,

View file

@ -5,7 +5,7 @@ mod media;
mod nodeinfo; mod nodeinfo;
mod statics; mod statics;
pub use self::{ pub(crate) use self::{
actor::route as actor, actor::route as actor,
inbox::route as inbox, inbox::route as inbox,
index::route as index, index::route as index,

View file

@ -5,7 +5,7 @@ use crate::{
use actix_web::{web, Responder}; use actix_web::{web, Responder};
use actix_webfinger::Link; 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 { web::Json(Links {
links: vec![Link { links: vec![Link {
rel: "http://nodeinfo.diaspora.software/ns/schema/2.0".to_owned(), rel: "http://nodeinfo.diaspora.software/ns/schema/2.0".to_owned(),
@ -22,7 +22,10 @@ struct Links {
links: Vec<Link>, 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 { web::Json(NodeInfo {
version: NodeInfoVersion, version: NodeInfoVersion,
software: Software { software: Software {

View file

@ -4,7 +4,7 @@ use actix_web::{
web, HttpResponse, 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()) { if let Some(data) = StaticFile::get(&filename.into_inner()) {
HttpResponse::Ok() HttpResponse::Ok()
.set(CacheControl(vec![ .set(CacheControl(vec![