From b6c16967e75569e023f45f85c273c0ed2ec20f09 Mon Sep 17 00:00:00 2001 From: Jarvis Carroll Date: Sun, 26 Oct 2025 11:23:34 +0000 Subject: [PATCH] notify router of new channels This way the second message received on a channel should be routed by the router without involving the fallback. Lolspeed achieved. --- src/msp_channel_man.erl | 3 +++ src/msp_router.erl | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/msp_channel_man.erl b/src/msp_channel_man.erl index 43b968d..681fe0c 100644 --- a/src/msp_channel_man.erl +++ b/src/msp_channel_man.erl @@ -204,6 +204,9 @@ do_create_channel3(State, Route, Info, ChanID) -> NewConns = maps:put(Route, NewInfo, State#s.connections), NewState = State#s{connections = NewConns}, + % Also add it to the router! + msp_router:add_channel(Info#route_info.router, ChanID, Chan), + {Result, NewState}. do_dispatch(Route, ID, Packet, State) -> diff --git a/src/msp_router.erl b/src/msp_router.erl index 4dc2773..f67a4ad 100644 --- a/src/msp_router.erl +++ b/src/msp_router.erl @@ -9,7 +9,7 @@ -copyright("Jarvis Carroll "). -license("MIT"). --export([begin_routing/4]). +-export([begin_routing/4, add_channel/3]). %% gen_server -export([start_link/0]). @@ -49,6 +49,9 @@ begin_routing(Router, OurSock, {TheirIP, TheirPort}, OurSide) -> {error, Reason} end. +add_channel(Router, ChanID, ChanPID) -> + gen_server:cast(Router, {add_channel, ChanID, ChanPID}). + %%% gen_server -spec start_link() -> Result @@ -72,6 +75,9 @@ handle_call(Unexpected, From, State) -> handle_cast({begin_routing, Sock, Peer, Side}, none) -> State = do_begin_routing(Sock, Peer, Side), {noreply, State}; +handle_cast({add_channel, ChanID, ChanPID}, State) -> + NewState = do_add_channel(ChanID, ChanPID, State), + {noreply, NewState}; handle_cast(Unexpected, State) -> ok = log(warning, "Unexpected cast: ~tp", [Unexpected]), {noreply, State}. @@ -111,6 +117,10 @@ do_begin_routing(Sock, Peer, Side) -> side = Side}, State. +do_add_channel(ChanID, ChanPID, State = #s{connections = Conns}) -> + NewConns = maps:put(ChanID, ChanPID, Conns), + State#s{connections = NewConns}. + do_dispatch(#s{socket = Sock, peer = Peer, connections = Conns}, <>) -> ok = inet:setopts(Sock, [{active, once}]), case maps:find(ID, Conns) of