Types
SvcName = term()
Action = Reply
| {relay, [Opt]}
| discard
| {eval|eval_packet, Action, PostF}
Reply = {reply, packet() | message()}
| {answer_message, 3000..3999|5000..5999}
| {protocol_error, 3000..3999}
Invoked when a request message is received from a peer.
The application in which the callback takes place (that is, the
callback module as configured with diameter:start_service/2)
is determined by the Application Identifier in the header of the
incoming request message, the selected module being the one
whose corresponding dictionary declares
itself as defining either the application in question or the Relay
application.
The argument packet() has the following signature.
#diameter_packet{header = #diameter_header{},
avps = [#diameter_avp{}],
msg = record() | undefined,
errors = [Unsigned32() | {Unsigned32(), #diameter_avp{}}],
bin = binary(),
transport_data = term()}
The msg field will be undefined in case the request has
been received in the relay application.
Otherwise it contains the record representing the request as outlined
in diameter_dict(4).
The errors field specifies any results codes identifying errors
found while decoding the request.
This is used to set Result-Code and/or Failed-AVP in a returned
answer unless the callback returns a #diameter_packet{}
whose errors field is set to either a non-empty list of its
own, in which case this list is used instead, or the atom false
to disable any setting of Result-Code and Failed-AVP.
Note that the errors detected by diameter are of the 3xxx
and 5xxx series, Protocol Errors and Permanent Failures respectively.
The errors list is empty if the request has been received in
the relay application.
The transport_data field contains an arbitrary term passed into
diameter from the transport module in question, or the atom
undefined if the transport specified no data.
The term is preserved if a message() is returned but must be set
explicitly in a returned packet().
The semantics of each of the possible return values are as follows.
- {reply, packet() | message()}
-
Send the specified answer message to the peer.
In the case of a packet(), the
message to be sent must be set in the
msg field and the header field can be set to a
#diameter_header{} to specify values that should be
preserved in the outgoing answer, appropriate values otherwise
being set by diameter.
- {answer_message, 3000..3999|5000..5999}
-
Send an answer message to the peer containing the specified
Result-Code.
Equivalent to
{reply, ['answer-message' | Avps]
where Avps sets the Origin-Host, Origin-Realm, the specified
Result-Code and (if the request contained one) Session-Id AVPs, and
possibly Failed-AVP as described below.
Returning a value other than 3xxx or 5xxx will cause the request
process in question to fail, as will returning a 5xxx value if the
peer connection in question has been configured with the RFC 3588
common dictionary diameter_gen_base_rfc3588.
(Since RFC 3588 only allows 3xxx values in an answer-message.)
When returning 5xxx, Failed-AVP will be populated with the AVP of the
first matching Result-Code/AVP pair in the errors field of the
argument packet(), if found.
If this is not appropriate then an answer-message should be
constructed explicitly and returned in a reply tuple
instead.
- {relay, Opts}
-
Relay a request to another peer in the role of a Diameter relay agent.
If a routing loop is detected then the request is answered with
3005 (DIAMETER_LOOP_DETECTED).
Otherwise a Route-Record AVP (containing the sending peer's Origin-Host) is
added to the request and pick_peer/4
and subsequent callbacks take place just as if diameter:call/4 had been called
explicitly.
The End-to-End Identifier of the incoming request is preserved in the
header of the relayed request.
The returned Opts should not specify detach.
A subsequent handle_answer/4
callback for the relayed request must return its first
argument, the packet() containing the answer message.
Note that the extra option can be specified to supply arguments
that can distinguish the relay case from others if so desired.
Any other return value (for example, from a
handle_error/4 callback)
causes the request to be answered with 3002 (DIAMETER_UNABLE_TO_DELIVER).
- discard
-
Discard the request.
No answer message is sent to the peer.
- {eval, Action, PostF}
-
Handle the request as if Action has been returned and then
evaluate PostF in the request process.
The return value is ignored.
- {eval_packet, Action, PostF}
-
Like eval but evaluate PostF on any encoded
#diameter_packet{} prior to transmission, the bin field
containing the encoded binary.
The return value is ignored.
- {protocol_error, 3000..3999}
-
Equivalent to {answer_message, 3000..3999}.
Note
Requests containing errors may be answered by diameter, without a
callback taking place, depending on the value of the
diameter:application_opt() request_errors.