anchor.diff:      end,
       {ok, RequestTime, S#state{trackerid = TrackerId}}.
   
  -%% TODO: Can be made better yet, I am sure! Generalize into a proper code
  -%%   construction.
  -
   construct_headers([], HeaderLines) ->
       lists:concat(lists:reverse(HeaderLines));
   construct_headers([{Key, Value}], HeaderLines) ->
  
positive.code: 	   end,
      lists:concat([S#state.url, "?", construct_headers(EReq, [])]).
  
  handle_tracker_contact(S, Event) ->
      {ok, NextContactTime, NS} = contact_tracker(S, Event),
      install_timer(NextContactTime, NS).
  
  install_timer(ContactTime, S) ->
      if
  	ContactTime > 30 ->
  	    io:format("Setting 30 sec timer! (~B left)~n", [ContactTime]),
  	    TimerRef = gen_fsm:start_timer(timer:seconds(30),
  					   reinstall_timer),
  	    S#state{timer = TimerRef,
  		    time_left = ContactTime - 30};
  	true ->
  	    io:format("Setting timer of ~B seconds~n", [ContactTime]),
  	    TimerRef = gen_fsm:start_timer(timer:seconds(ContactTime),
  					   may_contact),
  	    S#state{timer = TimerRef,
  		    time_left = 0}
      end.
  
  handle_nonregular(S, Event) ->
      NS = remove_timer(S),
      handle_tracker_contact(NS, Event).
  
  remove_timer(S) ->
      T = S#state.timer,
      case T of
  	none -> S;
  	Ref ->
  	    X = gen_fsm:cancel_timer(Ref),
  	    io:format("Timer cancelled again: ~p~n", [X]),
  	    S#state{timer = none,
  		    time_left = none}
      end.
  
  %%% Tracker response lookup functions
  find_next_request_time(BC) ->
      {integer, R} = bcoding:search_dict_default({string, "interval"},
  
negative.code: %%%-------------------------------------------------------------------
  %%% File    : tracker_delegate.erl
  %%% Author  : Jesper Louis Andersen <>
  %%% Description : Handles communication
  %%%
  %%% Created : 17 Jul 2007 by Jesper Louis Andersen <>
  %%%-------------------------------------------------------------------
  -module(tracker_delegate).
  
  -behaviour(gen_server).
  
  %% API
  -export([start_link/5, contact_tracker_now/1, start_now/1, stop_now/1,
  	torrent_completed/1]).
  
  %% gen_server callbacks
  -export([init/1, handle_call/3, handle_cast/2, handle_info/2,
  	 terminate/2, code_change/3]).
  
  -record(state, {should_contact_tracker = false,
  	        state_pid = none,
  