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"
|
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"
|
||||||
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"
|
||||||
|
|
|
@ -39,7 +39,7 @@ fn main() {
|
||||||
})
|
})
|
||||||
.bind((settings.bind, settings.port))
|
.bind((settings.bind, settings.port))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.start();
|
.run();
|
||||||
|
|
||||||
println!("Started http server at {}:{}", settings.bind, settings.port);
|
println!("Started http server at {}:{}", settings.bind, settings.port);
|
||||||
let _ = sys.run();
|
let _ = sys.run();
|
||||||
|
|
|
@ -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",
|
||||||
)?)
|
)?)
|
||||||
|
|
|
@ -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"");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Reference in a new issue