Merge branch 'actix-2.0' into dev

This commit is contained in:
Dessalines 2020-01-11 19:19:38 -05:00
commit f3dbedb5c5
12 changed files with 448 additions and 554 deletions

View file

@ -10,7 +10,7 @@ RUN yarn install --pure-lockfile
COPY ui /app/ui COPY ui /app/ui
RUN yarn build RUN yarn build
FROM ekidd/rust-musl-builder:1.38.0-openssl11 as rust FROM ekidd/rust-musl-builder:1.40.0-openssl11 as rust
# Cache deps # Cache deps
WORKDIR /app WORKDIR /app
@ -33,7 +33,7 @@ RUN cargo build --frozen --release
# RUN cargo install diesel_cli --no-default-features --features postgres # RUN cargo install diesel_cli --no-default-features --features postgres
FROM ekidd/rust-musl-builder:1.38.0-openssl11 as docs FROM ekidd/rust-musl-builder:1.40.0-openssl11 as docs
WORKDIR /app WORKDIR /app
COPY docs ./docs COPY docs ./docs
RUN sudo chown -R rust:rust . RUN sudo chown -R rust:rust .

918
server/Cargo.lock generated vendored

File diff suppressed because it is too large Load diff

9
server/Cargo.toml vendored
View file

@ -14,10 +14,11 @@ chrono = { version = "0.4.7", features = ["serde"] }
failure = "0.1.5" failure = "0.1.5"
serde_json = { version = "1.0.40", features = ["preserve_order"]} serde_json = { version = "1.0.40", features = ["preserve_order"]}
serde = { version = "1.0.94", features = ["derive"] } serde = { version = "1.0.94", features = ["derive"] }
actix = "0.8.3" actix = "0.9.0"
actix-web = "1.0" actix-web = "2.0.0"
actix-files = "0.1.3" actix-files = "0.2.1"
actix-web-actors = "1.0" actix-web-actors = "2.0.0"
actix-rt = "1.0.0"
env_logger = "0.7.1" env_logger = "0.7.1"
rand = "0.7.0" rand = "0.7.0"
strum = "0.17.1" strum = "0.17.1"

View file

@ -84,7 +84,7 @@ pub struct CommunityQuery {
community_name: String, community_name: String,
} }
pub fn get_apub_community(info: Path<CommunityQuery>) -> HttpResponse<Body> { pub async fn get_apub_community(info: Path<CommunityQuery>) -> HttpResponse<Body> {
let connection = establish_connection(); let connection = establish_connection();
if let Ok(community) = Community::read_from_name(&connection, info.community_name.to_owned()) { if let Ok(community) = Community::read_from_name(&connection, info.community_name.to_owned()) {
@ -96,7 +96,7 @@ pub fn get_apub_community(info: Path<CommunityQuery>) -> HttpResponse<Body> {
} }
} }
pub fn get_apub_community_followers(info: Path<CommunityQuery>) -> HttpResponse<Body> { pub async fn get_apub_community_followers(info: Path<CommunityQuery>) -> HttpResponse<Body> {
let connection = establish_connection(); let connection = establish_connection();
if let Ok(community) = Community::read_from_name(&connection, info.community_name.to_owned()) { if let Ok(community) = Community::read_from_name(&connection, info.community_name.to_owned()) {

View file

@ -61,7 +61,7 @@ pub struct UserQuery {
user_name: String, user_name: String,
} }
pub fn get_apub_user(info: Path<UserQuery>) -> HttpResponse<Body> { pub async fn get_apub_user(info: Path<UserQuery>) -> HttpResponse<Body> {
let connection = establish_connection(); let connection = establish_connection();
if let Ok(user) = User_::find_by_email_or_username(&connection, &info.user_name) { if let Ok(user) = User_::find_by_email_or_username(&connection, &info.user_name) {

View file

@ -6,12 +6,13 @@ use actix_web::*;
use lemmy_server::db::establish_connection; use lemmy_server::db::establish_connection;
use lemmy_server::routes::{federation, feeds, index, nodeinfo, webfinger, websocket}; use lemmy_server::routes::{federation, feeds, index, nodeinfo, webfinger, websocket};
use lemmy_server::settings::Settings; use lemmy_server::settings::Settings;
use std::io;
embed_migrations!(); embed_migrations!();
fn main() { #[actix_rt::main]
async fn main() -> io::Result<()> {
env_logger::init(); env_logger::init();
let sys = actix::System::new("lemmy");
// Run the migrations from code // Run the migrations from code
let conn = establish_connection(); let conn = establish_connection();
@ -19,6 +20,11 @@ fn main() {
let settings = Settings::get(); let settings = Settings::get();
println!(
"Starting http server at {}:{}",
settings.bind, settings.port
);
// Create Http server with websocket support // Create Http server with websocket support
HttpServer::new(move || { HttpServer::new(move || {
App::new() App::new()
@ -37,10 +43,7 @@ fn main() {
settings.front_end_dir.to_owned() + "/documentation", settings.front_end_dir.to_owned() + "/documentation",
)) ))
}) })
.bind((settings.bind, settings.port)) .bind((settings.bind, settings.port))?
.unwrap() .run()
.start(); .await
println!("Started http server at {}:{}", settings.bind, settings.port);
let _ = sys.run();
} }

View file

@ -37,7 +37,7 @@ pub fn config(cfg: &mut web::ServiceConfig) {
.route("/feeds/all.xml", web::get().to(feeds::get_all_feed)); .route("/feeds/all.xml", web::get().to(feeds::get_all_feed));
} }
fn get_all_feed(info: web::Query<Params>) -> HttpResponse<Body> { async fn get_all_feed(info: web::Query<Params>) -> HttpResponse<Body> {
let sort_type = match get_sort_type(info) { let sort_type = match get_sort_type(info) {
Ok(sort_type) => sort_type, Ok(sort_type) => sort_type,
Err(_) => return HttpResponse::BadRequest().finish(), Err(_) => return HttpResponse::BadRequest().finish(),
@ -53,7 +53,10 @@ fn get_all_feed(info: web::Query<Params>) -> HttpResponse<Body> {
} }
} }
fn get_feed(path: web::Path<(String, String)>, info: web::Query<Params>) -> HttpResponse<Body> { async fn get_feed(
path: web::Path<(String, String)>,
info: web::Query<Params>,
) -> HttpResponse<Body> {
let sort_type = match get_sort_type(info) { let sort_type = match get_sort_type(info) {
Ok(sort_type) => sort_type, Ok(sort_type) => sort_type,
Err(_) => return HttpResponse::BadRequest().finish(), Err(_) => return HttpResponse::BadRequest().finish(),

View file

@ -38,7 +38,7 @@ pub fn config(cfg: &mut web::ServiceConfig) {
.route("/password_change/{token}", web::get().to(index)); .route("/password_change/{token}", web::get().to(index));
} }
fn index() -> Result<NamedFile, actix_web::error::Error> { async fn index() -> Result<NamedFile, actix_web::error::Error> {
Ok(NamedFile::open( Ok(NamedFile::open(
Settings::get().front_end_dir.to_owned() + "/index.html", Settings::get().front_end_dir.to_owned() + "/index.html",
)?) )?)

View file

@ -13,7 +13,7 @@ pub fn config(cfg: &mut web::ServiceConfig) {
.route("/.well-known/nodeinfo", web::get().to(node_info_well_known)); .route("/.well-known/nodeinfo", web::get().to(node_info_well_known));
} }
pub fn node_info_well_known() -> HttpResponse<Body> { async fn node_info_well_known() -> HttpResponse<Body> {
let json = json!({ let json = json!({
"links": { "links": {
"rel": "http://nodeinfo.diaspora.software/ns/schema/2.0", "rel": "http://nodeinfo.diaspora.software/ns/schema/2.0",
@ -26,7 +26,7 @@ pub fn node_info_well_known() -> HttpResponse<Body> {
.body(json.to_string()) .body(json.to_string())
} }
fn node_info() -> HttpResponse<Body> { async fn node_info() -> HttpResponse<Body> {
let conn = establish_connection(); let conn = establish_connection();
let site_view = match SiteView::read(&conn) { let site_view = match SiteView::read(&conn) {
Ok(site_view) => site_view, Ok(site_view) => site_view,

View file

@ -37,7 +37,7 @@ lazy_static! {
/// ///
/// You can also view the webfinger response that Mastodon sends: /// You can also view the webfinger response that Mastodon sends:
/// https://radical.town/.well-known/webfinger?resource=acct:felix@radical.town /// https://radical.town/.well-known/webfinger?resource=acct:felix@radical.town
fn get_webfinger_response(info: Query<Params>) -> HttpResponse<Body> { async fn get_webfinger_response(info: Query<Params>) -> HttpResponse<Body> {
let regex_parsed = WEBFINGER_COMMUNITY_REGEX let regex_parsed = WEBFINGER_COMMUNITY_REGEX
.captures(&info.resource) .captures(&info.resource)
.map(|c| c.get(1)); .map(|c| c.get(1));

View file

@ -19,7 +19,7 @@ const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(5);
const CLIENT_TIMEOUT: Duration = Duration::from_secs(10); const CLIENT_TIMEOUT: Duration = Duration::from_secs(10);
/// Entry point for our route /// Entry point for our route
fn chat_route( async fn chat_route(
req: HttpRequest, req: HttpRequest,
stream: web::Payload, stream: web::Payload,
chat_server: web::Data<Addr<ChatServer>>, chat_server: web::Data<Addr<ChatServer>>,
@ -80,7 +80,7 @@ impl Actor for WSSession {
// something is wrong with chat server // something is wrong with chat server
_ => ctx.stop(), _ => ctx.stop(),
} }
fut::ok(()) actix::fut::ready(())
}) })
.wait(ctx); .wait(ctx);
} }
@ -107,10 +107,17 @@ impl Handler<WSMessage> for WSSession {
} }
/// WebSocket message handler /// WebSocket message handler
impl StreamHandler<ws::Message, ws::ProtocolError> for WSSession { impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for WSSession {
fn handle(&mut self, msg: ws::Message, ctx: &mut Self::Context) { fn handle(&mut self, result: Result<ws::Message, ws::ProtocolError>, ctx: &mut Self::Context) {
// println!("WEBSOCKET MESSAGE: {:?} from id: {}", msg, self.id); // println!("WEBSOCKET MESSAGE: {:?} from id: {}", msg, self.id);
match msg { let message = match result {
Ok(m) => m,
Err(e) => {
println!("{}", e);
return;
}
};
match message {
ws::Message::Ping(msg) => { ws::Message::Ping(msg) => {
self.hb = Instant::now(); self.hb = Instant::now();
ctx.pong(&msg); ctx.pong(&msg);
@ -136,7 +143,7 @@ impl StreamHandler<ws::Message, ws::ProtocolError> for WSSession {
eprintln!("{}", &e); eprintln!("{}", &e);
} }
} }
fut::ok(()) actix::fut::ready(())
}) })
.wait(ctx); .wait(ctx);
} }
@ -173,7 +180,7 @@ impl WSSession {
return; return;
} }
ctx.ping(""); ctx.ping(b"");
}); });
} }
} }

View file

@ -21,6 +21,7 @@ use crate::Settings;
/// Chat server sends this messages to session /// Chat server sends this messages to session
#[derive(Message)] #[derive(Message)]
#[rtype(result = "()")]
pub struct WSMessage(pub String); pub struct WSMessage(pub String);
/// Message for chat server communications /// Message for chat server communications
@ -35,6 +36,7 @@ pub struct Connect {
/// Session is disconnected /// Session is disconnected
#[derive(Message)] #[derive(Message)]
#[rtype(result = "()")]
pub struct Disconnect { pub struct Disconnect {
pub id: usize, pub id: usize,
pub ip: String, pub ip: String,
@ -42,6 +44,7 @@ pub struct Disconnect {
/// Send message to specific room /// Send message to specific room
#[derive(Message)] #[derive(Message)]
#[rtype(result = "()")]
pub struct ClientMessage { pub struct ClientMessage {
/// Id of the client session /// Id of the client session
pub id: usize, pub id: usize,
@ -51,7 +54,8 @@ pub struct ClientMessage {
pub room: String, pub room: String,
} }
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize, Message)]
#[rtype(String)]
pub struct StandardMessage { pub struct StandardMessage {
/// Id of the client session /// Id of the client session
pub id: usize, pub id: usize,
@ -59,10 +63,6 @@ pub struct StandardMessage {
pub msg: String, pub msg: String,
} }
impl actix::Message for StandardMessage {
type Result = String;
}
#[derive(Debug)] #[derive(Debug)]
pub struct RateLimitBucket { pub struct RateLimitBucket {
last_checked: SystemTime, last_checked: SystemTime,