From 993d540a3ad0f2fc932fdfb0aabba06cb03f320c Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Thu, 10 Mar 2016 17:43:50 +0100 Subject: Let a throttling callback discard a received message This can be used as a simple form of overload protection, discarding the message before it's passed into diameter to become one more request process in a flood. Replying with 3004 would be more appropriate when the request has been directed at a specific server (the RFC's requirement) however, and possibly it should be possible for a callback to do this as well. --- lib/diameter/src/transport/diameter_tcp.erl | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lib/diameter') diff --git a/lib/diameter/src/transport/diameter_tcp.erl b/lib/diameter/src/transport/diameter_tcp.erl index 7f9255c097..b68a16b521 100644 --- a/lib/diameter/src/transport/diameter_tcp.erl +++ b/lib/diameter/src/transport/diameter_tcp.erl @@ -892,6 +892,15 @@ throttle({NPid, F}, #transport{throttled = Msg} = S) when is_pid(NPid), is_binary(Msg) -> throttle(NPid, S#transport{throttle_cb = F}); +%% Callback to accept a received message says to discard it. +throttle(discard, #transport{throttled = Msg} = S) + when is_binary(Msg) -> + throttle(S#transport{throttled = true}); + +throttle({discard = T, F}, #transport{throttled = Msg} = S) + when is_binary(Msg) -> + throttle(T, S#transport{throttle_cb = F}); + %% Callback says to ask again in the specified number of milliseconds. throttle({timeout, Tmo}, #transport{} = S) -> erlang:send_after(Tmo, self(), throttle), -- cgit v1.2.3