From 45f0a499399aa9e8bb41187bbf83d72c11fa4940 Mon Sep 17 00:00:00 2001 From: Niclas Eklund Date: Mon, 15 Feb 2010 14:33:04 +0000 Subject: Added the configuration parameters iiop_out_ports_attempts and iiop_out_ports_random. --- lib/orber/doc/src/ch_install.xml | 23 +++++++++++++--- lib/orber/doc/src/notes.xml | 7 +++++ lib/orber/doc/src/orber.xml | 30 +++++++++++++++++---- lib/orber/src/orber.erl | 19 ++++++++----- lib/orber/src/orber_env.erl | 42 +++++++++++++++++++++++------ lib/orber/src/orber_socket.erl | 58 ++++++++++++++++++++++++++-------------- lib/orber/vsn.mk | 3 ++- 7 files changed, 139 insertions(+), 43 deletions(-) diff --git a/lib/orber/doc/src/ch_install.xml b/lib/orber/doc/src/ch_install.xml index ab5885954b..dde4bf4006 100644 --- a/lib/orber/doc/src/ch_install.xml +++ b/lib/orber/doc/src/ch_install.xml @@ -4,7 +4,7 @@
- 19972009 + 19972010 Ericsson AB. All Rights Reserved. @@ -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. - + Installing Orber @@ -233,6 +233,16 @@ nodeB@hostB> orber:start(). 0 | {integer(),integer()} 0 + + iiop_out_ports_attempts + integer() > 0 + 1 + + + iiop_out_ports_random + true | false + false + iiop_max_fragments integer() > 0 | infinity @@ -506,6 +516,13 @@ nodeB@hostB> orber:start(). If communicating via SSL, make sure you use a version that supports the local {port, Port} option. See also Firewall Configuration. + iiop_out_ports_random + Requires that iiop_out_ports define a port range. If that is the + case Orber will select a port randomly from that sequence. + iiop_out_ports_attempts + Requires that iiop_out_ports define a port range. If so Orber will + accept a number of timeouts, defined by this parameter, when trying to connect + to another ORB. iiop_max_fragments Limits the number of IIOP fragments allowed per request. iiop_max_in_requests diff --git a/lib/orber/doc/src/notes.xml b/lib/orber/doc/src/notes.xml index c7a2dab617..d388cc42a8 100644 --- a/lib/orber/doc/src/notes.xml +++ b/lib/orber/doc/src/notes.xml @@ -38,6 +38,13 @@
Improvements and New Features + +

+ Added the configuration parameters iiop_out_ports_attempts and + iiop_out_ports_random.

+

+ Own Id: OTP-8448 Aux Id: seq11498

+

Removed obsolete SSL dependency.

diff --git a/lib/orber/doc/src/orber.xml b/lib/orber/doc/src/orber.xml index 05036667cc..5e38e4cf9f 100644 --- a/lib/orber/doc/src/orber.xml +++ b/lib/orber/doc/src/orber.xml @@ -4,7 +4,7 @@
- 19972009 + 19972010 Ericsson AB. All Rights Reserved. @@ -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. - + orber @@ -162,13 +162,33 @@ iiop_out_ports() -> 0 | {Min, Max} - Display the ports Orber may use when connecting to another ORB + Display the ports Orber may use when connecting to another ORB

The return value of this operation is what the configuration parameter iiop_out_ports - have been set to.

+ has been set to.

+
+
+ + + iiop_out_ports_random() -> true | false + Determine if Orber should select local ports randomly + +

Return the value of the configuration parameter + iiop_out_ports_random.

+ + + iiop_out_ports_attempts() -> int() + Display if Orber should accept more than one timeout connecting to another ORB + +

Return the value of the configuration parameter + iiop_out_ports_attempts.

+
+
+ + iiop_ssl_port() -> int() Display the IIOP port number used for secure connections diff --git a/lib/orber/src/orber.erl b/lib/orber/src/orber.erl index e9c6822551..c3d37ad1fb 100644 --- a/lib/orber/src/orber.erl +++ b/lib/orber/src/orber.erl @@ -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% %% %% @@ -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, @@ -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) -> diff --git a/lib/orber/src/orber_env.erl b/lib/orber/src/orber_env.erl index 79f852eee0..d80edb4ee0 100644 --- a/lib/orber/src/orber_env.erl +++ b/lib/orber/src/orber_env.erl @@ -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% %% %% @@ -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, @@ -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" @@ -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(), @@ -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) -> @@ -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); diff --git a/lib/orber/src/orber_socket.erl b/lib/orber/src/orber_socket.erl index 2a64bd4e75..af6df01b7d 100644 --- a/lib/orber/src/orber_socket.erl +++ b/lib/orber/src/orber_socket.erl @@ -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% %% %% @@ -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. @@ -130,17 +130,17 @@ 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], @@ -148,13 +148,13 @@ multi_connect(CurrentPort, Max, normal, Host, Port, Options, Timeout) -> 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], @@ -162,10 +162,28 @@ multi_connect(CurrentPort, Max, ssl, Host, Port, Options, Timeout) -> 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 diff --git a/lib/orber/vsn.mk b/lib/orber/vsn.mk index b56172d7cf..d074bfb86c 100644 --- a/lib/orber/vsn.mk +++ b/lib/orber/vsn.mk @@ -4,7 +4,8 @@ ORBER_VSN = 3.6.15 TICKETS = OTP-8353 \ OTP-8354 \ OTP-8374 \ - OTP-8409 + OTP-8409 \ + OTP-8448 TICKETS_3.6.14 = OTP-8201 -- cgit v1.2.3