anchor.diff:              {A, Rq, Dict0, Pkt};
           {timeout = Reason, TRef, _} ->        %% No timely reply
               {error, Req, Reason};
  -        {failover, TRef} ->       %% Service says peer has gone down
  -            retransmit(pick_peer(SvcName, App, Req, Opts),
  -                       Req,
  -                       Opts,
  -                       SvcName,
  -                       Timeout)
  +        {'DOWN', MRef, process, _, _} when false /= MRef -> %% local peer_down
  +            failover(SvcName, App, Req, Opts, Timeout);
  +        {failover, TRef} ->                   %% local or remote peer_down
  +            failover(SvcName, App, Req, Opts, Timeout)
       end.
  +
  +%% failover/5
  +
  +failover(SvcName, App, Req, Opts, Timeout) ->
  +    retransmit(pick_peer(SvcName, App, Req, Opts),
  +               Req,
  +               Opts,
  +               SvcName,
  +               Timeout).
   
   %% handle_answer/3
   
  
positive.code: 
      ?LOG(retransmission, Pkt#diameter_packet.header),
      incr(TPid, {msg_id(Pkt, AppDict), send, retransmission}),
      TRef = send_request(TPid, Pkt, Req, SvcName, Tmo),
      {TRef, Req}.
  
  %% insert_request/1
  
  insert_request({_Seqs, #request{transport = TPid}, TRef} = T) ->
      ets:insert(?REQUEST_TABLE, [T, {TPid, {self(), TRef}}]),
      is_peer_up(TPid)
          orelse (self() ! {failover, TRef}).  %% failover/1 may have missed
  
  %% is_peer_up/1
  %%
  %% Is the entry written by peer_up/1 and deleted by peer_down/1 still
  %% in the request table?
  
  is_peer_up(TPid) ->
      Spec = [{{TPid}, [], ['$_']}],
      '$end_of_table' /= ets:select(?REQUEST_TABLE, Spec, 1).
  
  %% lookup_request/2
  %%
  
negative.code: %% peer_up/1
  %% ---------------------------------------------------------------------------
  
  %% Start a process that dies with peer_down/1, on which request
  %% processes can monitor. The transport process started in
  %% diameter_peer_fsm could be used for this, but starting a new
  %% process here is easier: don't otherwise have access to the
  %% transport process here (TPid here is the diameter_peer_fsm
  %% process), and the need for a process to monitor came much later
  %% than the calls to peer_up/down.
  peer_up(TPid) ->
      proc_lib:start(?MODULE, init, [TPid]).
  
  init(TPid) ->
      ets:insert(?REQUEST_TABLE, {TPid, self()}),
      proc_lib:init_ack(self()),
      proc_lib:hibernate(erlang, exit, [{shutdown, TPid}]).
  
  %% ---------------------------------------------------------------------------
  %% peer_down/1
  %% ---------------------------------------------------------------------------
  
  peer_down(TPid) ->
      [{_, Pid}] = ets:lookup(?REQUEST_TABLE, TPid),
      ets:delete(?REQUEST_TABLE, TPid),
      Pid ! ok,  %% make it die
      Pid.
  
  %% ---------------------------------------------------------------------------
  %% incr/4
  