rename Connection to Router
Connection is more of a supervision concept than a server concept. I should have a SWP of SWPs too, but I can't be bothered just yet.
This commit is contained in:
parent
669b2e51e1
commit
cfd9eb748f
@ -29,7 +29,7 @@
|
|||||||
{chan_pid :: pid()}).
|
{chan_pid :: pid()}).
|
||||||
|
|
||||||
-record(route_info,
|
-record(route_info,
|
||||||
{conn_pid :: pid(),
|
{router :: pid(),
|
||||||
socket :: gen_udp:socket(),
|
socket :: gen_udp:socket(),
|
||||||
unused_channels :: [integer()],
|
unused_channels :: [integer()],
|
||||||
used_channels :: #{integer() => #channel{}}}).
|
used_channels :: #{integer() => #channel{}}}).
|
||||||
@ -41,16 +41,16 @@
|
|||||||
|
|
||||||
%%% Service Interface
|
%%% Service Interface
|
||||||
|
|
||||||
update_router(OurPort, TheirIP, TheirPort, Conn, Sock) ->
|
update_router(OurPort, TheirIP, TheirPort, Router, Sock) ->
|
||||||
Route = #route{from = OurPort, to = {TheirIP, TheirPort}},
|
Route = #route{from = OurPort, to = {TheirIP, TheirPort}},
|
||||||
gen_server:cast(?MODULE, {update_router, Route, Conn, Sock}).
|
gen_server:cast(?MODULE, {update_router, Route, Router, Sock}).
|
||||||
|
|
||||||
create_channel(OurPort, TheirIP, TheirPort) ->
|
create_channel(OurPort, TheirIP, TheirPort) ->
|
||||||
Route = #route{from = OurPort, to = {TheirIP, TheirPort}},
|
Route = #route{from = OurPort, to = {TheirIP, TheirPort}},
|
||||||
gen_server:call(?MODULE, {create_channel, Route}).
|
gen_server:call(?MODULE, {create_channel, Route}).
|
||||||
|
|
||||||
% Deliver messages on behalf of msp_connection, if it doesn't know where to
|
% Deliver messages on behalf of msp_router, if it doesn't know where to send
|
||||||
% send something.
|
% something.
|
||||||
dispatch_fallback(OurPort, TheirIP, TheirPort, ID, Packet) ->
|
dispatch_fallback(OurPort, TheirIP, TheirPort, ID, Packet) ->
|
||||||
Route = #route{from = OurPort, to = {TheirIP, TheirPort}},
|
Route = #route{from = OurPort, to = {TheirIP, TheirPort}},
|
||||||
gen_server:cast(?MODULE, {dispatch, Route, ID, Packet}).
|
gen_server:cast(?MODULE, {dispatch, Route, ID, Packet}).
|
||||||
@ -89,8 +89,8 @@ handle_call(Unexpected, From, State) ->
|
|||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
|
|
||||||
handle_cast({update_router, Route, Conn, Sock}, State) ->
|
handle_cast({update_router, Route, Router, Sock}, State) ->
|
||||||
NewState = do_update_router(Route, Conn, Sock, State),
|
NewState = do_update_router(Route, Router, Sock, State),
|
||||||
{noreply, NewState};
|
{noreply, NewState};
|
||||||
handle_cast({dispatch, Route, ID, Packet}, State) ->
|
handle_cast({dispatch, Route, ID, Packet}, State) ->
|
||||||
NewState = do_dispatch(Route, ID, Packet, State),
|
NewState = do_dispatch(Route, ID, Packet, State),
|
||||||
@ -149,13 +149,13 @@ do_enroll2(PID, State, Channels) ->
|
|||||||
State
|
State
|
||||||
end.
|
end.
|
||||||
|
|
||||||
do_update_router(Route, Conn, Sock, State = #s{connections = Conns}) ->
|
do_update_router(Route, Router, Sock, State = #s{connections = Conns}) ->
|
||||||
case maps:find(Route, Conns) of
|
case maps:find(Route, Conns) of
|
||||||
{ok, _Info} ->
|
{ok, _Info} ->
|
||||||
io:format("Updating routes not yet implemented.~n", []),
|
io:format("Updating routes not yet implemented.~n", []),
|
||||||
init:stop();
|
init:stop();
|
||||||
error ->
|
error ->
|
||||||
NewConn = #route_info{conn_pid = Conn,
|
NewConn = #route_info{router = Router,
|
||||||
socket = Sock,
|
socket = Sock,
|
||||||
unused_channels = lists:seq(0, 255),
|
unused_channels = lists:seq(0, 255),
|
||||||
used_channels = #{}},
|
used_channels = #{}},
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
%%% Minimal Stream Protocol: Connection Worker
|
%%% Minimal Stream Protocol: Connection Worker
|
||||||
%%% @end
|
%%% @end
|
||||||
|
|
||||||
-module(msp_connection).
|
-module(msp_router).
|
||||||
-vsn("0.1.0").
|
-vsn("0.1.0").
|
||||||
-behavior(gen_server).
|
-behavior(gen_server).
|
||||||
-author("Jarvis Carroll <spiveehere@gmail.com>").
|
-author("Jarvis Carroll <spiveehere@gmail.com>").
|
||||||
@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
% msp does not negotiate new connections, but once you have a
|
% msp does not negotiate new connections, but once you have a
|
||||||
% socket, and a host that knows you will be talking MSP, then a
|
% socket, and a host that knows you will be talking MSP, then a
|
||||||
% new msp_connection can be initialized.
|
% new msp_router can be initialized.
|
||||||
begin_msp(Connection, OurSock, TheirIP, TheirPort, OurSide) ->
|
begin_msp(Connection, OurSock, TheirIP, TheirPort, OurSide) ->
|
||||||
% Transfer the socket to the gen_server. If it is
|
% Transfer the socket to the gen_server. If it is
|
||||||
% active then a bunch of messages will be received
|
% active then a bunch of messages will be received
|
||||||
@ -59,7 +59,7 @@ start_link() ->
|
|||||||
gen_server:start_link(?MODULE, none, []).
|
gen_server:start_link(?MODULE, none, []).
|
||||||
|
|
||||||
|
|
||||||
% TODO: Ask msp_connection_man for the socket and endpoint
|
% TODO: SWP? SWP of SWPs?
|
||||||
init(none) ->
|
init(none) ->
|
||||||
{ok, none}.
|
{ok, none}.
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user