anchor.diff:      ?WARN([got_unknown_message, Msg, S]),
       {stop, {unknown_msg, Msg}}.
   
  -%% Handle requests to choke and unchoke. If we are already choking the peer,
  -%% there is no reason to send the message again.
  -%% @private
  -handle_cast(choke, S) -> perform_choke(S);
  -handle_cast(unchoke, #state { choke = false } = S) -> {noreply, S, 0};
  -handle_cast(unchoke,
  -        #state { choke = true, torrent_id = Torrent_Id, control_pid = ControlPid } = S) ->
  -    ok = etorrent_peer_states:set_local_unchoke(Torrent_Id, ControlPid),
  -    send_message(unchoke, S#state{choke = false});
  -
  -%% A request to check the current choke state and ask for a rechoking
  -handle_cast(check_choke, #state { choke = true } = S) ->
  -    {noreply, S, 0};
  -handle_cast(check_choke, #state { choke = false } = S) ->
  -    ok = etorrent_choker:perform_rechoke(),
  -    {noreply, S, 0};
  -
  -%% Regular messages. We just send them onwards on the wire.
  -handle_cast({piece, Index, Offset, _, Data}, State) ->
  -    send_message({piece, Index, Offset, Data}, State);
  -handle_cast({reject, Index, Offset, Length}, State) ->
  -    send_message({reject_request, Index, Offset, Length}, State);
  -handle_cast({bitfield, BF}, S) ->
  -    send_message({bitfield, BF}, S);
  -handle_cast(extended_msg, S) ->
  -    send_message({extended, 0, etorrent_proto_wire:extended_msg_contents()}, S);
  -handle_cast(not_interested, #state { interested = false} = S) ->
  -    {noreply, S, 0};
  -handle_cast(not_interested, #state { interested = true } = S) ->
  -    send_message(not_interested, S#state { interested = false });
  -handle_cast(interested, #state { interested = true } = S) ->
  -    {noreply, S, 0};
  -handle_cast(interested, #state { interested = false } = S) ->
  -    send_message(interested, S#state { interested = true });
  -handle_cast({have, Pn}, S) ->
  -    send_message({have, Pn}, S);
  -
  -%% Cancels are handled specially when the fast extension is enabled.
  -handle_cast({cancel, Idx, Offset, Len},
  -        #state { fast_extension = true, requests = Requests} = S) ->
  -    try
  -	true = queue:member({Idx, Offset, Len}, Requests),
  -        NQ = etorrent_utils:queue_remove({Idx, Offset, Len}, Requests),
  -        {noreply, S#state { requests = NQ}, 0}
  -    catch
  -        exit:badmatch -> {stop, normal, S}
  -    end;
  -handle_cast({cancel, Index, OffSet, Len}, S) ->
  -    NQ = etorrent_utils:queue_remove({Index, OffSet, Len}, S#state.requests),
  -    {noreply, S#state{requests = NQ}, 0};
  -
  -handle_cast({request, {Index, Offset, Size}}, S) ->
  -    send_message({request, Index, Offset, Size}, S);
  -handle_cast({remote_request, Idx, Offset, Len},
  -    #state { fast_extension = true, choke = true } = S) ->
  -        send_message({reject_request, Idx, Offset, Len}, S, 0);
  -handle_cast({remote_request, _Index, _Offset, _Len}, #state { choke = true } = S) ->
  -    {noreply, S, 0};
  -handle_cast({remote_request, Index, Offset, Len},
  -            #state { choke = false, fast_extension = FastExtension,
  -                     requests = Reqs} = S) ->
  -    case queue:len(Reqs) > ?MAX_REQUESTS of
  -        true when FastExtension == true ->
  -            send_message({reject_request, Index, Offset, Len}, S, 0);
  -        true ->
  -            {stop, max_queue_len_exceeded, S};
  -        false ->
  -	    %% @todo consider to make a check here if the request is already
  -	    %%  on queue. I don't think we will have that, except if stray.
  -            NQ = queue:in({Index, Offset, Len}, S#state.requests),
  -            {noreply, S#state{requests = NQ}, 0}
  -    end;
  -
  -handle_cast(Msg, State) ->
  -    {stop, Msg, State}.
   
   
   %% @private
  
positive.code: 
  %%====================================================================
  
  %% @private
  handle_call(_Request, _From, State) ->
      Reply = ok,
      {reply, Reply, State}.
  
  %% @private
  init([Socket, TorrentId, FastExtension]) ->
  
negative.code: 		torrent_id = TorrentId,
  		fast_extension = FastExtension}}.
  
  %% @private
  handle_call(Msg, _From, State) ->
      {stop, Msg, State}.
  
  
  %% Handle requests to choke and unchoke. If we are already choking the peer,
  %% there is no reason to send the message again.
  %% @private
  handle_cast(choke, S) -> perform_choke(S);
  handle_cast(unchoke, #state { choke = false } = S) -> {noreply, S, 0};
  handle_cast(unchoke,
          #state { choke = true, torrent_id = Torrent_Id, control_pid = ControlPid } = S) ->
      ok = etorrent_peer_states:set_local_unchoke(Torrent_Id, ControlPid),
      send_message(unchoke, S#state{choke = false});
  
  %% A request to check the current choke state and ask for a rechoking
  handle_cast(check_choke, #state { choke = true } = S) ->
      {noreply, S, 0};
  handle_cast(check_choke, #state { choke = false } = S) ->
      ok = etorrent_choker:perform_rechoke(),
      {noreply, S, 0};
  
  %% Regular messages. We just send them onwards on the wire.
  handle_cast({piece, Index, Offset, _, Data}, State) ->
      send_message({piece, Index, Offset, Data}, State);
  handle_cast({reject, Index, Offset, Length}, State) ->
      send_message({reject_request, Index, Offset, Length}, State);
  handle_cast({bitfield, BF}, S) ->
      send_message({bitfield, BF}, S);
  handle_cast(extended_msg, S) ->
      send_message({extended, 0, etorrent_proto_wire:extended_msg_contents()}, S);
  handle_cast(not_interested, #state { interested = false} = S) ->
      {noreply, S, 0};
  handle_cast(not_interested, #state { interested = true } = S) ->
      send_message(not_interested, S#state { interested = false });
  handle_cast(interested, #state { interested = true } = S) ->
      {noreply, S, 0};
  handle_cast(interested, #state { interested = false } = S) ->
      send_message(interested, S#state { interested = true });
  handle_cast({have, Pn}, S) ->
      send_message({have, Pn}, S);
  
  %% Cancels are handled specially when the fast extension is enabled.
  handle_cast({cancel, Idx, Offset, Len},
          #state { fast_extension = true, requests = Requests} = S) ->
      try
  	true = queue:member({Idx, Offset, Len}, Requests),
          NQ = etorrent_utils:queue_remove({Idx, Offset, Len}, Requests),
          {noreply, S#state { requests = NQ}, 0}
      catch
          exit:badmatch -> {stop, normal, S}
      end;
  handle_cast({cancel, Index, OffSet, Len}, S) ->
      NQ = etorrent_utils:queue_remove({Index, OffSet, Len}, S#state.requests),
      {noreply, S#state{requests = NQ}, 0};
  
  handle_cast({request, {Index, Offset, Size}}, S) ->
      send_message({request, Index, Offset, Size}, S);
  handle_cast({remote_request, Idx, Offset, Len},
      #state { fast_extension = true, choke = true } = S) ->
          send_message({reject_request, Idx, Offset, Len}, S, 0);
  handle_cast({remote_request, _Index, _Offset, _Len}, #state { choke = true } = S) ->
      {noreply, S, 0};
  handle_cast({remote_request, Index, Offset, Len},
              #state { choke = false, fast_extension = FastExtension,
                       requests = Reqs} = S) ->
      case queue:len(Reqs) > ?MAX_REQUESTS of
          true when FastExtension == true ->
              send_message({reject_request, Index, Offset, Len}, S, 0);
          true ->
              {stop, max_queue_len_exceeded, S};
          false ->
  	    %% @todo consider to make a check here if the request is already
  	    %%  on queue. I don't think we will have that, except if stray.
              NQ = queue:in({Index, Offset, Len}, S#state.requests),
              {noreply, S#state{requests = NQ}, 0}
      end;
  
  handle_cast(Msg, State) ->
      {stop, Msg, State}.
  
  %% Whenever a tick is hit, we send out a keep alive message on the line.
  %% @private
  