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.
This commit is contained in:
Jarvis Carroll 2025-10-26 11:23:34 +00:00
parent 47612c2775
commit b6c16967e7
2 changed files with 14 additions and 1 deletions

View File

@ -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) ->

View File

@ -9,7 +9,7 @@
-copyright("Jarvis Carroll <spiveehere@gmail.com>").
-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}, <<ID:8, Packet/bytes>>) ->
ok = inet:setopts(Sock, [{active, once}]),
case maps:find(ID, Conns) of