anchor.diff:  unexpected(F, A, #state{service_name = Name}) ->
       ?UNEXPECTED(F, A ++ [Name]).
   
  +cb(#diameter_app{module = [_|_] = M}, F, A) ->
  +    eval(M, F, A);
   cb([_|_] = M, F, A) ->
  -    eval(M, F, A);
  -cb(Rec, F, A) ->
  -    {_, M} = app(Rec),
       eval(M, F, A).
  -
  -app(#request{app = A, module = M}) ->
  -    {A,M};
  -app(#diameter_app{alias = A, module = M}) ->
  -    {A,M}.
   
   eval([M|X], F, A) ->
       apply(M, F, A ++ X).
  
positive.code:     ?Dict:update(Alias, fun(Ps) -> lists:keydelete(Pid, 1, Ps) end, PDict).
  
  %% ---------------------------------------------------------------------------
  %% find_transport/2-3
  %%
  %% Return: {TransportPid, #diameter_caps{}, #diameter_app{}}
  %%         | false
  
negative.code:         {timeout = Reason, TRef, _} ->        %% No timely reply
              {error, Req, Reason};
          {failover, TRef} ->       %% Service says peer has gone down
              retransmit(Req, App, Opts, find_state(SvcName), Timeout)
      end.
  
  %% Note that failover starts a new timer and that expiry of an old
  %% timer value is ignored. This means that an answer could be accepted
  %% from a peer after timeout in the case of failover.
  
  retransmit(Req, App, Opts, #state{service_name = SvcName} = S, Timeout) ->
      rt(find_transport(Req, App, Opts, S), Req, Opts, SvcName, Timeout);
              
  retransmit(Req, _, _, false, _) ->  %% service has gone down
      {error, Req, failover}.
  
  rt({_,_,App} = Transport, Req, Opts, SvcName, Timeout) ->
      try retransmit(Transport, Req, SvcName, Timeout) of
          T -> recv_answer(Timeout, SvcName, App, Opts, T)
      catch
          ?FAILURE(Reason) -> {error, Req, Reason}
      end;
  
  rt(_, Req, _, _, _) ->  %% no alternate peer
      {error, Req, failover}.
  
  %% handle_error/4
  
  handle_error(App,
               #request{packet = Pkt,
                        transport = TPid,
                        caps = Caps},
               Reason,
               SvcName) ->
      cb(App, handle_error, [Reason, msg(Pkt), SvcName, {TPid, Caps}]).
  
  msg(#diameter_packet{msg = undefined, bin = Bin}) ->
      Bin;
  