2019-12-06 22:19:07 +01:00
|
|
|
use std::sync::atomic::{AtomicBool, Ordering};
|
|
|
|
|
2018-08-24 19:02:34 +02:00
|
|
|
use rocket::Route;
|
2018-10-10 20:40:39 +02:00
|
|
|
use rocket_contrib::json::Json;
|
2018-10-15 00:25:16 +02:00
|
|
|
use serde_json::Value as JsonValue;
|
2018-08-24 19:02:34 +02:00
|
|
|
|
2021-03-31 22:18:35 +02:00
|
|
|
use crate::{api::EmptyResult, auth::Headers, db::DbConn, Error, CONFIG};
|
2018-09-13 20:59:51 +02:00
|
|
|
|
2018-08-24 19:02:34 +02:00
|
|
|
pub fn routes() -> Vec<Route> {
|
2018-09-11 17:09:33 +02:00
|
|
|
routes![negotiate, websockets_err]
|
|
|
|
}
|
|
|
|
|
2019-12-06 22:19:07 +01:00
|
|
|
static SHOW_WEBSOCKETS_MSG: AtomicBool = AtomicBool::new(true);
|
|
|
|
|
2018-09-11 17:09:33 +02:00
|
|
|
#[get("/hub")]
|
2019-12-06 22:19:07 +01:00
|
|
|
fn websockets_err() -> EmptyResult {
|
2021-03-31 22:18:35 +02:00
|
|
|
if CONFIG.websocket_enabled()
|
|
|
|
&& SHOW_WEBSOCKETS_MSG
|
|
|
|
.compare_exchange(true, false, Ordering::Relaxed, Ordering::Relaxed)
|
|
|
|
.is_ok()
|
|
|
|
{
|
|
|
|
err!(
|
|
|
|
"
|
2021-01-31 20:07:42 +01:00
|
|
|
###########################################################
|
2019-12-06 22:19:07 +01:00
|
|
|
'/notifications/hub' should be proxied to the websocket server or notifications won't work.
|
|
|
|
Go to the Wiki for more info, or disable WebSockets setting WEBSOCKET_ENABLED=false.
|
2021-03-31 22:18:35 +02:00
|
|
|
###########################################################################################\n"
|
|
|
|
)
|
2019-12-06 22:19:07 +01:00
|
|
|
} else {
|
|
|
|
Err(Error::empty())
|
|
|
|
}
|
2018-08-24 19:02:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[post("/hub/negotiate")]
|
2021-03-27 16:07:26 +01:00
|
|
|
fn negotiate(_headers: Headers, _conn: DbConn) -> Json<JsonValue> {
|
2018-12-07 02:05:45 +01:00
|
|
|
use crate::crypto;
|
2018-08-30 17:43:46 +02:00
|
|
|
use data_encoding::BASE64URL;
|
2018-08-24 19:02:34 +02:00
|
|
|
|
|
|
|
let conn_id = BASE64URL.encode(&crypto::get_random(vec![0u8; 16]));
|
2018-10-15 00:25:16 +02:00
|
|
|
let mut available_transports: Vec<JsonValue> = Vec::new();
|
|
|
|
|
2019-01-25 18:23:51 +01:00
|
|
|
if CONFIG.websocket_enabled() {
|
2018-10-15 00:25:16 +02:00
|
|
|
available_transports.push(json!({"transport":"WebSockets", "transferFormats":["Text","Binary"]}));
|
|
|
|
}
|
2018-08-24 19:02:34 +02:00
|
|
|
|
|
|
|
// TODO: Implement transports
|
|
|
|
// Rocket WS support: https://github.com/SergioBenitez/Rocket/issues/90
|
|
|
|
// Rocket SSE support: https://github.com/SergioBenitez/Rocket/issues/33
|
2018-10-15 00:25:16 +02:00
|
|
|
// {"transport":"ServerSentEvents", "transferFormats":["Text"]},
|
|
|
|
// {"transport":"LongPolling", "transferFormats":["Text","Binary"]}
|
2021-03-27 16:07:26 +01:00
|
|
|
Json(json!({
|
2018-08-24 19:02:34 +02:00
|
|
|
"connectionId": conn_id,
|
2018-10-15 00:25:16 +02:00
|
|
|
"availableTransports": available_transports
|
2021-03-27 16:07:26 +01:00
|
|
|
}))
|
2018-08-30 17:43:46 +02:00
|
|
|
}
|
|
|
|
|
2018-12-30 23:34:31 +01:00
|
|
|
//
|
|
|
|
// Websockets server
|
|
|
|
//
|
2020-01-04 23:52:38 +01:00
|
|
|
use std::io;
|
2018-08-30 17:43:46 +02:00
|
|
|
use std::sync::Arc;
|
|
|
|
use std::thread;
|
|
|
|
|
2020-01-04 23:52:38 +01:00
|
|
|
use ws::{self, util::Token, Factory, Handler, Handshake, Message, Sender};
|
2018-08-30 17:43:46 +02:00
|
|
|
|
|
|
|
use chashmap::CHashMap;
|
|
|
|
use chrono::NaiveDateTime;
|
|
|
|
use serde_json::from_str;
|
|
|
|
|
2018-12-07 02:05:45 +01:00
|
|
|
use crate::db::models::{Cipher, Folder, User};
|
2018-08-30 17:43:46 +02:00
|
|
|
|
|
|
|
use rmpv::Value;
|
|
|
|
|
|
|
|
fn serialize(val: Value) -> Vec<u8> {
|
|
|
|
use rmpv::encode::write_value;
|
|
|
|
|
|
|
|
let mut buf = Vec::new();
|
|
|
|
write_value(&mut buf, &val).expect("Error encoding MsgPack");
|
|
|
|
|
|
|
|
// Add size bytes at the start
|
|
|
|
// Extracted from BinaryMessageFormat.js
|
2018-09-13 21:55:23 +02:00
|
|
|
let mut size: usize = buf.len();
|
2018-08-30 17:43:46 +02:00
|
|
|
let mut len_buf: Vec<u8> = Vec::new();
|
|
|
|
|
|
|
|
loop {
|
|
|
|
let mut size_part = size & 0x7f;
|
2018-09-13 21:55:23 +02:00
|
|
|
size >>= 7;
|
2018-08-30 17:43:46 +02:00
|
|
|
|
|
|
|
if size > 0 {
|
2018-09-13 21:55:23 +02:00
|
|
|
size_part |= 0x80;
|
2018-08-30 17:43:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
len_buf.push(size_part as u8);
|
|
|
|
|
2018-09-13 21:55:23 +02:00
|
|
|
if size == 0 {
|
2018-08-30 17:43:46 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
len_buf.append(&mut buf);
|
|
|
|
len_buf
|
|
|
|
}
|
|
|
|
|
|
|
|
fn serialize_date(date: NaiveDateTime) -> Value {
|
|
|
|
let seconds: i64 = date.timestamp();
|
2019-02-20 17:54:18 +01:00
|
|
|
let nanos: i64 = date.timestamp_subsec_nanos().into();
|
2018-08-30 17:43:46 +02:00
|
|
|
let timestamp = nanos << 34 | seconds;
|
2019-01-25 18:23:51 +01:00
|
|
|
|
2019-01-16 22:14:17 +01:00
|
|
|
let bs = timestamp.to_be_bytes();
|
2018-08-30 17:43:46 +02:00
|
|
|
|
|
|
|
// -1 is Timestamp
|
|
|
|
// https://github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-type
|
|
|
|
Value::Ext(-1, bs.to_vec())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn convert_option<T: Into<Value>>(option: Option<T>) -> Value {
|
|
|
|
match option {
|
|
|
|
Some(a) => a.into(),
|
|
|
|
None => Value::Nil,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Server WebSocket handler
|
2021-03-27 15:26:32 +01:00
|
|
|
pub struct WsHandler {
|
2018-08-30 17:43:46 +02:00
|
|
|
out: Sender,
|
|
|
|
user_uuid: Option<String>,
|
|
|
|
users: WebSocketUsers,
|
|
|
|
}
|
|
|
|
|
|
|
|
const RECORD_SEPARATOR: u8 = 0x1e;
|
|
|
|
const INITIAL_RESPONSE: [u8; 3] = [0x7b, 0x7d, RECORD_SEPARATOR]; // {, }, <RS>
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
struct InitialMessage {
|
|
|
|
protocol: String,
|
|
|
|
version: i32,
|
|
|
|
}
|
|
|
|
|
|
|
|
const PING_MS: u64 = 15_000;
|
|
|
|
const PING: Token = Token(1);
|
|
|
|
|
2020-01-04 23:52:38 +01:00
|
|
|
const ACCESS_TOKEN_KEY: &str = "access_token=";
|
|
|
|
|
2021-03-27 15:26:32 +01:00
|
|
|
impl WsHandler {
|
2020-01-04 23:52:38 +01:00
|
|
|
fn err(&self, msg: &'static str) -> ws::Result<()> {
|
|
|
|
self.out.close(ws::CloseCode::Invalid)?;
|
|
|
|
|
|
|
|
// We need to specifically return an IO error so ws closes the connection
|
|
|
|
let io_error = io::Error::from(io::ErrorKind::InvalidData);
|
|
|
|
Err(ws::Error::new(ws::ErrorKind::Io(io_error), msg))
|
|
|
|
}
|
2020-08-31 19:05:07 +02:00
|
|
|
|
2020-08-31 22:20:21 +02:00
|
|
|
fn get_request_token(&self, hs: Handshake) -> Option<String> {
|
|
|
|
use std::str::from_utf8;
|
2020-08-31 19:05:07 +02:00
|
|
|
|
2020-08-31 22:20:21 +02:00
|
|
|
// Verify we have a token header
|
|
|
|
if let Some(header_value) = hs.request.header("Authorization") {
|
|
|
|
if let Ok(converted) = from_utf8(header_value) {
|
|
|
|
if let Some(token_part) = converted.split("Bearer ").nth(1) {
|
|
|
|
return Some(token_part.into());
|
|
|
|
}
|
|
|
|
}
|
2020-08-31 19:05:07 +02:00
|
|
|
};
|
2021-01-31 20:07:42 +01:00
|
|
|
|
2020-08-31 22:20:21 +02:00
|
|
|
// Otherwise verify the query parameter value
|
|
|
|
let path = hs.request.resource();
|
|
|
|
if let Some(params) = path.split('?').nth(1) {
|
|
|
|
let params_iter = params.split('&').take(1);
|
|
|
|
for val in params_iter {
|
2021-03-27 15:03:31 +01:00
|
|
|
if let Some(stripped) = val.strip_prefix(ACCESS_TOKEN_KEY) {
|
|
|
|
return Some(stripped.into());
|
2020-08-31 22:20:21 +02:00
|
|
|
}
|
2020-08-31 19:05:07 +02:00
|
|
|
}
|
2020-08-31 22:20:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
None
|
2020-08-31 19:05:07 +02:00
|
|
|
}
|
2020-01-04 23:52:38 +01:00
|
|
|
}
|
|
|
|
|
2021-03-27 15:26:32 +01:00
|
|
|
impl Handler for WsHandler {
|
2018-08-30 17:43:46 +02:00
|
|
|
fn on_open(&mut self, hs: Handshake) -> ws::Result<()> {
|
2020-01-04 23:52:38 +01:00
|
|
|
// Path == "/notifications/hub?id=<id>==&access_token=<access_token>"
|
2020-03-27 03:26:44 +01:00
|
|
|
//
|
|
|
|
// We don't use `id`, and as of around 2020-03-25, the official clients
|
|
|
|
// no longer seem to pass `id` (only `access_token`).
|
2020-07-14 18:00:09 +02:00
|
|
|
|
2020-08-31 19:05:07 +02:00
|
|
|
// Get user token from header or query parameter
|
2020-08-31 22:20:21 +02:00
|
|
|
let access_token = match self.get_request_token(hs) {
|
|
|
|
Some(token) => token,
|
|
|
|
_ => return self.err("Missing access token"),
|
|
|
|
};
|
2018-08-30 17:43:46 +02:00
|
|
|
|
|
|
|
// Validate the user
|
2018-12-07 02:05:45 +01:00
|
|
|
use crate::auth;
|
2020-08-31 22:20:21 +02:00
|
|
|
let claims = match auth::decode_login(access_token.as_str()) {
|
2018-08-30 17:43:46 +02:00
|
|
|
Ok(claims) => claims,
|
2020-01-04 23:52:38 +01:00
|
|
|
Err(_) => return self.err("Invalid access token provided"),
|
2018-08-30 17:43:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Assign the user to the handler
|
|
|
|
let user_uuid = claims.sub;
|
|
|
|
self.user_uuid = Some(user_uuid.clone());
|
|
|
|
|
|
|
|
// Add the current Sender to the user list
|
|
|
|
let handler_insert = self.out.clone();
|
|
|
|
let handler_update = self.out.clone();
|
|
|
|
|
2018-12-30 23:34:31 +01:00
|
|
|
self.users
|
|
|
|
.map
|
|
|
|
.upsert(user_uuid, || vec![handler_insert], |ref mut v| v.push(handler_update));
|
2018-08-30 17:43:46 +02:00
|
|
|
|
|
|
|
// Schedule a ping to keep the connection alive
|
|
|
|
self.out.timeout(PING_MS, PING)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn on_message(&mut self, msg: Message) -> ws::Result<()> {
|
|
|
|
if let Message::Text(text) = msg.clone() {
|
|
|
|
let json = &text[..text.len() - 1]; // Remove last char
|
|
|
|
|
|
|
|
if let Ok(InitialMessage { protocol, version }) = from_str::<InitialMessage>(json) {
|
|
|
|
if &protocol == "messagepack" && version == 1 {
|
|
|
|
return self.out.send(&INITIAL_RESPONSE[..]); // Respond to initial message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If it's not the initial message, just echo the message
|
|
|
|
self.out.send(msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn on_timeout(&mut self, event: Token) -> ws::Result<()> {
|
|
|
|
if event == PING {
|
|
|
|
// send ping
|
|
|
|
self.out.send(create_ping())?;
|
|
|
|
|
|
|
|
// reschedule the timeout
|
|
|
|
self.out.timeout(PING_MS, PING)
|
|
|
|
} else {
|
2020-01-04 23:52:38 +01:00
|
|
|
Ok(())
|
2018-08-30 17:43:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-27 15:26:32 +01:00
|
|
|
struct WsFactory {
|
2018-08-30 17:43:46 +02:00
|
|
|
pub users: WebSocketUsers,
|
|
|
|
}
|
|
|
|
|
2021-03-27 15:26:32 +01:00
|
|
|
impl WsFactory {
|
2018-08-30 17:43:46 +02:00
|
|
|
pub fn init() -> Self {
|
2021-03-27 15:26:32 +01:00
|
|
|
WsFactory {
|
2018-08-30 17:43:46 +02:00
|
|
|
users: WebSocketUsers {
|
|
|
|
map: Arc::new(CHashMap::new()),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-27 15:26:32 +01:00
|
|
|
impl Factory for WsFactory {
|
|
|
|
type Handler = WsHandler;
|
2018-08-30 17:43:46 +02:00
|
|
|
|
|
|
|
fn connection_made(&mut self, out: Sender) -> Self::Handler {
|
2021-03-27 15:26:32 +01:00
|
|
|
WsHandler {
|
2018-08-30 17:43:46 +02:00
|
|
|
out,
|
|
|
|
user_uuid: None,
|
|
|
|
users: self.users.clone(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn connection_lost(&mut self, handler: Self::Handler) {
|
|
|
|
// Remove handler
|
2018-11-21 15:07:18 +01:00
|
|
|
if let Some(user_uuid) = &handler.user_uuid {
|
|
|
|
if let Some(mut user_conn) = self.users.map.get_mut(user_uuid) {
|
2020-05-03 17:24:51 +02:00
|
|
|
if let Some(pos) = user_conn.iter().position(|x| x == &handler.out) {
|
|
|
|
user_conn.remove(pos);
|
|
|
|
}
|
2018-11-21 15:07:18 +01:00
|
|
|
}
|
2018-08-30 17:43:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct WebSocketUsers {
|
2018-12-30 23:34:31 +01:00
|
|
|
map: Arc<CHashMap<String, Vec<Sender>>>,
|
2018-08-30 17:43:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl WebSocketUsers {
|
2019-02-27 17:21:04 +01:00
|
|
|
fn send_update(&self, user_uuid: &str, data: &[u8]) -> ws::Result<()> {
|
2018-08-30 17:43:46 +02:00
|
|
|
if let Some(user) = self.map.get(user_uuid) {
|
|
|
|
for sender in user.iter() {
|
2018-12-07 15:01:29 +01:00
|
|
|
sender.send(data)?;
|
2018-08-30 17:43:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: The last modified date needs to be updated before calling these methods
|
|
|
|
pub fn send_user_update(&self, ut: UpdateType, user: &User) {
|
|
|
|
let data = create_update(
|
|
|
|
vec![
|
|
|
|
("UserId".into(), user.uuid.clone().into()),
|
|
|
|
("Date".into(), serialize_date(user.updated_at)),
|
2018-09-13 21:55:23 +02:00
|
|
|
],
|
2018-08-30 17:43:46 +02:00
|
|
|
ut,
|
|
|
|
);
|
|
|
|
|
2019-02-20 17:54:18 +01:00
|
|
|
self.send_update(&user.uuid, &data).ok();
|
2018-08-30 17:43:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn send_folder_update(&self, ut: UpdateType, folder: &Folder) {
|
|
|
|
let data = create_update(
|
|
|
|
vec![
|
|
|
|
("Id".into(), folder.uuid.clone().into()),
|
|
|
|
("UserId".into(), folder.user_uuid.clone().into()),
|
|
|
|
("RevisionDate".into(), serialize_date(folder.updated_at)),
|
2018-09-13 21:55:23 +02:00
|
|
|
],
|
2018-08-30 17:43:46 +02:00
|
|
|
ut,
|
|
|
|
);
|
|
|
|
|
2018-12-07 15:01:29 +01:00
|
|
|
self.send_update(&folder.user_uuid, &data).ok();
|
2018-08-30 17:43:46 +02:00
|
|
|
}
|
|
|
|
|
2018-12-07 15:01:29 +01:00
|
|
|
pub fn send_cipher_update(&self, ut: UpdateType, cipher: &Cipher, user_uuids: &[String]) {
|
2018-08-30 17:43:46 +02:00
|
|
|
let user_uuid = convert_option(cipher.user_uuid.clone());
|
|
|
|
let org_uuid = convert_option(cipher.organization_uuid.clone());
|
|
|
|
|
|
|
|
let data = create_update(
|
|
|
|
vec![
|
|
|
|
("Id".into(), cipher.uuid.clone().into()),
|
|
|
|
("UserId".into(), user_uuid),
|
|
|
|
("OrganizationId".into(), org_uuid),
|
|
|
|
("CollectionIds".into(), Value::Nil),
|
|
|
|
("RevisionDate".into(), serialize_date(cipher.updated_at)),
|
2018-09-13 21:55:23 +02:00
|
|
|
],
|
2018-08-30 17:43:46 +02:00
|
|
|
ut,
|
|
|
|
);
|
|
|
|
|
2018-09-01 06:30:53 +02:00
|
|
|
for uuid in user_uuids {
|
2018-12-07 15:01:29 +01:00
|
|
|
self.send_update(&uuid, &data).ok();
|
2018-08-30 17:43:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Message Structure
|
|
|
|
[
|
|
|
|
1, // MessageType.Invocation
|
2020-08-31 19:05:07 +02:00
|
|
|
{}, // Headers (map)
|
2018-08-30 17:43:46 +02:00
|
|
|
null, // InvocationId
|
|
|
|
"ReceiveMessage", // Target
|
|
|
|
[ // Arguments
|
|
|
|
{
|
|
|
|
"ContextId": "app_id",
|
|
|
|
"Type": ut as i32,
|
|
|
|
"Payload": {}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
]
|
|
|
|
*/
|
|
|
|
fn create_update(payload: Vec<(Value, Value)>, ut: UpdateType) -> Vec<u8> {
|
|
|
|
use rmpv::Value as V;
|
|
|
|
|
|
|
|
let value = V::Array(vec![
|
|
|
|
1.into(),
|
2020-08-31 19:05:07 +02:00
|
|
|
V::Map(vec![]),
|
2018-08-30 17:43:46 +02:00
|
|
|
V::Nil,
|
|
|
|
"ReceiveMessage".into(),
|
|
|
|
V::Array(vec![V::Map(vec![
|
|
|
|
("ContextId".into(), "app_id".into()),
|
|
|
|
("Type".into(), (ut as i32).into()),
|
|
|
|
("Payload".into(), payload.into()),
|
|
|
|
])]),
|
|
|
|
]);
|
|
|
|
|
|
|
|
serialize(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn create_ping() -> Vec<u8> {
|
|
|
|
serialize(Value::Array(vec![6.into()]))
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
2019-01-28 00:39:14 +01:00
|
|
|
#[derive(PartialEq)]
|
2018-08-30 17:43:46 +02:00
|
|
|
pub enum UpdateType {
|
2018-12-30 23:34:31 +01:00
|
|
|
CipherUpdate = 0,
|
|
|
|
CipherCreate = 1,
|
|
|
|
LoginDelete = 2,
|
|
|
|
FolderDelete = 3,
|
|
|
|
Ciphers = 4,
|
|
|
|
|
|
|
|
Vault = 5,
|
|
|
|
OrgKeys = 6,
|
|
|
|
FolderCreate = 7,
|
|
|
|
FolderUpdate = 8,
|
|
|
|
CipherDelete = 9,
|
2018-08-30 17:43:46 +02:00
|
|
|
SyncSettings = 10,
|
|
|
|
|
|
|
|
LogOut = 11,
|
2019-01-28 00:39:14 +01:00
|
|
|
|
2021-03-14 23:35:55 +01:00
|
|
|
SyncSendCreate = 12,
|
|
|
|
SyncSendUpdate = 13,
|
|
|
|
SyncSendDelete = 14,
|
|
|
|
|
2019-01-28 00:39:14 +01:00
|
|
|
None = 100,
|
2018-08-30 17:43:46 +02:00
|
|
|
}
|
|
|
|
|
2018-12-30 23:34:31 +01:00
|
|
|
use rocket::State;
|
|
|
|
pub type Notify<'a> = State<'a, WebSocketUsers>;
|
|
|
|
|
2018-08-30 17:43:46 +02:00
|
|
|
pub fn start_notification_server() -> WebSocketUsers {
|
2021-03-27 15:26:32 +01:00
|
|
|
let factory = WsFactory::init();
|
2018-08-30 17:43:46 +02:00
|
|
|
let users = factory.users.clone();
|
|
|
|
|
2019-01-25 18:23:51 +01:00
|
|
|
if CONFIG.websocket_enabled() {
|
2018-10-15 16:08:15 +02:00
|
|
|
thread::spawn(move || {
|
2021-03-27 15:03:31 +01:00
|
|
|
let settings = ws::Settings {
|
|
|
|
max_connections: 500,
|
|
|
|
queue_size: 2,
|
|
|
|
panic_on_internal: false,
|
|
|
|
..Default::default()
|
|
|
|
};
|
2020-01-04 23:52:38 +01:00
|
|
|
|
|
|
|
ws::Builder::new()
|
|
|
|
.with_settings(settings)
|
|
|
|
.build(factory)
|
2019-01-25 18:23:51 +01:00
|
|
|
.unwrap()
|
2019-02-02 01:09:21 +01:00
|
|
|
.listen((CONFIG.websocket_address().as_str(), CONFIG.websocket_port()))
|
2019-01-25 18:23:51 +01:00
|
|
|
.unwrap();
|
2018-10-15 16:08:15 +02:00
|
|
|
});
|
|
|
|
}
|
2018-08-30 17:43:46 +02:00
|
|
|
|
|
|
|
users
|
|
|
|
}
|