Move #peer record management to etorrent_t_peer_recv.
[etorrent.git] / lib / etorrent-1.0 / src / etorrent_t_peer_sup.erl
blob841c144665cb4fc63925b7b4029066c95fffe121
1 %%%-------------------------------------------------------------------
2 %%% File : etorrent_t_peer_sup.erl
3 %%% Author : Jesper Louis Andersen <>
4 %%% Description : Supervisor for a peer connection.
5 %%%
6 %%% Created : 10 Jul 2008 by Jesper Louis Andersen <>
7 %%%-------------------------------------------------------------------
8 -module(etorrent_t_peer_sup).
10 -behaviour(supervisor).
12 %% API
13 -export([start_link/6, add_sender/5]).
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(LocalPeerId, InfoHash, FilesystemPid, GroupPid, Id, {IP, Port}) ->
28 supervisor:start_link(?MODULE, [LocalPeerId,
29 InfoHash,
30 FilesystemPid,
31 GroupPid,
32 Id,
33 {IP, Port}]).
35 add_sender(Pid, Socket, FileSystemPid, Id, RecvPid) ->
36 Sender = {sender, {etorrent_t_peer_send, start_link,
37 [Socket, FileSystemPid, Id, RecvPid]},
38 permanent, 15000, worker, [etorrent_t_peer_send]},
39 supervisor:start_child(Pid, Sender).
41 %%====================================================================
42 %% Supervisor callbacks
43 %%====================================================================
44 %%--------------------------------------------------------------------
45 %% Func: init(Args) -> {ok, {SupFlags, [ChildSpec]}} |
46 %% ignore |
47 %% {error, Reason}
48 %% Description: Whenever a supervisor is started using
49 %% supervisor:start_link/[2,3], this function is called by the new process
50 %% to find out about restart strategy, maximum restart frequency and child
51 %% specifications.
52 %%--------------------------------------------------------------------
53 init([LocalPeerId, InfoHash, FilesystemPid, GroupPid, Id, {IP, Port}]) ->
54 Reciever = {reciever, {etorrent_t_peer_recv, start_link,
55 [LocalPeerId, InfoHash, FilesystemPid, GroupPid, Id, self(),
56 {IP, Port}]},
57 permanent, 15000, worker, [etorrent_t_peer_recv]},
58 {ok, {{one_for_all, 0, 1}, [Reciever]}}.
60 %%====================================================================
61 %% Internal functions
62 %%====================================================================