anchor.diff:                      NodeID
               end
       end.
  -    
  +
  +%
  +% Refresh the contents of a bucket by issuing find_node queries to each node
  +% in the bucket until enough nodes that falls within the range of the bucket
  +% has been returned to replace the inactive nodes in the bucket.
  +%
  +refresh(Range, Inactive, Active) ->
  +    % Try to refresh the routing table using the inactive nodes first, 
  +    % If they turn out to be reachable the problem's solved.
  +    do_refresh(Range, Inactive ++ Active, []).
  +
  +do_refresh(_, [], _) ->
  +    ok; % TODO - perform a find_node_search here?
  +do_refresh(Range, [{ID, IP, Port}|T], IDs) ->
  +    Continue = case etorrent_dht_net:find_node(IP, Port, ID) of
  +        {error, timeout} ->
  +            true;
  +        {_, CloseNodes} ->
  +            do_refresh_inserts(Range, CloseNodes)
  +    end,
  +    case Continue of 
  +        false -> ok;
  +        true  -> do_refresh(Range, T, [ID|IDs])
  +    end.
  +
  +do_refresh_inserts({_, _}, []) ->
  +    true;
  +do_refresh_inserts({Min, Max}=Range, [{ID, IP, Port}|T])
  +when ?in_range(ID, Min, Max) ->
  +    case safe_insert_node(ID, IP, Port) of
  +        {error, timeout} ->
  +            do_refresh_inserts(Range, T);
  +        true ->
  +            do_refresh_inserts(Range, T);
  +        false ->
  +            safe_insert_nodes(T),
  +            false
  +    end;
  +
  +do_refresh_inserts(Range, [{ID, IP, Port}|T]) ->
  +    _ = safe_insert_node(ID, IP, Port),
  +    do_refresh_inserts(Range, T).
  +
  +spawn_refresh(Range, InputInactive, InputActive) ->
  +    Inactive = [{ensure_bin_id(ID), IP, Port}
  +               || {ID, IP, Port} <- InputInactive],
  +    Active   = [{ensure_bin_id(ID), IP, Port}
  +               || {ID, IP, Port} <- InputActive],
  +    spawn(?MODULE, refresh, [Range, Inactive, Active]).
   
   
   max_unreachable() ->
  
positive.code: % a ping query to it first. This function must be used when we
  % want to verify the identify and status of a node.
  %
  safe_insert_node(ID, IP, Port) ->
      case is_interesting(ID, IP, Port) of
          false ->
              ok;
          true ->
              % Since this clause will be reached every time this node
              % receives a query from a node that is interesting, use the
              % unsafe_ping function to avoid repeatedly issuing ping queries
              % to nodes that won't reply to them.
              case unsafe_ping(IP, Port) of
                  pang -> ok;
                  ID   -> unsafe_insert_node(ID, IP, Port);
                  _    -> ok
          end
      end.
  
  
negative.code:     TmpNTimers = case Replace of
          none ->
              PrevNTimers;
          {_, _, _}=DNode ->
              del_timer(DNode, PrevNTimers)
      end,
  
  