🏡 index : ~doyle/titanirc.git

author Jordan Doyle <jordan@doyle.la> 2023-01-08 1:45:10.0 +00:00:00
committer Jordan Doyle <jordan@doyle.la> 2023-01-08 1:45:10.0 +00:00:00
commit
4baa711cb36920dc28229e6106d76cd5ea88da24 [patch]
tree
185388ef1687064a78b0e124bd1f8961ee486aa4
parent
fc6e6eaef3e1fa32c97da7b14f0a68d080ee356f
download
4baa711cb36920dc28229e6106d76cd5ea88da24.tar.gz

Start Server and Channels in a supervisor



Diff

 src/channel.rs |  4 +++-
 src/main.rs    |  4 ++--
 src/server.rs  |  9 +++++++--
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/channel.rs b/src/channel.rs
index 371de39..50b607e 100644
--- a/src/channel.rs
+++ b/src/channel.rs
@@ -4,7 +4,7 @@ use std::collections::HashMap;

use actix::{
    Actor, ActorFutureExt, Addr, AsyncContext, Context, Handler, MessageResult, ResponseActFuture,
    WrapFuture,
    Supervised, WrapFuture,
};
use chrono::{DateTime, Utc};
use futures::future::Either;
@@ -36,6 +36,8 @@ impl Actor for Channel {
    type Context = Context<Self>;
}

impl Supervised for Channel {}

/// Broadcast a raw IRC message to all clients connected to this channel.
impl Handler<Broadcast> for Channel {
    type Result = ();
diff --git a/src/main.rs b/src/main.rs
index 0aced60..4b9f2a0 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,7 +3,7 @@

use std::{collections::HashMap, sync::Arc};

use actix::{io::FramedWrite, Actor, Addr, AsyncContext};
use actix::{io::FramedWrite, Actor, Addr, AsyncContext, Supervisor};
use actix_rt::{Arbiter, System};
use clap::Parser;
use irc_proto::IrcCodec;
@@ -48,7 +48,7 @@ async fn main() -> anyhow::Result<()> {
    let listen_address = opts.config.listen_address;
    let client_threads = opts.config.client_threads;

    let server = Server::start_in_arbiter(&Arbiter::new().handle(), |_ctx| Server {
    let server = Supervisor::start_in_arbiter(&Arbiter::new().handle(), |_ctx| Server {
        channels: HashMap::default(),
        clients: HashMap::default(),
        channel_arbiters: build_arbiters(opts.config.channel_threads),
diff --git a/src/server.rs b/src/server.rs
index fb9972b..699bc0b 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -2,7 +2,10 @@ pub mod response;

use std::collections::HashMap;

use actix::{Actor, Addr, AsyncContext, Context, Handler, MessageResult, ResponseFuture};
use actix::{
    Actor, Addr, AsyncContext, Context, Handler, MessageResult, ResponseFuture, Supervised,
    Supervisor,
};
use actix_rt::Arbiter;
use futures::{stream::FuturesOrdered, TryFutureExt};
use irc_proto::{Command, Message, Prefix, Response};
@@ -32,6 +35,8 @@ pub struct Server {
    pub config: Config,
}

impl Supervised for Server {}

/// Received when an admin SANICKs another user.
impl Handler<UserNickChangeInternal> for Server {
    type Result = ();
@@ -148,7 +153,7 @@ impl Handler<ChannelJoin> for Server {
                let channel_name = msg.channel_name.clone();
                let server = ctx.address();

                Channel::start_in_arbiter(&arbiter, move |_ctx| Channel {
                Supervisor::start_in_arbiter(&arbiter, move |_ctx| Channel {
                    name: channel_name,
                    clients: HashMap::new(),
                    topic: None,