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:
parent
47612c2775
commit
b6c16967e7
@ -204,6 +204,9 @@ do_create_channel3(State, Route, Info, ChanID) ->
|
|||||||
NewConns = maps:put(Route, NewInfo, State#s.connections),
|
NewConns = maps:put(Route, NewInfo, State#s.connections),
|
||||||
NewState = State#s{connections = NewConns},
|
NewState = State#s{connections = NewConns},
|
||||||
|
|
||||||
|
% Also add it to the router!
|
||||||
|
msp_router:add_channel(Info#route_info.router, ChanID, Chan),
|
||||||
|
|
||||||
{Result, NewState}.
|
{Result, NewState}.
|
||||||
|
|
||||||
do_dispatch(Route, ID, Packet, State) ->
|
do_dispatch(Route, ID, Packet, State) ->
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
-copyright("Jarvis Carroll <spiveehere@gmail.com>").
|
-copyright("Jarvis Carroll <spiveehere@gmail.com>").
|
||||||
-license("MIT").
|
-license("MIT").
|
||||||
|
|
||||||
-export([begin_routing/4]).
|
-export([begin_routing/4, add_channel/3]).
|
||||||
|
|
||||||
%% gen_server
|
%% gen_server
|
||||||
-export([start_link/0]).
|
-export([start_link/0]).
|
||||||
@ -49,6 +49,9 @@ begin_routing(Router, OurSock, {TheirIP, TheirPort}, OurSide) ->
|
|||||||
{error, Reason}
|
{error, Reason}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
add_channel(Router, ChanID, ChanPID) ->
|
||||||
|
gen_server:cast(Router, {add_channel, ChanID, ChanPID}).
|
||||||
|
|
||||||
%%% gen_server
|
%%% gen_server
|
||||||
|
|
||||||
-spec start_link() -> Result
|
-spec start_link() -> Result
|
||||||
@ -72,6 +75,9 @@ handle_call(Unexpected, From, State) ->
|
|||||||
handle_cast({begin_routing, Sock, Peer, Side}, none) ->
|
handle_cast({begin_routing, Sock, Peer, Side}, none) ->
|
||||||
State = do_begin_routing(Sock, Peer, Side),
|
State = do_begin_routing(Sock, Peer, Side),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
|
handle_cast({add_channel, ChanID, ChanPID}, State) ->
|
||||||
|
NewState = do_add_channel(ChanID, ChanPID, State),
|
||||||
|
{noreply, NewState};
|
||||||
handle_cast(Unexpected, State) ->
|
handle_cast(Unexpected, State) ->
|
||||||
ok = log(warning, "Unexpected cast: ~tp", [Unexpected]),
|
ok = log(warning, "Unexpected cast: ~tp", [Unexpected]),
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
@ -111,6 +117,10 @@ do_begin_routing(Sock, Peer, Side) ->
|
|||||||
side = Side},
|
side = Side},
|
||||||
State.
|
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>>) ->
|
do_dispatch(#s{socket = Sock, peer = Peer, connections = Conns}, <<ID:8, Packet/bytes>>) ->
|
||||||
ok = inet:setopts(Sock, [{active, once}]),
|
ok = inet:setopts(Sock, [{active, once}]),
|
||||||
case maps:find(ID, Conns) of
|
case maps:find(ID, Conns) of
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user