Handle HAVE_ALL and HAVE_NONE. Cleanup the BITFIELD message.
[etorrent.git] / lib / etorrent-1.0 / src / etorrent_t_peer_sup.erl
blob1d7a21fecb9856d127abd8a6dfbc97c54f7e24bc
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/5, 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, Id, {IP, Port}) ->
28 supervisor:start_link(?MODULE, [LocalPeerId,
29 InfoHash,
30 FilesystemPid,
31 Id,
32 {IP, Port}]).
34 add_sender(Pid, Socket, FileSystemPid, Id, RecvPid) ->
35 Sender = {sender, {etorrent_t_peer_send, start_link,
36 [Socket, FileSystemPid, Id, RecvPid]},
37 permanent, 15000, worker, [etorrent_t_peer_send]},
38 supervisor:start_child(Pid, Sender).
40 %%====================================================================
41 %% Supervisor callbacks
42 %%====================================================================
43 %%--------------------------------------------------------------------
44 %% Func: init(Args) -> {ok, {SupFlags, [ChildSpec]}} |
45 %% ignore |
46 %% {error, Reason}
47 %% Description: Whenever a supervisor is started using
48 %% supervisor:start_link/[2,3], this function is called by the new process
49 %% to find out about restart strategy, maximum restart frequency and child
50 %% specifications.
51 %%--------------------------------------------------------------------
52 init([LocalPeerId, InfoHash, FilesystemPid, Id, {IP, Port}]) ->
53 Receiver = {receiver, {etorrent_t_peer_recv, start_link,
54 [LocalPeerId, InfoHash, FilesystemPid, Id, self(),
55 {IP, Port}]},
56 permanent, 15000, worker, [etorrent_t_peer_recv]},
57 {ok, {{one_for_all, 0, 1}, [Receiver]}}.
59 %%====================================================================
60 %% Internal functions
61 %%====================================================================