anchor.diff:  %%% Internal functions
   %%%===================================================================
   
  --spec p_generate_token(KeyId, Path, MaxLeaseTime, WorkerPort, Timeout)
  +-spec p_generate_token(KeyId, Path, MaxLeaseTime, WorkerPort, From, Timeout)
                         -> {Token, Public, Secret}
                                when KeyId :: binary(),
                                     Path :: binary(),
                                     MaxLeaseTime :: integer(),
                                     WorkerPort :: port(),
  +                                  From :: pid(),
                                     Timeout :: integer(),
                                     Token :: binary(),
                                     Public :: binary(),
                                     Secret :: binary().
  -p_generate_token(KeyId, Path, MaxLeaseTime, WorkerPort, Timeout) ->
  +p_generate_token(KeyId, Path, MaxLeaseTime, WorkerPort, From, Timeout) ->
       ReqBody = jsx:encode(#{<<"key_id">> => KeyId, <<"path">> => Path,
                             <<"max_lease_time">> => MaxLeaseTime}),
       p_write_request(WorkerPort, ?kGenerateToken, ReqBody),
  -    {ok, {_Size, ReplyBody}} = p_read_reply(WorkerPort, Timeout),
  -    #{<<"token">> := Token, <<"id">> := Public, <<"secret">> := Secret}
  -        = jsx:decode(ReplyBody, [return_maps]),
  -    {Public, Secret, Token}.
  -
  -
  --spec p_get_token_id(Token, WorkerPort, Timeout)
  +    case p_read_reply(WorkerPort, Timeout) of
  +        {ok, {_Size, ReplyBody}} ->
  +            #{<<"token">> := Token, <<"id">> := Public, <<"secret">> := Secret}
  +                    = jsx:decode(ReplyBody, [return_maps]),
  +            {Public, Secret, Token};
  +        {error, worker_died} ->
  +            gen_server:reply(From, {error, worker_died}),
  +            exit(self(), kill)
  +    end.
  +
  +
  +-spec p_get_token_id(Token, WorkerPort, From, Timeout)
                       -> {ok, PublicId} | {error, invalid_macaroon}
                              when Token :: binary(),
                                   WorkerPort :: port(),
  +                                From :: pid(),
                                   Timeout :: integer(),
                                   PublicId :: binary().
  -p_get_token_id(Token, WorkerPort, Timeout) ->
  +p_get_token_id(Token, WorkerPort, From, Timeout) ->
       p_write_request(WorkerPort, ?kGetTokenId, Token),
       case p_read_reply(WorkerPort, Timeout) of
           {ok, {_, Reply}} ->
  
positive.code:                 #{<<"status">> := <<"error">>, <<"reason">> := <<"invalid_token">>} ->
                      {error, invalid_lease}
              end;
          {error, worker_timeout} ->
              lager:error("Timeout reached waiting for reply from worker ~p", [WorkerPort]),
              {error, worker_timeout}
      end.
  
  
  -spec p_commit(WorkerPort, LeasePath, OldRootHash, NewRootHash, RepoTag, Timeout)
                -> ok | {error, merge_error | io_error | worker_timeout}
                                          when WorkerPort :: port(),
                                               LeasePath :: binary(),
                                               OldRootHash :: binary(),
                                               NewRootHash :: binary(),
                                               RepoTag :: cvmfs_common_types:repository_tag(),
                                               Timeout :: integer().
  p_commit(WorkerPort, LeasePath, OldRootHash, NewRootHash, RepoTag, Timeout) ->
      {TagName, TagChannel, TagDescription} = RepoTag,
      Req1 = jsx:encode(#{<<"lease_path">> => LeasePath,
                          <<"old_root_hash">> => OldRootHash,
  
negative.code: %%                                   {stop, Reason, State}
  %% @end
  %%--------------------------------------------------------------------
  handle_call({worker_req, generate_token, KeyId, Path, MaxLeaseTime}, From, State) ->
      #{worker := WorkerPort, max_lease_time := Timeout} = State,
      Reply = p_generate_token(KeyId, Path, MaxLeaseTime, WorkerPort, From, Timeout),
      lager:info("Worker ~p request: {generate_token, {~p, ~p, ~p}} -> Reply: ~p",
                 [self(), KeyId, Path, MaxLeaseTime, Reply]),
      {reply, Reply, State};
  handle_call({worker_req, get_token_id, Token}, From, State) ->
      #{worker := WorkerPort, max_lease_time := Timeout} = State,
      Reply = p_get_token_id(Token, WorkerPort, From, Timeout),
      lager:info("Worker ~p request: {get_token_id, ~p} -> Reply: ~p",
                 [self(), Token, Reply]),
      {reply, Reply, State};
  handle_call({worker_req, submit_payload, {Token, _, Digest, HeaderSize} = SubmissionData,
               Secret}, From, State) ->
      #{worker := WorkerPort, max_lease_time := Timeout} = State,
      Reply = p_submit_payload(SubmissionData, Secret, WorkerPort, From, Timeout),
      lager:info("Worker ~p request: {submit_payload, {{~p, PAYLOAD_NOT_SHOWN, ~p, ~p} ~p}} -> Reply: ~p",
                 [self(), Token, Digest, HeaderSize, Secret, Reply]),
      {reply, Reply, State};
  handle_call({worker_req, commit, LeasePath, OldRootHash, NewRootHash, RepoTag}, From, State) ->
      #{worker := WorkerPort, max_lease_time := Timeout} = State,
      Reply = p_commit(WorkerPort, LeasePath, OldRootHash, NewRootHash, RepoTag, From, Timeout),
      lager:info("Worker ~p request: {commit, ~p, ~p, ~p, ~p} -> Reply: ~p",
                 [self(), LeasePath, OldRootHash, NewRootHash, RepoTag, Reply]),
      {reply, Reply, State}.
  