Handle HAVE_ALL and HAVE_NONE. Cleanup the BITFIELD message.
[etorrent.git] / lib / etorrent-1.0 / src / etorrent_t_peer_pool_sup.erl
blobc54807cff7a6f5129bb881fe955bef1c7607929e
1 %%%-------------------------------------------------------------------
2 %%% File : etorrent_t_peer_pool_sup.erl
3 %%% Author : Jesper Louis Andersen <>
4 %%% Description : Supervise a group of peer processes.
5 %%%
6 %%% Created : 17 Aug 2007 by Jesper Louis Andersen <>
7 %%%-------------------------------------------------------------------
8 -module(etorrent_t_peer_pool_sup).
10 -behaviour(supervisor).
12 %% API
13 -export([start_link/0, add_peer/6]).
15 %% Supervisor callbacks
16 -export([init/1]).
18 -define(SERVER, ?MODULE).
20 %%====================================================================
21 %% API functions
22 %%====================================================================
23 %%--------------------------------------------------------------------
24 %% Function: start_link() -> {ok,Pid} | ignore | {error,Error}
25 %% Description: Starts the supervisor
26 %%--------------------------------------------------------------------
27 start_link() ->
28 supervisor:start_link(?MODULE, []).
30 %%--------------------------------------------------------------------
31 %% Function: add_peer/6
32 %% Description: Add a peer to the supervisor pool. Returns the
33 %% receiver process hooked on the supervisor.
34 %%--------------------------------------------------------------------
35 add_peer(GroupPid, LocalPeerId, InfoHash, FilesystemPid, Id,
36 {IP, Port}) ->
37 {ok, Pid} = supervisor:start_child(GroupPid, [LocalPeerId, InfoHash,
38 FilesystemPid, Id,
39 {IP, Port}]),
40 Children = supervisor:which_children(Pid),
41 {value, {_, Child, _, _}} = lists:keysearch(receiver, 1, Children),
42 {ok, Child}.
44 %%====================================================================
45 %% Supervisor callbacks
46 %%====================================================================
47 init([]) ->
48 PeerRecvs = {peer_recv,
49 {etorrent_t_peer_sup, start_link, []},
50 temporary, infinity, supervisor, [etorrent_t_peer_recv]},
51 {ok, {{simple_one_for_one, 15, 60}, [PeerRecvs]}}.
53 %%====================================================================
54 %% Internal functions
55 %%====================================================================