diff options
author | Anders Svensson <[email protected]> | 2012-10-05 11:13:11 +0200 |
---|---|---|
committer | Anders Svensson <[email protected]> | 2012-11-05 11:53:44 +0100 |
commit | bc87eb33f3878051b1d757710b4aa58136169c3a (patch) | |
tree | 43c07cb563bbe2921902cfa3305dbf665fe9c943 /lib/diameter/src/base/diameter_config.erl | |
parent | 2ba65b0d81b6a047bed3babf5371e500c1a72541 (diff) | |
download | otp-bc87eb33f3878051b1d757710b4aa58136169c3a.tar.gz otp-bc87eb33f3878051b1d757710b4aa58136169c3a.tar.bz2 otp-bc87eb33f3878051b1d757710b4aa58136169c3a.zip |
Implement sequence masks
Code should be loaded in this order:
diameter_session (sequence/1)
diameter_peer_fsm (calls to sequence/1)
diameter_service (sequence config, mask in receive_message/3)
diameter_watchdog (mask in peer start and receive_message/3)
diameter_config (accept sequence config)
Order of diameter and diameter_peer doesn't matter.
Diffstat (limited to 'lib/diameter/src/base/diameter_config.erl')
-rw-r--r-- | lib/diameter/src/base/diameter_config.erl | 62 |
1 files changed, 44 insertions, 18 deletions
diff --git a/lib/diameter/src/base/diameter_config.erl b/lib/diameter/src/base/diameter_config.erl index d1916c26e6..fc37ca8541 100644 --- a/lib/diameter/src/base/diameter_config.erl +++ b/lib/diameter/src/base/diameter_config.erl @@ -97,6 +97,9 @@ -record(monitor, {mref = make_ref() :: reference(), service}). %% name +%% The default sequence mask. +-define(NOMASK, {0,32}). + %% Time to lay low before restarting a dead service. -define(RESTART_SLEEP, 2000). @@ -549,9 +552,10 @@ make_config(SvcName, Opts) -> ok = encode_CER(COpts), - Os = split(Opts, [{[fun erlang:is_boolean/1], false, share_peers}, - {[fun erlang:is_boolean/1], false, use_shared_peers}, - {[fun erlang:is_pid/1, false], false, monitor}]), + Os = split(Opts, fun opt/2, [{false, share_peers}, + {false, use_shared_peers}, + {false, monitor}, + {?NOMASK, sequence}]), %% share_peers and use_shared_peers are currently undocumented. #service{name = SvcName, @@ -559,6 +563,43 @@ make_config(SvcName, Opts) -> capabilities = Caps}, options = Os}. +split(Opts, F, Defs) -> + [{K, F(K, get_opt(K, Opts, D))} || {D,K} <- Defs]. + +opt(K, false = B) + when K /= sequence -> + B; + +opt(K, true = B) + when K == share_peer; + K == use_shared_peers -> + B; + +opt(monitor, P) + when is_pid(P) -> + P; + +opt(sequence, {_,_} = T) -> + sequence(T); + +opt(sequence, F) -> + try diameter_lib:eval(F) of + T -> sequence(T) + catch + E:R -> + ?THROW({value, {sequence, E, R, ?STACK}}) + end; + +opt(K, _) -> + ?THROW({value, K}). + +sequence({H,N} = T) + when 0 =< N, N =< 32, 0 =< H, 0 == H bsr N -> + T; + +sequence(_) -> + ?THROW({value, sequence}). + make_caps(Caps, Opts) -> case diameter_capx:make_caps(Caps, Opts) of {ok, T} -> @@ -663,21 +704,6 @@ get_opt(Key, List, Def) -> _ -> ?THROW({arity, Key}) end. -split(Opts, Defs) -> - [{K, value(D, Opts)} || {_,_,K} = D <- Defs]. - -value({Preds, Def, Key}, Opts) -> - V = get_opt(Key, Opts, Def), - lists:any(fun(P) -> pred(P,V) end, Preds) - orelse ?THROW({value, Key}), - V. - -pred(F, V) - when is_function(F) -> - F(V); -pred(T, V) -> - T == V. - cb(M,F) -> try M:F() of V -> V |