anchor.diff:      ?OPENED(S0#state{ replay = Replay1 });
   
   %% This is step three of exactly once; we receive it if we send pubrec
  -%% to acknowledge a publish with QoS = exactly_once
  +%% to acknowledge a publish with QoS = exactly_once. Once we've seen
  +%% this frame, we no longer have to remember the message for
  +%% deduplication.
  +%%
  +%% These frames might get resent, but the pubcomp must be sent in any
  +%% case (since that will stop the sender sending pubrel).
   opened({frame, #pubrel{ message_id = Id }}, S0) ->
  +    #state{ dedup = Dedup } = S0,
  +    Dedup1 = remove_from_dedup(Id, Dedup),
       write(S0, #pubcomp{ message_id = Id }),
  -    ?OPENED(S0);
  +    ?OPENED(S0#state{ dedup = Dedup1 });
   
   %% These two ff frames end a "guaranteed delivery" exchange.
   opened({frame, #puback{ message_id = Id }}, S0) ->
  
positive.code: 
  opened({frame, pingresp}, S0) -> ?OPENED(S0);
  
  opened({frame, Frame = #publish{}}, S0) ->
      S1 = do_ack(S0, Frame),
      #state{ receiver = Receiver } = S1,
      Receiver ! {frame, Frame},
      ?OPENED(S1);
  
  %% This is step two of "exactly once" delivery (step one is publish),
  %% the first of two acknowledgments.
  
negative.code: next_replay(?REPLAY(Replay)) ->
      {_Id, Frame, Replay1} = gb_trees:take_smallest(Replay),
      {Frame, ?REPLAY(Replay1)}.
  
  -spec(empty_dedup() -> dedup()).
  empty_dedup() -> ?DEDUP(?SETS:new()).
  
  -spec(is_duplicate(message_id(), dedup()) -> boolean()).
  is_duplicate(Id, ?DEDUP(Set)) ->
      ?SETS:is_element(Id, Set).
  
  -spec(record_for_dedup(message_id(), dedup()) -> dedup()).
  record_for_dedup(Id, ?DEDUP(Set)) ->
      ?DEDUP(?SETS:add_element(Id, Set)).
  
  -spec(remove_from_dedup(message_id(), dedup()) -> dedup()).
  remove_from_dedup(Id, ?DEDUP(Set)) ->
      ?DEDUP(?SETS:del_element(Id, Set)).
  
  with_id(Id, S = #subscribe{})   -> S#subscribe{ message_id = Id };
  with_id(Id, U = #unsubscribe{}) -> U#unsubscribe{ message_id = Id }.
  