From 13ae345cb8e446faf1804c41bb823ba1b278c449 Mon Sep 17 00:00:00 2001 From: Jesper Louis Andersen Date: Fri, 25 Jul 2008 00:43:51 +0200 Subject: [PATCH] Only perform rechokes when we need to from peer_recv. --- lib/etorrent-1.0/src/etorrent_t_peer_recv.erl | 6 ++---- lib/etorrent-1.0/src/etorrent_t_peer_send.erl | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/etorrent-1.0/src/etorrent_t_peer_recv.erl b/lib/etorrent-1.0/src/etorrent_t_peer_recv.erl index 80cbe2d..f8bc4f0 100644 --- a/lib/etorrent-1.0/src/etorrent_t_peer_recv.erl +++ b/lib/etorrent-1.0/src/etorrent_t_peer_recv.erl @@ -308,13 +308,11 @@ handle_message(unchoke, S) -> try_to_queue_up_pieces(S#state{remote_choked = false}); handle_message(interested, S) -> ok = etorrent_rate_mgr:interested(S#state.torrent_id, self()), - %%TODO: Only call this if the guy is *not* choked by us - etorrent_choker:perform_rechoke(), + ok = etorrent_t_peer_send:check_choke(S#state.send_pid), {ok, S}; handle_message(not_interested, S) -> ok = etorrent_rate_mgr:not_interested(S#state.torrent_id, self()), - %%TODO: Only call this if the guy is *not* choked by us - etorrent_choker:perform_rechoke(), + ok = etorrent_t_peer_send:check_choke(S#state.send_pid), {ok, S}; handle_message({request, Index, Offset, Len}, S) -> etorrent_t_peer_send:remote_request(S#state.send_pid, Index, Offset, Len), diff --git a/lib/etorrent-1.0/src/etorrent_t_peer_send.erl b/lib/etorrent-1.0/src/etorrent_t_peer_send.erl index 4c014df..208eeb2 100644 --- a/lib/etorrent-1.0/src/etorrent_t_peer_send.erl +++ b/lib/etorrent-1.0/src/etorrent_t_peer_send.erl @@ -15,9 +15,16 @@ -behaviour(gen_server). %% API --export([start_link/4, remote_request/4, cancel/4, choke/1, unchoke/1, - local_request/2, not_interested/1, send_have_piece/2, stop/1, - bitfield/2, interested/1]). +-export([start_link/4, + stop/1, + check_choke/1, + + local_request/2, remote_request/4, cancel/4, + choke/1, unchoke/1, + + not_interested/1, interested/1, + send_have_piece/2, + bitfield/2]). %% gen_server callbacks -export([init/1, handle_info/2, terminate/2, code_change/3, @@ -81,6 +88,8 @@ choke(Pid) -> unchoke(Pid) -> gen_server:cast(Pid, unchoke). +check_choke(Pid) -> gen_server:cast(Pid, check_choke). + %%-------------------------------------------------------------------- %% Func: not_interested(Pid) %% Description: Tell the peer we are not interested in him anymore @@ -184,6 +193,11 @@ handle_cast(unchoke, S) when S#state.choke == true -> ok = etorrent_rate_mgr:local_unchoke(S#state.torrent_id, S#state.parent), send_message(unchoke, S#state{choke = false, request_queue = queue:new()}); +handle_cast(check_choke, S) when S#state.choke =:= true -> + {noreply, S, 0}; +handle_cast(check_choke, S) when S#state.choke =:= false -> + ok = etorrent_choker:perform_rechoke(), + {noreply, S, 0}; handle_cast({bitfield, BF}, S) -> send_message({bitfield, BF}, S); handle_cast(not_interested, S) when S#state.interested =:= false -> -- 2.11.4.GIT