mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-26 04:41:31 +00:00
Upgrade actix to 2.0 (fixes #392)
This commit is contained in:
parent
f67436792a
commit
d8c84e2541
6 changed files with 423 additions and 537 deletions
917
server/Cargo.lock
generated
vendored
917
server/Cargo.lock
generated
vendored
File diff suppressed because it is too large
Load diff
8
server/Cargo.toml
vendored
8
server/Cargo.toml
vendored
|
@ -14,10 +14,10 @@ chrono = { version = "0.4.7", features = ["serde"] }
|
|||
failure = "0.1.5"
|
||||
serde_json = { version = "1.0.40", features = ["preserve_order"]}
|
||||
serde = { version = "1.0.94", features = ["derive"] }
|
||||
actix = "0.8.3"
|
||||
actix-web = "1.0"
|
||||
actix-files = "0.1.3"
|
||||
actix-web-actors = "1.0"
|
||||
actix = "0.9.0"
|
||||
actix-web = "2.0.0"
|
||||
actix-files = "0.2.1"
|
||||
actix-web-actors = "2.0.0"
|
||||
env_logger = "0.7.1"
|
||||
rand = "0.7.0"
|
||||
strum = "0.17.1"
|
||||
|
|
|
@ -39,7 +39,7 @@ fn main() {
|
|||
})
|
||||
.bind((settings.bind, settings.port))
|
||||
.unwrap()
|
||||
.start();
|
||||
.run();
|
||||
|
||||
println!("Started http server at {}:{}", settings.bind, settings.port);
|
||||
let _ = sys.run();
|
||||
|
|
|
@ -38,7 +38,7 @@ pub fn config(cfg: &mut web::ServiceConfig) {
|
|||
.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(
|
||||
Settings::get().front_end_dir.to_owned() + "/index.html",
|
||||
)?)
|
||||
|
|
|
@ -19,7 +19,7 @@ const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(5);
|
|||
const CLIENT_TIMEOUT: Duration = Duration::from_secs(10);
|
||||
|
||||
/// Entry point for our route
|
||||
fn chat_route(
|
||||
async fn chat_route(
|
||||
req: HttpRequest,
|
||||
stream: web::Payload,
|
||||
chat_server: web::Data<Addr<ChatServer>>,
|
||||
|
@ -80,7 +80,7 @@ impl Actor for WSSession {
|
|||
// something is wrong with chat server
|
||||
_ => ctx.stop(),
|
||||
}
|
||||
fut::ok(())
|
||||
actix::fut::ready(())
|
||||
})
|
||||
.wait(ctx);
|
||||
}
|
||||
|
@ -107,10 +107,17 @@ impl Handler<WSMessage> for WSSession {
|
|||
}
|
||||
|
||||
/// WebSocket message handler
|
||||
impl StreamHandler<ws::Message, ws::ProtocolError> for WSSession {
|
||||
fn handle(&mut self, msg: ws::Message, ctx: &mut Self::Context) {
|
||||
impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for WSSession {
|
||||
fn handle(&mut self, result: Result<ws::Message, ws::ProtocolError>, ctx: &mut Self::Context) {
|
||||
// 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) => {
|
||||
self.hb = Instant::now();
|
||||
ctx.pong(&msg);
|
||||
|
@ -136,7 +143,7 @@ impl StreamHandler<ws::Message, ws::ProtocolError> for WSSession {
|
|||
eprintln!("{}", &e);
|
||||
}
|
||||
}
|
||||
fut::ok(())
|
||||
actix::fut::ready(())
|
||||
})
|
||||
.wait(ctx);
|
||||
}
|
||||
|
@ -173,7 +180,7 @@ impl WSSession {
|
|||
return;
|
||||
}
|
||||
|
||||
ctx.ping("");
|
||||
ctx.ping(b"");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ use crate::Settings;
|
|||
|
||||
/// Chat server sends this messages to session
|
||||
#[derive(Message)]
|
||||
#[rtype(result = "()")]
|
||||
pub struct WSMessage(pub String);
|
||||
|
||||
/// Message for chat server communications
|
||||
|
@ -35,6 +36,7 @@ pub struct Connect {
|
|||
|
||||
/// Session is disconnected
|
||||
#[derive(Message)]
|
||||
#[rtype(result = "()")]
|
||||
pub struct Disconnect {
|
||||
pub id: usize,
|
||||
pub ip: String,
|
||||
|
@ -42,6 +44,7 @@ pub struct Disconnect {
|
|||
|
||||
/// Send message to specific room
|
||||
#[derive(Message)]
|
||||
#[rtype(result = "()")]
|
||||
pub struct ClientMessage {
|
||||
/// Id of the client session
|
||||
pub id: usize,
|
||||
|
@ -51,7 +54,8 @@ pub struct ClientMessage {
|
|||
pub room: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[derive(Serialize, Deserialize, Message)]
|
||||
#[rtype(String)]
|
||||
pub struct StandardMessage {
|
||||
/// Id of the client session
|
||||
pub id: usize,
|
||||
|
@ -59,10 +63,6 @@ pub struct StandardMessage {
|
|||
pub msg: String,
|
||||
}
|
||||
|
||||
impl actix::Message for StandardMessage {
|
||||
type Result = String;
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RateLimitBucket {
|
||||
last_checked: SystemTime,
|
||||
|
|
Loading…
Reference in a new issue