1 %%%-------------------------------------------------------------------
2 %%% File : etorrent_t_sup.erl
3 %%% Author : Jesper Louis Andersen <jlouis@succubus.local.domain>
4 %%% License : See COPYING
5 %%% Description : Supervision of torrent modules.
7 %%% Created : 13 Jul 2007 by
8 %%% Jesper Louis Andersen <jlouis@succubus.local.domain>
9 %%%-------------------------------------------------------------------
10 -module(etorrent_t_sup
).
12 -behaviour(supervisor
).
15 -export([start_link
/3, add_tracker
/5, get_pid
/2,
18 %% Supervisor callbacks
21 %%====================================================================
23 %%====================================================================
24 start_link(File
, Local_PeerId
, Id
) ->
25 supervisor:start_link(?MODULE
, [File
, Local_PeerId
, Id
]).
27 %%--------------------------------------------------------------------
29 %% Args: Pid ::= pid() - Pid of the supervisor
30 %% Name ::= atom() - the atom the pid is identified by
31 %% Description: Return the Pid of the peer group process.
32 %%--------------------------------------------------------------------
34 {value
, {_
, Child
, _
, _
}} =
35 lists:keysearch(Name
, 1, supervisor:which_children(Pid
)),
38 %%--------------------------------------------------------------------
39 %% Func: add_filesystem/3
40 %% Description: Add a filesystem process to the torrent.
41 %%--------------------------------------------------------------------
43 %%--------------------------------------------------------------------
44 %% Func: add_file_system_pool/1
45 %% Description: Add a filesystem process to the torrent.
46 %%--------------------------------------------------------------------
47 add_tracker(Pid
, URL
, InfoHash
, Local_Peer_Id
, TorrentId
) ->
48 Tracker
= {tracker_communication
,
49 {etorrent_tracker_communication
, start_link
,
50 [self(), URL
, InfoHash
, Local_Peer_Id
, TorrentId
]},
51 permanent
, 15000, worker
, [etorrent_tracker_communication
]},
52 supervisor:start_child(Pid
, Tracker
).
54 add_peer(Pid
, PeerId
, InfoHash
, TorrentId
, {IP
, Port
}) ->
55 FSPid
= get_pid(Pid
, fs
),
56 GroupPid
= get_pid(Pid
, peer_pool_sup
),
57 etorrent_t_peer_pool_sup:add_peer(GroupPid
,
64 %%====================================================================
65 %% Supervisor callbacks
66 %%====================================================================
67 %%--------------------------------------------------------------------
68 %% Func: init(Args) -> {ok, {SupFlags, [ChildSpec]}} |
71 %% Description: Whenever a supervisor is started using
72 %% supervisor:start_link/[2,3], this function is called by the new process
73 %% to find out about restart strategy, maximum restart frequency and child
75 %%--------------------------------------------------------------------
76 init([Path
, PeerId
, Id
]) ->
78 {etorrent_fs_pool_sup
, start_link
, []},
79 transient
, infinity
, supervisor
, [etorrent_fs_pool_sup
]},
81 {etorrent_fs
, start_link
, [Id
, self()]},
82 permanent
, 2000, worker
, [etorrent_fs
]},
84 {etorrent_t_control
, start_link
, [Id
, Path
, PeerId
]},
85 permanent
, 20000, worker
, [etorrent_t_control
]},
86 PeerPool
= {peer_pool_sup
,
87 {etorrent_t_peer_pool_sup
, start_link
, []},
88 transient
, infinity
, supervisor
, [etorrent_t_peer_pool_sup
]},
89 {ok
, {{one_for_all
, 1, 60}, [FSPool
, FS
, Control
, PeerPool
]}}.
91 %%====================================================================
93 %%====================================================================