2023-02-11 18:35:37 +05:30
|
|
|
use crate::{
|
2023-03-02 19:48:06 +05:30
|
|
|
instance::{listen, new_instance, Webserver},
|
2023-02-19 17:56:01 +05:30
|
|
|
objects::post::DbPost,
|
2023-02-11 18:35:37 +05:30
|
|
|
utils::generate_object_id,
|
|
|
|
};
|
|
|
|
use error::Error;
|
2023-03-02 19:48:06 +05:30
|
|
|
use std::{env::args, str::FromStr};
|
2023-02-19 17:56:01 +05:30
|
|
|
use tracing::log::{info, LevelFilter};
|
2022-06-02 16:47:12 +05:30
|
|
|
|
|
|
|
mod activities;
|
2023-02-11 18:35:37 +05:30
|
|
|
#[cfg(feature = "actix-web")]
|
|
|
|
mod actix_web;
|
|
|
|
#[cfg(feature = "axum")]
|
|
|
|
mod axum;
|
2022-06-02 16:47:12 +05:30
|
|
|
mod error;
|
|
|
|
mod instance;
|
|
|
|
mod objects;
|
2022-11-26 21:42:08 +05:30
|
|
|
mod utils;
|
2022-06-02 16:47:12 +05:30
|
|
|
|
2023-06-20 15:24:14 +05:30
|
|
|
#[tokio::main]
|
2022-06-02 16:47:12 +05:30
|
|
|
async fn main() -> Result<(), Error> {
|
|
|
|
env_logger::builder()
|
2023-02-19 17:56:01 +05:30
|
|
|
.filter_level(LevelFilter::Warn)
|
2023-03-08 03:31:36 +05:30
|
|
|
.filter_module("activitypub_federation", LevelFilter::Info)
|
2023-02-19 17:56:01 +05:30
|
|
|
.filter_module("local_federation", LevelFilter::Info)
|
|
|
|
.format_timestamp(None)
|
2022-06-02 16:47:12 +05:30
|
|
|
.init();
|
|
|
|
|
2023-03-02 19:48:06 +05:30
|
|
|
info!("Start with parameter `axum` or `actix-web` to select the webserver");
|
|
|
|
let webserver = args()
|
|
|
|
.nth(1)
|
|
|
|
.map(|arg| Webserver::from_str(&arg).unwrap())
|
|
|
|
.unwrap_or(Webserver::Axum);
|
|
|
|
|
2023-06-20 15:24:14 +05:30
|
|
|
let alpha = new_instance("localhost:8001", "alpha".to_string()).await?;
|
|
|
|
let beta = new_instance("localhost:8002", "beta".to_string()).await?;
|
2023-03-02 19:48:06 +05:30
|
|
|
listen(&alpha, &webserver)?;
|
|
|
|
listen(&beta, &webserver)?;
|
2023-02-19 17:56:01 +05:30
|
|
|
info!("Local instances started");
|
2022-06-02 16:47:12 +05:30
|
|
|
|
2023-03-02 04:49:10 +05:30
|
|
|
info!("Alpha user follows beta user via webfinger");
|
2022-06-02 16:47:12 +05:30
|
|
|
alpha
|
|
|
|
.local_user()
|
2023-03-02 04:49:10 +05:30
|
|
|
.follow("beta@localhost:8002", &alpha.to_request_data())
|
2022-06-02 16:47:12 +05:30
|
|
|
.await?;
|
|
|
|
assert_eq!(
|
|
|
|
beta.local_user().followers(),
|
|
|
|
&vec![alpha.local_user().ap_id.inner().clone()]
|
|
|
|
);
|
2023-02-19 17:56:01 +05:30
|
|
|
info!("Follow was successful");
|
2022-06-02 16:47:12 +05:30
|
|
|
|
2023-02-19 17:56:01 +05:30
|
|
|
info!("Beta sends a post to its followers");
|
|
|
|
let sent_post = DbPost::new("Hello world!".to_string(), beta.local_user().ap_id)?;
|
2023-02-11 18:02:35 +05:30
|
|
|
beta.local_user()
|
|
|
|
.post(sent_post.clone(), &beta.to_request_data())
|
|
|
|
.await?;
|
2022-06-02 16:47:12 +05:30
|
|
|
let received_post = alpha.posts.lock().unwrap().first().cloned().unwrap();
|
2023-02-19 17:56:01 +05:30
|
|
|
info!("Alpha received post: {}", received_post.text);
|
2022-06-02 16:47:12 +05:30
|
|
|
|
|
|
|
// assert that alpha received the post
|
|
|
|
assert_eq!(received_post.text, sent_post.text);
|
|
|
|
assert_eq!(received_post.ap_id.inner(), sent_post.ap_id.inner());
|
|
|
|
assert_eq!(received_post.creator.inner(), sent_post.creator.inner());
|
2023-02-19 17:56:01 +05:30
|
|
|
info!("Test completed");
|
2022-06-02 16:47:12 +05:30
|
|
|
Ok(())
|
|
|
|
}
|