+ Split ConnectionHandler into its own struct + Handle errors more gracefully + System no longer locks up or crashes if a bot goes offline + Bots who go offline are automatically removed from the connector pool
35 lines
827 B
Rust
35 lines
827 B
Rust
use raas_types::raas;
|
|
use std::collections::HashMap;
|
|
use thiserror::Error;
|
|
use tokio::io::DuplexStream;
|
|
|
|
pub mod connection_handler;
|
|
pub mod robot_connector;
|
|
pub mod robot_manager;
|
|
|
|
pub const ROBOT_MESSAGE_QUEUE_SIZE: usize = 10;
|
|
|
|
#[derive(Debug)]
|
|
pub struct ConnectorHandle {
|
|
pub stream: DuplexStream,
|
|
pub tags: Vec<raas::register::BotTypes>,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct ConnectorManager {
|
|
pub next_id: u32,
|
|
pub connectors: HashMap<u32, ConnectorHandle>,
|
|
}
|
|
|
|
#[derive(Error, Debug)]
|
|
pub enum Error {
|
|
#[error("IO Error")]
|
|
Io(#[from] std::io::Error),
|
|
#[error("Protobuf Encode Error")]
|
|
ProtobufEncode(#[from] prost::EncodeError),
|
|
#[error("Protobuf Decode Error")]
|
|
ProtobufDecode(#[from] prost::DecodeError),
|
|
#[error("Connection to bot has been closed")]
|
|
ConnectionClosed(u32),
|
|
}
|