Skip to content

Commit

Permalink
Add transport interface 'connected' message with local address list
Browse files Browse the repository at this point in the history
A transport module can return a local address list from its start/3
function in order to specify addresses to be used as Host-IP-Address
during capabilities exchange. Now allow addresses to be communicated in
a 'connected' message in the case of a connecting transport, so that
diameter_tcp (in particular) can make local address configuration
optional, communicating the gen_tcp default after connection
establishment instead.
  • Loading branch information
Anders Svensson committed Apr 11, 2013
1 parent 157886e commit 2e848e9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
30 changes: 19 additions & 11 deletions lib/diameter/doc/src/diameter_transport.xml
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="latin1" ?>
<!DOCTYPE erlref SYSTEM "erlref.dtd" [
<!ENTITY message '<seealso marker="#message">message()</seealso>'>
<!ENTITY MESSAGES '<seealso marker="#MESSAGES">MESSAGES</seealso>'>
<!ENTITY start '<seealso marker="#Mod:start-3">start/3</seealso>'>
<!ENTITY ip_address
'<seealso marker="kernel:inet#type-ip_address">inet:ip_address()</seealso>'>
<!ENTITY % also SYSTEM "seealso.ent" >
Expand All @@ -12,7 +14,7 @@
<erlref>
<header>
<copyright>
<year>2011</year><year>2012</year>
<year>2011</year><year>2013</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
Expand Down Expand Up @@ -125,7 +127,7 @@ Ref is the value that was returned from the call to &mod_add_transport;
that has lead to starting of a transport process.</p>

<p>
<c>Svc</c> contains the capabilities passed to &mod_start_service; and
<c>Svc</c> contains capabilities passed to &mod_start_service; and
&mod_add_transport;, values passed to the latter overriding those
passed to the former.</p>

Expand All @@ -134,13 +136,16 @@ passed to the former.</p>
&mod_transport_opt; list passed to &mod_add_transport;.</p>

<p>
The start function should use the <c>Host-IP-Address</c> list and/or
<c>Config</c> to select an appropriate list of local IP addresses,
and should return this list if different from the
<c>#diameter_service{}</c> addresses.
The returned list is used to populate <c>Host-IP-Address</c> AVPs in
outgoing capabilities exchange messages, the
<c>#diameter_service{}</c> addresses being used otherwise.</p>
The start function should use the <c>Host-IP-Address</c> list in
<c>Svc</c> and/or <c>Config</c> to select an appropriate list of local
IP addresses, and should return this list if different from the
<c>Svc</c> addresses.
In the connecting case, the local address list can instead be
communicated in a <c>connected</c> message (see &MESSAGES; below)
following connection establishment.
In either case, the local address list is used to populate
<c>Host-IP-Address</c> AVPs in outgoing capabilities exchange
messages.</p>

<p>
A transport process must implement the message interface documented below.
Expand Down Expand Up @@ -230,13 +235,16 @@ Not sent if the transport process has <c>Type=connect</c>.</p>
</item>

<tag><c>{diameter, {self(), connected, Remote}}</c></tag>
<tag><c>{diameter, {self(), connected, Remote, [LocalAddr]}}</c></tag>
<item>
<p>
Inform the parent that the transport process with <c>Type=connect</c>
has established a connection with a peer.
Not sent if the transport process has <c>Type=accept</c>.
Not sent if the transport process has <c>Type=accept</c>.&nbsp;
<c>Remote</c> is an arbitrary term that uniquely identifies the remote
endpoint to which the transport has connected.</p>
endpoint to which the transport has connected.
A <c>LocalAddr</c> list has the same semantics as one returned from
&start;.</p>
</item>

<tag><c>{diameter, {recv, &message;}}</c></tag>
Expand Down
8 changes: 6 additions & 2 deletions lib/diameter/src/base/diameter_peer.erl
Expand Up @@ -24,7 +24,8 @@
%% Interface towards transport modules ...
-export([recv/2,
up/1,
up/2]).
up/2,
up/3]).

%% ... and the stack.
-export([start/1,
Expand Down Expand Up @@ -180,7 +181,7 @@ start(Mod, Args) ->
apply(Mod, start, Args).

%%% ---------------------------------------------------------------------------
%%% # up/[12]
%%% # up/1-3
%%% ---------------------------------------------------------------------------

up(Pid) -> %% accepting transport
Expand All @@ -189,6 +190,9 @@ up(Pid) -> %% accepting transport
up(Pid, Remote) -> %% connecting transport
ifc_send(Pid, {self(), connected, Remote}).

up(Pid, Remote, LAddrs) -> %% connecting transport
ifc_send(Pid, {self(), connected, Remote, LAddrs}).

%%% ---------------------------------------------------------------------------
%%% # recv/2
%%% ---------------------------------------------------------------------------
Expand Down
13 changes: 11 additions & 2 deletions lib/diameter/src/base/diameter_peer_fsm.erl
Expand Up @@ -351,10 +351,17 @@ transition({diameter, {TPid, connected, Remote}},
mode = M}
= S) ->
{'Wait-Conn-Ack', _} = PS, %% assert
connect = M, %%
connect = M, %%
keep_transport(TPid),
send_CER(S#state{mode = {M, Remote}});

transition({diameter, {TPid, connected, Remote, LAddrs}},
#state{transport = TPid,
service = Svc}
= S) ->
transition({diameter, {TPid, connected, Remote}},
S#state{service = readdr(Svc, LAddrs)});

%% Connection from peer.
transition({diameter, {TPid, connected}},
#state{transport = TPid,
Expand All @@ -363,7 +370,7 @@ transition({diameter, {TPid, connected}},
parent = Pid}
= S) ->
{'Wait-Conn-Ack', Tmo} = PS, %% assert
accept = M, %%
accept = M, %%
keep_transport(TPid),
Pid ! {accepted, self()},
start_timer(Tmo, S#state{state = recv_CER});
Expand All @@ -376,6 +383,8 @@ transition({diameter, {_, connected}}, _) ->
{stop, connection_timeout};
transition({diameter, {_, connected, _}}, _) ->
{stop, connection_timeout};
transition({diameter, {_, connected, _, _}}, _) ->
{stop, connection_timeout};

%% Connection has timed out: start an alternate.
transition({connection_timeout = T, TPid},
Expand Down

0 comments on commit 2e848e9

Please sign in to comment.