anchor.diff:              NewStored = etorrent_pieceset:insert(Index, Stored),
               IState = State#state{
                   chunks_stored=NewChunksStored,
  -                peer_monitors=NewPeers,
                   pieces_assigned=NewAssigned,
                   pieces_stored=NewStored},
               IState
       end,
  -    {reply, ok, NewState};
  -
  -handle_call({mark_all_dropped, Pid}, _, State) ->
  -    %% When marking all requests as dropped, send a series of
  -    %% mark_dropped-messages to ourselves. The state of each
  -    %% piece should be restored eventually.
  -    #state{peer_monitors=Peers} = State,
  -
  -    %% Add the chunks back to the chunkset of each piece.
  -    OpenReqs = etorrent_monitorset:fetch(Pid, Peers),
  -    _ = [begin
  -        cast(self(), {mark_dropped, Pid, Index, Offset, Length})
  -    end || {Index, Offset, Length} <- chunk_list(OpenReqs)],
  -    {reply, ok, State};
  -
  -handle_call({state_members, Piecestate}, _, State) ->
  -    Stateset = case Piecestate of
  -        unassigned -> State#state.pieces_unassigned;
  -        begun -> State#state.pieces_begun;
  -        assigned -> State#state.pieces_assigned;
  -        stored -> State#state.pieces_stored;
  -        valid -> State#state.pieces_valid
  -    end,
  -    {reply, Stateset, State}.
  -
  -handle_cast({mark_dropped, Pid, Index, Offset, Length}, State) ->
  +    {noreply, NewState};
  +
  +handle_info({chunk, {dropped, Piece, Offset, Length, Peerpid}}, State)
  +when ?in_endgame(State) ->
  +    #state{assigning=Assigning} = State,
  +    ok = etorrent_chunkstate:dropped(Piece, Offset, Length, Peerpid, Assigning),
  +    {noreply, State};
  +
  +handle_info({chunk, {dropped, Piece, Offset, Length, _}}, State) ->
       #state{
           torrent_id=TorrentID,
           pieces_begun=Begun,
           pieces_assigned=Assigned,
           chunks_assigned=AssignedChunks,
  -        peer_monitors=Peers,
           prio_begun=PrioBegun} = State,
   
  -     %% Reemove the chunk from the peer's set of open requests
  -     OpenReqs = etorrent_monitorset:fetch(Pid, Peers),
  -     NewReqs  = gb_trees:delete({Index, Offset}, OpenReqs),
  -     NewPeers = etorrent_monitorset:update(Pid, NewReqs, Peers),
  - 
        %% Add the chunk back to the chunkset of the piece.
  -     Chunks = array:get(Index, AssignedChunks),
  +     Chunks = array:get(Piece, AssignedChunks),
        NewChunks = etorrent_chunkset:insert(Offset, Length, Chunks),
  -     NewAssignedChunks = array:set(Index, NewChunks, AssignedChunks),
  +     NewAssignedChunks = array:set(Piece, NewChunks, AssignedChunks),
   
        %% Assigned -> Begun
  -     NewAssigned = etorrent_pieceset:delete(Index, Assigned),
  -     NewBegun = etorrent_pieceset:insert(Index, Begun),
  +     NewAssigned = etorrent_pieceset:delete(Piece, Assigned),
  +     NewBegun = etorrent_pieceset:insert(Piece, Begun),
        NewPrioBegun = update_priority(TorrentID, PrioBegun, NewBegun),
    
        NewState = State#state{
            pieces_begun=NewBegun,
            pieces_assigned=NewAssigned,
            chunks_assigned=NewAssignedChunks,
  -         peer_monitors=NewPeers,
            prio_begun=NewPrioBegun},
       {noreply, NewState};
   
  -handle_cast({demonitor, Pid}, State) ->
  -    %% This message should be received after all mark_dropped messages.
  -    %% At this point the set of open requests for the peer should be empty.
  -    #state{peer_monitors=Peers} = State,
  -    NewPeers = etorrent_monitorset:delete(Pid, Peers),
  -    NewState = State#state{peer_monitors=NewPeers},
  -    {noreply, NewState}.
  -
  -handle_info({'DOWN', _, process, Pid, _}, State) ->
  -    %% When a peer crashes, send a series of mark-dropped messages
  -    %% and a demonitor-message to ourselves.
  -    #state{peer_monitors=Peers} = State,
  -    OpenReqs = etorrent_monitorset:fetch(Pid, Peers),
  -    _ = [begin
  -        cast(self(), {mark_dropped, Pid, Index, Offset, Length})
  -    end || {Index, Offset, Length} <- chunk_list(OpenReqs)],
  -    _ = cast(self(), {demonitor, Pid}),
  -    {noreply, State};
   
   handle_info({scarcity, Ref, Tag, Piecelist}, State) ->
       #state{prio_begun=Begun, prio_unassigned=Unass} = State,
  
positive.code:             {reply, {ok, Chunks}, NewState}
      end;
  
  handle_call({mark_valid, _, Index}, _, State) ->
      #state{
          pieces_stored=Stored,
          pieces_valid=Valid} = State,
  
negative.code:     ok = etorrent_utils:shutdown(SPid),
      ok = etorrent_utils:shutdown(CPid).
  
  lookup_registered_case() ->
      ?assertEqual(true, ?chunk_server:register_chunk_server(0)),
      ?assertEqual(self(), ?chunk_server:lookup_chunk_server(0)).
  