1 %%%-------------------------------------------------------------------
2 %%% File : etorrent_t_peer_pool_sup.erl
3 %%% Author : Jesper Louis Andersen <>
4 %%% Description : Supervise a group of peer processes.
6 %%% Created : 17 Aug 2007 by Jesper Louis Andersen <>
7 %%%-------------------------------------------------------------------
8 -module(etorrent_t_peer_pool_sup
).
10 -behaviour(supervisor
).
13 -export([start_link
/0, add_peer
/6]).
15 %% Supervisor callbacks
18 -define(SERVER
, ?MODULE
).
20 %%====================================================================
22 %%====================================================================
23 %%--------------------------------------------------------------------
24 %% Function: start_link() -> {ok,Pid} | ignore | {error,Error}
25 %% Description: Starts the supervisor
26 %%--------------------------------------------------------------------
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
,
37 {ok
, Pid
} = supervisor:start_child(GroupPid
, [LocalPeerId
, InfoHash
,
40 Children
= supervisor:which_children(Pid
),
41 {value
, {_
, Child
, _
, _
}} = lists:keysearch(receiver
, 1, Children
),
44 %%====================================================================
45 %% Supervisor callbacks
46 %%====================================================================
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 %%====================================================================
55 %%====================================================================