1 2This directory contains small examples of simple Diameter nodes. They 3don't do everything a real node should do obviously, but they're a 4starting point. 5 6Each example consists of an interface module with functions to start 7and stop a service and add transport, and a corresponding callback 8module for the Diameter application the service configures. A real 9node might support multiple Diameter applications, either with the 10same callback or sharing a common callback, maybe using extra 11arguments to distinguish between callbacks for the different 12applications. 13 14The interface functions are named start, stop, connect, and listen; 15the client example also has a call function that sends an example 16message. Service names should be atoms in these modules (since the 17default setting of Origin-Host assumes this), but doesn't need to be 18in general. Options are passed directly to diameter:start_service/2 19and diameter:add_transport/2, with some additional convenience options 20for the latter; in particular, the atoms tcp and sctp to connect to or 21listen on default endpoints (127.0.01:3868), or tuples with protocol 22and another endpoint {eg. {tcp, {192,168,1,5}, 3869}. This convenience 23makes the simplest usage like this in an Erlang shell: 24 25 diameter:start(). 26 server:start(). 27 server:listen(tcp). 28 client:start(). 29 client:connect(tcp). 30 client:call(). 31 32Or put a relay between the client and server: 33 34 diameter:start(). 35 server:start(). 36 server:listen(sctp). 37 relay:start(). 38 relay:connect(sctp). 39 relay:listen(tcp). 40 client:start(). 41 client:connect(tcp). 42 client:call(). 43 44Most services should probably set the following options, which have 45been added to solve various problems over the years, while the 46defaults have not been changed for backwards compatibility. 47 48 {decode_format, map} 49 50 Provide decoded messages in #diameter_packet.msg of a 51 handle_request or handle_answer callback in the form [Name | Avps], 52 where Name is the atom() name of the message in the (Diameter) 53 application dictionary in question (eg. 'ACR') and Avps is a map 54 of AVP values. This avoids compile-time dependencies on the 55 generated records and their (generally) long-winded names. The 56 hrl files generated from dictionaries are best avoided. 57 58 {restrict_connections, false} 59 60 Accept multiple connections with the same peer. By default, 61 diameter will only accept a single connection with a given peer, 62 which the Diameter RFC can be interpreted as requiring. In 63 practice, wanting multiple connections to the same peer is 64 common. 65 66 {string_decode, false} 67 68 Disable the decoding of string-ish Diameter types to Erlang 69 strings, leaving them as binary(). Strings can be costly if 70 decoded Diameter messages are passed between processes. 71 72 {strict_mbit, false} 73 74 Relax the interpretation of the M-bit so that an AVP setting 75 this bit is not regarded as a 5001 error when the message 76 grammar in question doesn't explicitly list the AVP. Without 77 this, a Redirect-Host AVP received in a 3006 78 (DIAMETER_REDIRECT_INDICATION) answer-message from a redirect 79 agent will be treated as error, and there have been other 80 situations in which the default value has caused problems (or at 81 least surprise). 82 83 {call_mutates_state, false} (on each configured application) 84 85 Avoid pick_peer and subsequent callbacks going through a single 86 process, which can be a bottleneck. Better to use the tid() of 87 an ets table as (immutable) state, for example. 88 89Other options that are particularly useful/necessary in some 90situations are: 91 92 pool_size - Create a pool of accepting processes for a listening 93 transport, to avoid refused connections when many peers 94 connect simultaneously. Can also be used on a connecting 95 transport to establish multiple connections with a 96 single call to diameter:add_transport/2. 97 98 sequence - Ensure unique End-to-End and Hop-by-Hop identifiers over 99 a cluster of Erlang nodes. 100 101 share_peers - Share peer connections across a cluster of 102 use_shared_peers Erlang nodes. 103 104 spawn_opt - Replace diameter's spawning of a new handler process for 105 each request by something else: diameter_dist is an example. 106