Skip to content

Commit

Permalink
Added the configuration parameters iiop_out_ports_attempts and iiop_o…
Browse files Browse the repository at this point in the history
…ut_ports_random.
  • Loading branch information
Niclas Eklund authored and Erlang/OTP committed Feb 15, 2010
1 parent 4ec4a06 commit 45f0a49
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 43 deletions.
23 changes: 20 additions & 3 deletions lib/orber/doc/src/ch_install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<chapter>
<header>
<copyright>
<year>1997</year><year>2009</year>
<year>1997</year><year>2010</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
Expand All @@ -13,12 +13,12 @@
compliance with the License. You should have received a copy of the
Erlang Public License along with this software. If not, it can be
retrieved online at http://www.erlang.org/.

Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
the License for the specific language governing rights and limitations
under the License.

</legalnotice>

<title>Installing Orber</title>
Expand Down Expand Up @@ -233,6 +233,16 @@ nodeB@hostB> orber:start().
<cell align="left" valign="middle">0 | {integer(),integer()}</cell>
<cell align="left" valign="middle">0</cell>
</row>
<row>
<cell align="left" valign="middle">iiop_out_ports_attempts</cell>
<cell align="left" valign="middle">integer() > 0</cell>
<cell align="left" valign="middle">1</cell>
</row>
<row>
<cell align="left" valign="middle">iiop_out_ports_random</cell>
<cell align="left" valign="middle">true | false</cell>
<cell align="left" valign="middle">false</cell>
</row>
<row>
<cell align="left" valign="middle">iiop_max_fragments</cell>
<cell align="left" valign="middle">integer() > 0 | infinity</cell>
Expand Down Expand Up @@ -506,6 +516,13 @@ nodeB@hostB> orber:start().
If communicating via SSL, make sure you use a version that supports
the local <c>{port, Port}</c> option. See also
<seealso marker="ch_install#firewall">Firewall Configuration</seealso>.</item>
<tag><em>iiop_out_ports_random</em></tag>
<item>Requires that <c>iiop_out_ports</c> define a port range. If that is the
case Orber will select a port randomly from that sequence.</item>
<tag><em>iiop_out_ports_attempts</em></tag>
<item>Requires that <c>iiop_out_ports</c> define a port range. If so Orber will
accept a number of timeouts, defined by this parameter, when trying to connect
to another ORB.</item>
<tag><em>iiop_max_fragments</em></tag>
<item>Limits the number of IIOP fragments allowed per request.</item>
<tag><em>iiop_max_in_requests</em></tag>
Expand Down
7 changes: 7 additions & 0 deletions lib/orber/doc/src/notes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
<section>
<title>Improvements and New Features</title>
<list type="bulleted">
<item>
<p>
Added the configuration parameters iiop_out_ports_attempts and
iiop_out_ports_random.</p>
<p>
Own Id: OTP-8448 Aux Id: seq11498</p>
</item>
<item>
<p>
Removed obsolete SSL dependency.</p>
Expand Down
30 changes: 25 additions & 5 deletions lib/orber/doc/src/orber.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<erlref>
<header>
<copyright>
<year>1997</year><year>2009</year>
<year>1997</year><year>2010</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
Expand All @@ -13,12 +13,12 @@
compliance with the License. You should have received a copy of the
Erlang Public License along with this software. If not, it can be
retrieved online at http://www.erlang.org/.

Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
the License for the specific language governing rights and limitations
under the License.

</legalnotice>

<title>orber</title>
Expand Down Expand Up @@ -162,13 +162,33 @@
</func>
<func>
<name>iiop_out_ports() -> 0 | {Min, Max}</name>
<fsummary>Display the ports Orber may use when connecting to another ORB</fsummary>
<fsummary>Display the ports Orber may use when connecting to another ORB</fsummary>
<desc>
<p>The return value of this operation is what the configuration
parameter <seealso marker="ch_install#config">iiop_out_ports</seealso>
have been set to.</p>
has been set to.</p>
</desc>
</func>

<func>
<name>iiop_out_ports_random() -> true | false</name>
<fsummary>Determine if Orber should select local ports randomly</fsummary>
<desc>
<p>Return the value of the configuration parameter
<seealso marker="ch_install#config">iiop_out_ports_random</seealso>.</p>
</desc>
</func>

<func>
<name>iiop_out_ports_attempts() -> int()</name>
<fsummary>Display if Orber should accept more than one timeout connecting to another ORB</fsummary>
<desc>
<p>Return the value of the configuration parameter
<seealso marker="ch_install#config">iiop_out_ports_attempts</seealso>.</p>
</desc>
</func>


<func>
<name>iiop_ssl_port() -> int()</name>
<fsummary>Display the IIOP port number used for secure connections</fsummary>
Expand Down
19 changes: 13 additions & 6 deletions lib/orber/src/orber.erl
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
%%--------------------------------------------------------------------
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 1997-2009. All Rights Reserved.
%%
%%
%% Copyright Ericsson AB 1997-2010. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
%% compliance with the License. You should have received a copy of the
%% Erlang Public License along with this software. If not, it can be
%% retrieved online at http://www.erlang.org/.
%%
%%
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%% the License for the specific language governing rights and limitations
%% under the License.
%%
%%
%% %CopyrightEnd%
%%
%%
Expand All @@ -34,7 +34,8 @@
%% External exports
%%-----------------------------------------------------------------
-export([start/0, start/1, stop/0, install/1, install/2, orber_nodes/0, iiop_port/0,
domain/0, iiop_ssl_port/0, iiop_out_ports/0,
domain/0, iiop_ssl_port/0, iiop_out_ports/0, iiop_out_ports_random/0,
iiop_out_ports_attempts/0,
ssl_server_certfile/0, ssl_client_certfile/0, set_ssl_client_certfile/1,
ssl_server_verify/0, ssl_client_verify/0, set_ssl_client_verify/1,
ssl_server_depth/0, ssl_client_depth/0, set_ssl_client_depth/1,
Expand Down Expand Up @@ -305,6 +306,12 @@ nat_iiop_port() ->
iiop_out_ports() ->
orber_env:iiop_out_ports().

iiop_out_ports_random() ->
orber_env:iiop_out_ports_random().

iiop_out_ports_attempts() ->
orber_env:iiop_out_ports_attempts().

orber_nodes() ->
case catch mnesia:table_info(orber_objkeys,ram_copies) of
Nodes when is_list(Nodes) ->
Expand Down
42 changes: 34 additions & 8 deletions lib/orber/src/orber_env.erl
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
%%--------------------------------------------------------------------
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2004-2009. All Rights Reserved.
%%
%%
%% Copyright Ericsson AB 2004-2010. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
%% compliance with the License. You should have received a copy of the
%% Erlang Public License along with this software. If not, it can be
%% retrieved online at http://www.erlang.org/.
%%
%%
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%% the License for the specific language governing rights and limitations
%% under the License.
%%
%%
%% %CopyrightEnd%
%%
%%
Expand Down Expand Up @@ -43,8 +43,8 @@

-export([iiop_acl/0, iiop_port/0, nat_iiop_port/0, nat_iiop_port/1, iiop_out_ports/0,
domain/0, ip_address_variable_defined/0, nat_host/0, nat_host/1, host/0,
ip_address/0, ip_address/1, giop_version/0, iiop_timeout/0,
iiop_connection_timeout/0, iiop_setup_connection_timeout/0,
ip_address/0, ip_address/1, giop_version/0, iiop_timeout/0, iiop_out_ports_random/0,
iiop_connection_timeout/0, iiop_setup_connection_timeout/0, iiop_out_ports_attempts/0,
iiop_in_connection_timeout/0, iiop_max_fragments/0, iiop_max_in_requests/0,
iiop_max_in_connections/0, iiop_backlog/0, objectkeys_gc_time/0,
get_ORBInitRef/0, get_ORBDefaultInitRef/0, get_interceptors/0,
Expand Down Expand Up @@ -234,6 +234,8 @@ create_main_info() ->
"IIOP out connection timeout...: ~p msec~n"
"IIOP setup connection timeout.: ~p msec~n"
"IIOP out ports................: ~p~n"
"IIOP out ports attempts.......: ~p~n"
"IIOP out ports random.........: ~p~n"
"IIOP out connections..........: ~p~n"
"IIOP out connections (pending): ~p~n"
"IIOP out keepalive............: ~p~n"
Expand All @@ -256,7 +258,8 @@ create_main_info() ->
nat_host(), ip_address_local(),
orber:orber_nodes(), Major, Minor,
iiop_timeout(), iiop_connection_timeout(),
iiop_setup_connection_timeout(), iiop_out_ports(),
iiop_setup_connection_timeout(), iiop_out_ports(),
iiop_out_ports_attempts(), iiop_out_ports_random(),
orber:iiop_connections(out), orber:iiop_connections_pending(),
iiop_out_keepalive(), orber:iiop_connections(in),
iiop_in_connection_timeout(), iiop_in_keepalive(),
Expand Down Expand Up @@ -389,6 +392,23 @@ iiop_out_ports() ->
0
end.

iiop_out_ports_random() ->
case application:get_env(orber, iiop_out_ports_random) of
{ok, true} ->
true;
_ ->
false
end.

iiop_out_ports_attempts() ->
case application:get_env(orber, iiop_out_ports_attempts) of
{ok, No} when is_integer(No) andalso No > 0 ->
No;
_ ->
1
end.


domain() ->
case application:get_env(orber, domain) of
{ok, Domain} when is_list(Domain) ->
Expand Down Expand Up @@ -1251,6 +1271,12 @@ configure(nat_ip_address, {local, Value1, Value2}, Status) when is_list(Value1)
%% Set the range of ports we may use on this machine when connecting to a server.
configure(iiop_out_ports, {Min, Max}, Status) when is_integer(Min) andalso is_integer(Max) ->
do_safe_configure(iiop_out_ports, {Min, Max}, Status);
configure(iiop_out_ports_attempts, Max, Status) when is_integer(Max) andalso Max > 0 ->
do_safe_configure(iiop_out_ports_attempts, Max, Status);
configure(iiop_out_ports_random, true, Status) ->
do_safe_configure(iiop_out_ports_random, true, Status);
configure(iiop_out_ports_random, false, Status) ->
do_safe_configure(iiop_out_ports_random, false, Status);
%% Set the lightweight option.
configure(lightweight, Value, Status) when is_list(Value) ->
do_safe_configure(lightweight, Value, Status);
Expand Down
58 changes: 38 additions & 20 deletions lib/orber/src/orber_socket.erl
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
%%--------------------------------------------------------------------
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 1997-2009. All Rights Reserved.
%%
%%
%% Copyright Ericsson AB 1997-2010. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
%% compliance with the License. You should have received a copy of the
%% Erlang Public License along with this software. If not, it can be
%% retrieved online at http://www.erlang.org/.
%%
%%
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%% the License for the specific language governing rights and limitations
%% under the License.
%%
%%
%% %CopyrightEnd%
%%
%%
Expand Down Expand Up @@ -82,17 +82,17 @@ connect(Type, Host, Port, Options) ->
end,
case orber:iiop_out_ports() of
{Min, Max} when Type == normal ->
multi_connect(Min, Max, Type, Host, Port,
[binary, {reuseaddr, true},
{packet,cdr}| Options2], Timeout);
multi_connect(get_port_sequence(Min, Max), orber_env:iiop_out_ports_attempts(),
Type, Host, Port, [binary, {reuseaddr, true},
{packet,cdr}| Options2], Timeout);
{Min, Max} when Generation > 2 ->
multi_connect(Min, Max, Type, Host, Port,
[binary, {reuseaddr, true},
{packet,cdr}| Options2], Timeout);
multi_connect(get_port_sequence(Min, Max), orber_env:iiop_out_ports_attempts(),
Type, Host, Port, [binary, {reuseaddr, true},
{packet,cdr}| Options2], Timeout);
{Min, Max} ->
%% reuseaddr not available for older SSL versions
multi_connect(Min, Max, Type, Host, Port,
[binary, {packet,cdr}| Options2], Timeout);
multi_connect(get_port_sequence(Min, Max), orber_env:iiop_out_ports_attempts(),
Type, Host, Port, [binary, {packet,cdr}| Options2], Timeout);
_ ->
connect(Type, Host, Port, [binary, {packet,cdr}| Options2], Timeout)
end.
Expand Down Expand Up @@ -130,42 +130,60 @@ connect(ssl, Host, Port, Options, Timeout) ->
corba:raise(#'COMM_FAILURE'{completion_status=?COMPLETED_NO})
end.

multi_connect(CurrentPort, Max, Type, Host, Port, Options, _) when CurrentPort > Max ->
multi_connect([], _Retries, Type, Host, Port, Options, _) ->
orber:dbg("[~p] orber_socket:multi_connect(~p, ~p, ~p, ~p);~n"
"Unable to use any of the sockets defined by 'iiop_out_ports'.~n"
"Either all ports are in use or to many connections already exists.",
[?LINE, Type, Host, Port, Options], ?DEBUG_LEVEL),
corba:raise(#'IMP_LIMIT'{minor=(?ORBER_VMCID bor 1), completion_status=?COMPLETED_NO});
multi_connect(CurrentPort, Max, normal, Host, Port, Options, Timeout) ->
multi_connect([CurrentPort|Rest], Retries, normal, Host, Port, Options, Timeout) ->
case catch gen_tcp:connect(Host, Port, [{port, CurrentPort}|Options], Timeout) of
{ok, Socket} ->
Socket;
{error, timeout} ->
{error, timeout} when Retries =< 1 ->
orber:dbg("[~p] orber_socket:multi_connect(normal, ~p, ~p, ~p);~n"
"Timeout after ~p msec.",
[?LINE, Host, Port, [{port, CurrentPort}|Options],
Timeout], ?DEBUG_LEVEL),
corba:raise(#'COMM_FAILURE'{minor=(?ORBER_VMCID bor 4),
completion_status=?COMPLETED_NO});
_ ->
multi_connect(CurrentPort+1, Max, normal, Host, Port, Options, Timeout)
multi_connect(Rest, Retries - 1, normal, Host, Port, Options, Timeout)
end;
multi_connect(CurrentPort, Max, ssl, Host, Port, Options, Timeout) ->
multi_connect([CurrentPort|Rest], Retries, ssl, Host, Port, Options, Timeout) ->
case catch ssl:connect(Host, Port, [{port, CurrentPort}|Options], Timeout) of
{ok, Socket} ->
Socket;
{error, timeout} ->
{error, timeout} when Retries =< 1 ->
orber:dbg("[~p] orber_socket:multi_connect(ssl, ~p, ~p, ~p);~n"
"Timeout after ~p msec.",
[?LINE, Host, Port, [{port, CurrentPort}|Options],
Timeout], ?DEBUG_LEVEL),
corba:raise(#'COMM_FAILURE'{minor=(?ORBER_VMCID bor 4),
completion_status=?COMPLETED_NO});
_ ->
multi_connect(CurrentPort+1, Max, ssl, Host, Port, Options, Timeout)
multi_connect(Rest, Retries - 1, ssl, Host, Port, Options, Timeout)
end.


get_port_sequence(Min, Max) ->
case orber_env:iiop_out_ports_random() of
true ->
{A1,A2,A3} = now(),
random:seed(A1, A2, A3),
Seq = lists:seq(Min, Max),
random_sequence((Max - Min) + 1, Seq, []);
_ ->
lists:seq(Min, Max)
end.

random_sequence(0, _, Acc) ->
Acc;
random_sequence(Length, Seq, Acc) ->
Nth = random:uniform(Length),
Value = lists:nth(Nth, Seq),
NewSeq = lists:delete(Value, Seq),
random_sequence(Length-1, NewSeq, [Value|Acc]).

%%-----------------------------------------------------------------
%% Create a listen socket at Port in CDR mode for
Expand Down
Loading

0 comments on commit 45f0a49

Please sign in to comment.