Skip to content

Commit

Permalink
ssh: handshakers removal prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
u3s committed Dec 20, 2024
1 parent 0d80df5 commit ab5836e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 27 deletions.
29 changes: 5 additions & 24 deletions lib/ssh/src/ssh_acceptor.erl
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,8 @@ acceptor_loop(Port, Address, Opts, ListenSocket, AcceptTimeout, SystemSup) ->
PeerName = inet:peername(Socket),
MaxSessions = ?GET_OPT(max_sessions, Opts),
NumSessions = number_of_connections(SystemSup),
ParallelLogin = ?GET_OPT(parallel_login, Opts),
case handle_connection(Address, Port, PeerName, Opts, Socket,
MaxSessions, NumSessions, ParallelLogin) of
MaxSessions, NumSessions) of
{error,Error} ->
catch close(Socket, Opts),
handle_error(Error, Address, Port, PeerName);
Expand All @@ -156,33 +155,15 @@ acceptor_loop(Port, Address, Opts, ListenSocket, AcceptTimeout, SystemSup) ->

%%%----------------------------------------------------------------
handle_connection(_Address, _Port, _Peer, _Options, _Socket,
MaxSessions, NumSessions, _ParallelLogin)
MaxSessions, NumSessions)
when NumSessions >= MaxSessions->
{error,{max_sessions,MaxSessions}};
handle_connection(_Address, _Port, {error,Error}, _Options, _Socket,
_MaxSessions, _NumSessions, _ParallelLogin) ->
_MaxSessions, _NumSessions) ->
{error,Error};
handle_connection(Address, Port, _Peer, Options, Socket,
_MaxSessions, _NumSessions, ParallelLogin)
when ParallelLogin == false ->
handle_connection(Address, Port, Options, Socket);
handle_connection(Address, Port, _Peer, Options, Socket,
_MaxSessions, _NumSessions, ParallelLogin)
when ParallelLogin == true ->
Ref = make_ref(),
Pid = spawn_link(
fun() ->
process_flag(trap_exit, true),
receive
{start,Ref} ->
handle_connection(Address, Port, Options, Socket)
after 10000 ->
{error, timeout2}
end
end),
catch gen_tcp:controlling_process(Socket, Pid),
Pid ! {start,Ref},
ok.
_MaxSessions, _NumSessions) ->
handle_connection(Address, Port, Options, Socket).

handle_connection(Address, Port, Options, Socket) ->
AddressR = #address{address = Address, port = Port,
Expand Down
11 changes: 8 additions & 3 deletions lib/ssh/src/ssh_connection_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ takeover(ConnPid, Role, Socket, Options) ->
Options,
?GET_OPT(negotiation_timeout, Options)
),
handshake(ConnPid, Role, Ref, NegTimeout);
ParallelLogin = ?GET_OPT(parallel_login, Options, disabled),
handshake(ConnPid, Role, Ref, NegTimeout, ParallelLogin);
{error, Reason} ->
{error, Reason}
end.
Expand Down Expand Up @@ -491,7 +492,11 @@ init_ssh_record(Role, Socket, PeerAddr, Opts) ->
}
end.

handshake(ConnPid, server, Ref, Timeout) ->
handshake(ConnPid, server, Ref, _Timeout, true) ->
%% FIXME how ssh_connected messages should be cleaned, flushed?
erlang:demonitor(Ref, [flush]),
{ok, ConnPid};
handshake(ConnPid, server, Ref, Timeout, _) ->
receive
{ConnPid, ssh_connected} ->
erlang:demonitor(Ref, [flush]),
Expand All @@ -511,7 +516,7 @@ handshake(ConnPid, server, Ref, Timeout) ->
ssh_connection_handler:stop(ConnPid),
{error, timeout}
end;
handshake(ConnPid, client, Ref, Timeout) ->
handshake(ConnPid, client, Ref, Timeout, _) ->
receive
{ConnPid, ssh_connected} ->
erlang:demonitor(Ref, [flush]),
Expand Down

0 comments on commit ab5836e

Please sign in to comment.