fix/hosepipe
This commit is contained in:
@@ -36,6 +36,7 @@ async-std = { version = "1.8.0", features = [
|
||||
"tokio02",
|
||||
"attributes",
|
||||
] }
|
||||
async-trait = "0.1.89"
|
||||
|
||||
# core
|
||||
authifier = { version = "1.0.16" }
|
||||
@@ -48,3 +49,6 @@ revolt-presence = { path = "../core/presence", features = ["redis-is-patched"] }
|
||||
|
||||
# redis
|
||||
fred = { version = "8.0.1", features = ["subscriber-client"] }
|
||||
|
||||
# Redis
|
||||
amqprs = { version = "1.7.0" }
|
||||
@@ -1,6 +1,18 @@
|
||||
use std::env;
|
||||
|
||||
use amqprs::{
|
||||
channel::{
|
||||
BasicConsumeArguments, Channel, ExchangeDeclareArguments, QueueBindArguments,
|
||||
QueueDeclareArguments,
|
||||
},
|
||||
connection::{Connection, OpenConnectionArguments},
|
||||
consumer::AsyncConsumer,
|
||||
BasicProperties, Deliver,
|
||||
};
|
||||
use async_std::net::TcpListener;
|
||||
use async_trait::async_trait;
|
||||
use redis_kiss::AsyncCommands;
|
||||
use revolt_database::util::rabbit::set_rabbitmq_connection;
|
||||
use revolt_presence::clear_region;
|
||||
|
||||
#[macro_use]
|
||||
@@ -31,6 +43,53 @@ async fn main() {
|
||||
let try_socket = TcpListener::bind(bind).await;
|
||||
let listener = try_socket.expect("Failed to bind");
|
||||
|
||||
let config = revolt_config::config().await;
|
||||
|
||||
let rmq_conn = Connection::open(&OpenConnectionArguments::new(
|
||||
&config.rabbit.host,
|
||||
config.rabbit.port,
|
||||
&config.rabbit.username,
|
||||
&config.rabbit.password,
|
||||
))
|
||||
.await
|
||||
.expect("Failed to connect to RabbitMQ");
|
||||
|
||||
set_rabbitmq_connection(rmq_conn.clone());
|
||||
|
||||
let channel = rmq_conn
|
||||
.open_channel(None)
|
||||
.await
|
||||
.expect("Failed to open RabbitMQ channel.");
|
||||
|
||||
channel
|
||||
.exchange_declare(
|
||||
ExchangeDeclareArguments::new("events", "fanout")
|
||||
.durable(true)
|
||||
.finish(),
|
||||
)
|
||||
.await
|
||||
.expect("wires");
|
||||
|
||||
channel
|
||||
.queue_declare(QueueDeclareArguments::new("events").durable(true).finish())
|
||||
.await
|
||||
.expect("wires 2");
|
||||
|
||||
channel
|
||||
.queue_bind(QueueBindArguments::new("events", "events", "events"))
|
||||
.await
|
||||
.expect("wires 3");
|
||||
|
||||
channel
|
||||
.basic_consume(
|
||||
RabbitToRedisConsumer,
|
||||
BasicConsumeArguments::new("events", "")
|
||||
.manual_ack(false)
|
||||
.finish(),
|
||||
)
|
||||
.await
|
||||
.expect("wires 4");
|
||||
|
||||
// Start accepting new connections and spawn a client for each connection.
|
||||
while let Ok((stream, addr)) = listener.accept().await {
|
||||
async_std::task::spawn(async move {
|
||||
@@ -40,3 +99,32 @@ async fn main() {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
struct RabbitToRedisConsumer;
|
||||
|
||||
#[async_trait]
|
||||
impl AsyncConsumer for RabbitToRedisConsumer {
|
||||
async fn consume(
|
||||
&mut self,
|
||||
_channel: &Channel,
|
||||
_deliver: Deliver,
|
||||
basic_properties: BasicProperties,
|
||||
content: Vec<u8>,
|
||||
) {
|
||||
let mut redis_conn = redis_kiss::get_connection()
|
||||
.await
|
||||
.expect("Failed to connect to Redis.");
|
||||
|
||||
let pubsub_channel = basic_properties
|
||||
.headers()
|
||||
.expect("No headers")
|
||||
.get(&"c".try_into().unwrap())
|
||||
.expect("No channel header")
|
||||
.to_string();
|
||||
|
||||
redis_conn
|
||||
.publish(pubsub_channel, content)
|
||||
.await
|
||||
.expect("failed to publish")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -464,30 +464,30 @@ async fn worker(
|
||||
|
||||
match payload {
|
||||
// disabled events
|
||||
// ClientMessage::BeginTyping { channel } => {
|
||||
// if !subscribed.read().await.contains(&channel) {
|
||||
// continue;
|
||||
// }
|
||||
ClientMessage::BeginTyping { channel } => {
|
||||
if !subscribed.read().await.contains(&channel) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// EventV1::ChannelStartTyping {
|
||||
// id: channel.clone(),
|
||||
// user: user_id.clone(),
|
||||
// }
|
||||
// .p(channel.clone())
|
||||
// .await;
|
||||
// }
|
||||
// ClientMessage::EndTyping { channel } => {
|
||||
// if !subscribed.read().await.contains(&channel) {
|
||||
// continue;
|
||||
// }
|
||||
EventV1::ChannelStartTyping {
|
||||
id: channel.clone(),
|
||||
user: user_id.clone(),
|
||||
}
|
||||
.p(channel.clone())
|
||||
.await;
|
||||
}
|
||||
ClientMessage::EndTyping { channel } => {
|
||||
if !subscribed.read().await.contains(&channel) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// EventV1::ChannelStopTyping {
|
||||
// id: channel.clone(),
|
||||
// user: user_id.clone(),
|
||||
// }
|
||||
// .p(channel.clone())
|
||||
// .await;
|
||||
// }
|
||||
EventV1::ChannelStopTyping {
|
||||
id: channel.clone(),
|
||||
user: user_id.clone(),
|
||||
}
|
||||
.p(channel.clone())
|
||||
.await;
|
||||
}
|
||||
ClientMessage::Subscribe { server_id } => {
|
||||
let mut servers = active_servers.lock().await;
|
||||
let has_item = servers.contains_key(&server_id);
|
||||
|
||||
Reference in New Issue
Block a user