Skip to content
Browse files

Return correct number of complete and incomplete peers in tracker res…

…ponse
  • Loading branch information...
1 parent 94da7e6 commit 6502ee42a7b17a81b7c474034001684e833a9642 @timpritlove committed Mar 13, 2011
Showing with 10 additions and 2 deletions.
  1. +4 −1 src/tracker_web.erl
  2. +6 −1 src/trackerdb.erl
View
5 src/tracker_web.erl
@@ -36,7 +36,10 @@ loop(Req) ->
Payload = << <<A,B,C,D,P:16/big>> || { _, {A,B,C,D}, P } <- AvailablePeers >>,
{ok, Interval} = tracker_manager:get(interval),
- Response = benc:to_binary([{<<"interval">>,Interval},{<<"peers">>, Payload}]),
+ Response = benc:to_binary([ {<<"complete">>,Complete},
+ {<<"incomplete">>,Incomplete},
+ {<<"interval">>,Interval},
+ {<<"peers">>, Payload}]),
io:format("~p~s~n", [AvailablePeers,Response]),
Req:ok({"text/plain", Response});
View
7 src/trackerdb.erl
@@ -30,7 +30,12 @@ announce(InfoHash, Ip, Port, PeerId, Uploaded, Downloaded, Left) ->
AvailablePeers = [ { TmpPeerId, TmpIp, TmpPort } ||
Peer = #pirate{ peer_id = TmpPeerId, ip = TmpIp, port = TmpPort } <- AllPeers, Peer#pirate.id =/= PrimaryPeerKey],
- Complete = 0, Incomplete = 0,
+ { Complete, Incomplete } = mnesia:foldl(
+ fun(#pirate{left = 0}, { CompleteAcc, IncompleteAcc} ) ->
+ { CompleteAcc + 1, IncompleteAcc };
+ (_, { CompleteAcc, IncompleteAcc} ) ->
+ { CompleteAcc , IncompleteAcc + 1 }
+ end, { 0, 0}, pirate),
{ ok, AvailablePeers, Complete, Incomplete }
end),
Result.

0 comments on commit 6502ee4

Please sign in to comment.
Something went wrong with that request. Please try again.