2024-04-09 14:58:57 +05:30
|
|
|
#![allow(clippy::unwrap_used)]
|
|
|
|
|
2023-03-08 03:31:36 +05:30
|
|
|
use crate::{
|
|
|
|
database::Database,
|
|
|
|
http::{http_get_user, http_post_user_inbox, webfinger},
|
|
|
|
objects::{person::DbUser, post::DbPost},
|
|
|
|
utils::generate_object_id,
|
|
|
|
};
|
2023-03-17 02:11:29 +05:30
|
|
|
use activitypub_federation::config::{FederationConfig, FederationMiddleware};
|
2023-03-08 03:31:36 +05:30
|
|
|
use axum::{
|
|
|
|
routing::{get, post},
|
|
|
|
Router,
|
|
|
|
};
|
|
|
|
use error::Error;
|
|
|
|
use std::{
|
|
|
|
net::ToSocketAddrs,
|
|
|
|
sync::{Arc, Mutex},
|
|
|
|
};
|
|
|
|
use tracing::log::{info, LevelFilter};
|
|
|
|
|
|
|
|
mod activities;
|
|
|
|
mod database;
|
|
|
|
mod error;
|
|
|
|
#[allow(clippy::diverging_sub_expression, clippy::items_after_statements)]
|
|
|
|
mod http;
|
|
|
|
mod objects;
|
|
|
|
mod utils;
|
|
|
|
|
|
|
|
const DOMAIN: &str = "example.com";
|
|
|
|
const LOCAL_USER_NAME: &str = "alison";
|
|
|
|
const BIND_ADDRESS: &str = "localhost:8003";
|
|
|
|
|
2023-06-20 15:24:14 +05:30
|
|
|
#[tokio::main]
|
2023-03-08 03:31:36 +05:30
|
|
|
async fn main() -> Result<(), Error> {
|
|
|
|
env_logger::builder()
|
|
|
|
.filter_level(LevelFilter::Warn)
|
|
|
|
.filter_module("activitypub_federation", LevelFilter::Info)
|
|
|
|
.filter_module("live_federation", LevelFilter::Info)
|
|
|
|
.format_timestamp(None)
|
|
|
|
.init();
|
|
|
|
|
|
|
|
info!("Setup local user and database");
|
|
|
|
let local_user = DbUser::new(DOMAIN, LOCAL_USER_NAME)?;
|
|
|
|
let database = Arc::new(Database {
|
|
|
|
users: Mutex::new(vec![local_user]),
|
|
|
|
});
|
|
|
|
|
|
|
|
info!("Setup configuration");
|
|
|
|
let config = FederationConfig::builder()
|
|
|
|
.domain(DOMAIN)
|
|
|
|
.app_data(database)
|
2023-06-20 15:24:14 +05:30
|
|
|
.build()
|
|
|
|
.await?;
|
2023-03-08 03:31:36 +05:30
|
|
|
|
|
|
|
info!("Listen with HTTP server on {BIND_ADDRESS}");
|
|
|
|
let config = config.clone();
|
|
|
|
let app = Router::new()
|
|
|
|
.route("/:user", get(http_get_user))
|
|
|
|
.route("/:user/inbox", post(http_post_user_inbox))
|
|
|
|
.route("/.well-known/webfinger", get(webfinger))
|
2023-03-17 02:11:29 +05:30
|
|
|
.layer(FederationMiddleware::new(config));
|
2023-03-08 03:31:36 +05:30
|
|
|
|
|
|
|
let addr = BIND_ADDRESS
|
|
|
|
.to_socket_addrs()?
|
|
|
|
.next()
|
|
|
|
.expect("Failed to lookup domain name");
|
2024-09-11 18:17:13 +05:30
|
|
|
let listener = tokio::net::TcpListener::bind(addr).await?;
|
|
|
|
axum::serve(listener, app.into_make_service()).await?;
|
2023-03-08 03:31:36 +05:30
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|