From ffb43b2ec0f8ec8bbe15dea3675242b69c6a4516 Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Mon, 21 Jan 2013 14:50:44 +0100 Subject: Remove upgrade code not needed at a major release --- lib/diameter/src/base/diameter_peer.erl | 13 +---- lib/diameter/src/base/diameter_peer_fsm.erl | 47 ++++-------------- lib/diameter/src/base/diameter_service.erl | 74 +++-------------------------- lib/diameter/src/base/diameter_watchdog.erl | 29 +++-------- 4 files changed, 23 insertions(+), 140 deletions(-) (limited to 'lib/diameter/src/base') diff --git a/lib/diameter/src/base/diameter_peer.erl b/lib/diameter/src/base/diameter_peer.erl index 1b2f32ddff..25c9eab4cb 100644 --- a/lib/diameter/src/base/diameter_peer.erl +++ b/lib/diameter/src/base/diameter_peer.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2010-2012. All Rights Reserved. +%% Copyright Ericsson AB 2010-2013. 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 @@ -33,9 +33,6 @@ abort/1, notify/2]). -%% Old interface only called from old code. --export([start/3]). %% < diameter-1.2 (R15B02) - %% Server start. -export([start_link/0]). @@ -72,14 +69,6 @@ notify(SvcName, T) -> rpc:abcast(nodes(), ?SERVER, {notify, SvcName, T}). -%%% --------------------------------------------------------------------------- -%%% # start/3 -%%% --------------------------------------------------------------------------- - -%% From old code: make it restart. -start(_T, _Opts, #diameter_service{}) -> - {error, restart}. - %%% --------------------------------------------------------------------------- %%% # start/1 %%% --------------------------------------------------------------------------- diff --git a/lib/diameter/src/base/diameter_peer_fsm.erl b/lib/diameter/src/base/diameter_peer_fsm.erl index 858870566f..5dab6214b1 100644 --- a/lib/diameter/src/base/diameter_peer_fsm.erl +++ b/lib/diameter/src/base/diameter_peer_fsm.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2010-2012. All Rights Reserved. +%% Copyright Ericsson AB 2010-2013. 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 @@ -95,10 +95,8 @@ -record(state, {state %% of RFC 3588 Peer State Machine - :: 'Wait-Conn-Ack' %% old code - | {'Wait-Conn-Ack', uint32()} + :: {'Wait-Conn-Ack', uint32()} | recv_CER - | 'Wait-CEA' %% old code | {'Wait-CEA', uint32(), uint32()} | 'Open', mode :: accept | connect | {connect, reference()}, @@ -142,8 +140,7 @@ %%% Output: Pid %%% --------------------------------------------------------------------------- --spec start(T, [Opt], #diameter_service{} %% from old code - | {diameter:sequence(), +-spec start(T, [Opt], {diameter:sequence(), diameter:restriction(), #diameter_service{}}) -> pid() @@ -175,9 +172,6 @@ init(T) -> proc_lib:init_ack({ok, self()}), gen_server:enter_loop(?MODULE, [], i(T)). -i({WPid, Type, Opts, #diameter_service{} = Svc}) -> %% from old code - i({WPid, Type, Opts, {?NOMASK, [node() | nodes()], Svc}}); - i({WPid, T, Opts, {Mask, Nodes, #diameter_service{applications = Apps, capabilities = LCaps} = Svc}}) -> @@ -334,10 +328,6 @@ eraser(Key) -> %% transition/2 -%% Started in old code. -transition(T, #state{state = 'Wait-Conn-Ack' = PS} = S) -> - transition(T, S#state{state = {PS, ?EVENT_TIMEOUT}}); - %% Connection to peer. transition({diameter, {TPid, connected, Remote}}, #state{transport = TPid, @@ -401,10 +391,6 @@ transition({send, Msg}, #state{transport = TPid}) -> send(TPid, Msg), ok; -%% Messages from old (diameter_service) code. -transition(shutdown = T, #state{parent = Pid} = S) -> - transition({T, Pid, service}, S); %% Reason irrelevant: old code has no cb - %% Request for graceful shutdown at remove_transport, stop_service of %% application shutdown. transition({shutdown = T, Pid}, S) -> @@ -508,22 +494,13 @@ build_CER(#state{service = #diameter_service{capabilities = LCaps}}) -> %% encode/1 encode(Rec) -> - Seq = diameter_session:sequence(sequence()), + Seq = diameter_session:sequence({_,_} = getr(?SEQUENCE_KEY)), Hdr = #diameter_header{version = ?DIAMETER_VERSION, end_to_end_id = Seq, hop_by_hop_id = Seq}, diameter_codec:encode(?BASE, #diameter_packet{header = Hdr, msg = Rec}). -sequence() -> - case getr(?SEQUENCE_KEY) of - {_,_} = Mask -> - Mask; - undefined -> %% started in old code - putr(?SEQUENCE_KEY, ?NOMASK), - ?NOMASK - end. - %% recv/2 %% RFC 3588 has result code 5015 for an invalid length but if a @@ -585,10 +562,8 @@ rcv('CEA', #diameter_packet{header = #diameter_header{end_to_end_id = Eid, hop_by_hop_id = Hid}} = Pkt, - #state{state = {'Wait-CEA' = T, Hid, Eid}} + #state{state = {'Wait-CEA', Hid, Eid}} = S) -> - handle_CEA(Pkt, S#state{state = T}); -rcv('CEA', Pkt, #state{state = 'Wait-CEA'} = S) -> %% old code handle_CEA(Pkt, S); %% Incoming CER @@ -1021,14 +996,10 @@ dpr(Reason, #state{state = 'Open', dpr = false, service = #diameter_service{capabilities = Caps}} = S) -> - case getr(?DPR_KEY) of - CBs when is_list(CBs) -> - Ref = getr(?REF_KEY), - Peer = {self(), Caps}, - dpr(CBs, [Reason, Ref, Peer], S); - undefined -> %% started in old code - send_dpr(Reason, [], S) - end; + CBs = getr(?DPR_KEY), + Ref = getr(?REF_KEY), + Peer = {self(), Caps}, + dpr(CBs, [Reason, Ref, Peer], S); %% Connection is open, DPR already sent. dpr(_, #state{state = 'Open'}) -> diff --git a/lib/diameter/src/base/diameter_service.erl b/lib/diameter/src/base/diameter_service.erl index 9db3f9e6f8..d2a416166f 100644 --- a/lib/diameter/src/base/diameter_service.erl +++ b/lib/diameter/src/base/diameter_service.erl @@ -361,9 +361,6 @@ find_state(SvcName) -> fs([#state{} = S]) -> S; -fs([S]) -> %% inserted from old code - upgrade(S); - fs([]) -> false. @@ -462,10 +459,6 @@ i(_, false) -> %%% # handle_call(Req, From, State) %%% --------------------------------------------------------------------------- -handle_call(T, From, S) - when not is_record(S, state) -> - handle_call(T, From, upgrade(S)); - handle_call(state, _, S) -> {reply, S, S}; @@ -489,10 +482,6 @@ handle_call({pick_peer, Local, Remote, App}, _From, S) -> handle_call({call_module, AppMod, Req}, From, S) -> call_module(AppMod, Req, From, S); -%% Call from old code. -handle_call({info, Item}, _From, S) -> - {reply, service_info(Item, S), S}; - handle_call(stop, _From, S) -> shutdown(service, S), {stop, normal, ok, S}; @@ -500,14 +489,6 @@ handle_call(stop, _From, S) -> %% gets the reply. We deal with this in the call to the server, %% stating a monitor that waits for DOWN before returning. -%% Watchdog is asking for the sequence mask. -handle_call(sequence, _From, #state{options = [{_, Mask} | _]} = S) -> - {reply, Mask, S}; - -%% Watchdog is asking for the nodes restriction. -handle_call(restriction, _From, #state{options = [_,_,_,{_,R} | _]} = S) -> - {reply, R, S}; - handle_call(Req, From, S) -> unexpected(handle_call, [Req, From], S), {reply, nok, S}. @@ -530,10 +511,7 @@ handle_info(T, #state{} = S) -> {noreply, S}; {stop, Reason} -> {stop, {shutdown, Reason}, S} - end; - -handle_info(T, S) -> - handle_info(T, upgrade(S)). + end. %% transition/2 @@ -643,39 +621,10 @@ transition({failover, TRef, Seqs}, S) -> failover(TRef, Seqs, S), ok; -%% Ensure upgraded state is stored in state table. -transition(upgrade, _) -> - ok; - transition(Req, S) -> unexpected(handle_info, [Req], S), ok. -%% upgrade/1 - -upgrade({state, Id, Svc, Name, Svc, PT, CT, SB, UB, SD, LD, MPid}) -> - S = #state{id = Id, - service_name = Name, - service = Svc, - peerT = PT, - connT = CT, - shared_peers = SD, - local_peers = LD, - monitor = MPid, - options = [{sequence, ?NOMASK}, - {share_peers, SB}, - {use_shared_peers, UB}, - {restrict_connections, ?RESTRICT}]}, - upgrade_insert(S), - S. - -upgrade_insert(#state{service = #diameter_service{pid = Pid}} = S) -> - if Pid == self() -> - ets:insert(?STATE_TABLE, S); - true -> - Pid ! upgrade - end. - %%% --------------------------------------------------------------------------- %%% # terminate(Reason, State) %%% --------------------------------------------------------------------------- @@ -944,6 +893,7 @@ type(connect = T) -> T. start(Ref, Type, Opts, #state{peerT = PeerT, connT = ConnT, + options = SvcOpts, service_name = SvcName, service = Svc}) when Type == connect; @@ -951,6 +901,7 @@ start(Ref, Type, Opts, #state{peerT = PeerT, Pid = s(Type, Ref, {ConnT, Opts, SvcName, + SvcOpts, merge_service(Opts, Svc)}), insert(PeerT, #peer{pid = Pid, type = Type, @@ -963,13 +914,8 @@ start(Ref, Type, Opts, #state{peerT = PeerT, %% record is what is passed back into application callbacks. s(Type, Ref, T) -> - case diameter_watchdog:start({Type, Ref}, T) of - {_MRef, Pid} -> - Pid; - Pid when is_pid(Pid) -> %% from old code - erlang:monitor(process, Pid), - Pid - end. + {_MRef, Pid} = diameter_watchdog:start({Type, Ref}, T), + Pid. %% merge_service/2 @@ -1116,12 +1062,7 @@ init_conn(Id, Alias, {TPid, _} = TC, {SvcName, Apps}) -> %% find_app/2 find_app(Alias, Apps) -> - case lists:keyfind(Alias, #diameter_app.alias, Apps) of - #diameter_app{options = E} = A when is_atom(E) -> %% upgrade - A#diameter_app{options = [{answer_errors, E}]}; - A -> - A - end. + lists:keyfind(Alias, #diameter_app.alias, Apps). %% Don't bring down the service (and all associated connections) %% regardless of what happens. @@ -1819,9 +1760,6 @@ request_peer_down(TPid, S) -> %%% recv_request/3 %%% --------------------------------------------------------------------------- -recv_request(TPid, Pkt, {ConnT, SvcName, Apps}) -> %% upgrade - recv_request(TPid, Pkt, {ConnT, SvcName, Apps, ?NOMASK}); - recv_request(TPid, Pkt, {ConnT, SvcName, Apps, Mask}) -> try ets:lookup(ConnT, TPid) of [C] -> diff --git a/lib/diameter/src/base/diameter_watchdog.erl b/lib/diameter/src/base/diameter_watchdog.erl index 243ad0a986..a5429c967c 100644 --- a/lib/diameter/src/base/diameter_watchdog.erl +++ b/lib/diameter/src/base/diameter_watchdog.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2010-2012. All Rights Reserved. +%% Copyright Ericsson AB 2010-2013. 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 @@ -68,11 +68,12 @@ %% that a failed capabilities exchange produces the desired exit %% reason. --spec start(Type, {RecvData, [Opt], SvcName, #diameter_service{}}) +-spec start(Type, {RecvData, [Opt], SvcName, SvcOpts, #diameter_service{}}) -> {reference(), pid()} when Type :: {connect|accept, diameter:transport_ref()}, RecvData :: term(), Opt :: diameter:transport_opt(), + SvcOpts :: [diameter:service_opt()], SvcName :: diameter:service_name(). start({_,_} = Type, T) -> @@ -107,23 +108,20 @@ i({Ref, {_, Pid, _} = T}) -> make_state(T); {'DOWN', MRef, process, _, _} = D -> exit({shutdown, D}) - end; - -i({_, Pid, _} = T) -> %% from old code - erlang:monitor(process, Pid), - make_state(T). + end. make_state({T, Pid, {RecvData, Opts, SvcName, + SvcOpts, #diameter_service{applications = Apps, capabilities = Caps} = Svc}}) -> random:seed(now()), putr(restart, {T, Opts, Svc}), %% save seeing it in trace putr(dwr, dwr(Caps)), %% - {_,_} = Mask = call(Pid, sequence), - Restrict = call(Pid, restriction), + {_,_} = Mask = proplists:get_value(sequence, SvcOpts), + Restrict = proplists:get_value(restrict_connections, SvcOpts), Nodes = restrict_nodes(Restrict), #watchdog{parent = Pid, transport = monitor(diameter_peer_fsm:start(T, @@ -136,10 +134,6 @@ make_state({T, Pid, {RecvData, sequence = Mask, restrict = {Restrict, lists:member(node(), Nodes)}}. -%% Retrieve the sequence mask from the parent from the parent, rather -%% than having it passed into init/1, for upgrade reasons: the call to -%% diameter_service:receive_message/3 passes back the mask. - %% handle_call/3 handle_call(_, _, State) -> @@ -342,15 +336,6 @@ transition({state, Pid}, #watchdog{status = S}) -> %% =========================================================================== -%% Only call "upwards", to the parent service. -call(Pid, Req) -> - try - gen_server:call(Pid, Req, infinity) - catch - exit: Reason -> - exit({shutdown, {Req, Reason}}) - end. - monitor(Pid) -> erlang:monitor(process, Pid), Pid. -- cgit v1.2.3