aboutsummaryrefslogtreecommitdiffstats
path: root/lib/diameter/src/transport/diameter_tcp.erl
diff options
context:
space:
mode:
authorAnders Svensson <[email protected]>2016-03-10 17:43:50 +0100
committerAnders Svensson <[email protected]>2016-03-13 07:10:11 +0100
commit993d540a3ad0f2fc932fdfb0aabba06cb03f320c (patch)
treec7f07b76f72aed653695885f8021494873cd6ac1 /lib/diameter/src/transport/diameter_tcp.erl
parent2ffb288d8daeb72c27c5cead30ce779682bdd8b0 (diff)
downloadotp-993d540a3ad0f2fc932fdfb0aabba06cb03f320c.tar.gz
otp-993d540a3ad0f2fc932fdfb0aabba06cb03f320c.tar.bz2
otp-993d540a3ad0f2fc932fdfb0aabba06cb03f320c.zip
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.
Diffstat (limited to 'lib/diameter/src/transport/diameter_tcp.erl')
-rw-r--r--lib/diameter/src/transport/diameter_tcp.erl9
1 files changed, 9 insertions, 0 deletions
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),