anchor.diff:      {noreply, State}.
   
   
  -%%--------------------------------------------------------------------
  -%% Function: terminate(Reason, State) -> void()
  -%% Description: This function is called by a gen_server when it is about to
  -%% terminate. It should be the opposite of Module:init/1 and do any necessary
  -%% cleaning up. When it returns, the gen_server terminates with Reason.
  -%% The return value is ignored.
  -%%--------------------------------------------------------------------
   terminate(normal, _State) ->
       persist_to_disk(),
       ok;
   terminate(_Reason, _State) ->
       ok.
   
  -
  -%%--------------------------------------------------------------------
  -%% Func: code_change(OldVsn, State, Extra) -> {ok, NewState}
  -%% Description: Convert process state when code is changed
  -%%--------------------------------------------------------------------
   code_change(_OldVsn, State, _Extra) ->
       {ok, State}.
  -
  -%%--------------------------------------------------------------------
  -%%% Internal functions
  -%%--------------------------------------------------------------------
  -
  -%%--------------------------------------------------------------------
  -%% Func: prune_disk_state(Tracking) -> ok
  -%% Description: Prune the persistent disk state for anything we are
  -%%   not tracking.
  -%%--------------------------------------------------------------------
  -
  -%%--------------------------------------------------------------------
  -%% Func: persist_disk_state(Tracking) -> ok
  -%% Description: Persist state on disk
  -%%--------------------------------------------------------------------
  -track_in_ets_table([]) -> ok;
  -track_in_ets_table([#tracking_map { id = Id,
  -                                    filename = FName} | Next]) ->
  -    {F, St} = case etorrent_torrent:state(Id) of
  -        not_found -> track_in_ets_table(Next); %% Not hot, skip it.
  -        {value, seeding}  -> {FName, seeding};
  -        {value, leeching} -> {FName, {bitfield, etorrent_piece_mgr:bitfield(Id)}};
  -        {value, endgame}  -> {FName, {bitfield, etorrent_piece_mgr:bitfield(Id)}};
  -        {value, unknown}  -> track_in_ets_table(Next) %% Skip, we know nothing yet
  -    end,
  -    true = ets:insert(etorrent_fast_resume, #piece_diskstate{filename = F,
  -                                                             state    = St}),
  -    track_in_ets_table(Next).
  -
  -persist_to_disk() ->
  -    {atomic, Torrents} = etorrent_tracking_map:all(),
  -    track_in_ets_table(Torrents),
  -    {ok, F} = application:get_env(etorrent, fast_resume_file),
  -    ok = ets:tab2file(etorrent_fast_resume, F, [{extended_info, [object_count, md5sum]}]),
  -    etorrent_event_mgr:persisted_state_to_disk(),
  -    ok.
  -
  -
  
positive.code: 
  -record(state, { timer = none }).
  
  %% Type of the state in the diskstate in question.
  -type(diskstate_state() :: 'seeding' | {'bitfield', binary()}).
  
  %% Piece state on disk for persistence
  -record(piece_diskstate, {filename :: string(), % Name of torrent
                            state :: diskstate_state()}).
  
  -define(SERVER, ?MODULE).
  -define(PERSIST_TIME, timer:seconds(300)). % Every 300 secs, may be done configurable.
  
  
negative.code: query_state(Id) ->
          gen_server:call(?SERVER, {query_state, Id}).
  
  %% ==================================================================
  
  %% Enter a torrent into the tracking table
  track_torrent(#tracking_map { id = Id, filename = FName}) ->
      case etorrent_torrent:state(Id) of
          not_found -> ignore;
          {value, unknown} -> ignore;
          {value, seeding} -> ets:insert(?MODULE, {FName, seeding});
          {value, _Other}  -> ets:insert(?MODULE,
                                  {FName, {bitfield, etorrent_piece_mgr:bitfield(Id)}})
      end.
  
  %% Enter all torrents into a tracking table
  track_in_ets_table(Lst) when is_list(Lst) ->
      [track_torrent(TM) || TM <- Lst].
  
  %% Run a persistence operation
  persist_to_disk() ->
      {atomic, Torrents} = etorrent_tracking_map:all(),
      _ = track_in_ets_table(Torrents),
      {ok, F} = application:get_env(etorrent, fast_resume_file),
      ok = ets:tab2file(etorrent_fast_resume, F, [{extended_info, [object_count, md5sum]}]),
      etorrent_event_mgr:persisted_state_to_disk(),
      ok.
  
  %% ==================================================================
  
  init([]) ->
      process_flag(trap_exit, true),
      {ok, F} = application:get_env(etorrent, fast_resume_file),
  