Permalink
Browse files

Whitespace...

  • Loading branch information...
1 parent f6937bb commit 88febcc825c9f57eec04e33685c926699fb71560 @jlouis committed Nov 19, 2011
@@ -48,8 +48,8 @@ handle_cast(_Msg, State) ->
handle_info(timeout, #state { our_peer_id = PeerId } = S) ->
case gen_tcp:accept(S#state.listen_socket) of
{ok, Socket} ->
- {ok, _Pid} = etorrent_listen_sup:start_child(),
- handshake(Socket, PeerId);
+ {ok, _Pid} = etorrent_listen_sup:start_child(),
+ handshake(Socket, PeerId);
{error, closed} -> ok;
{error, econnaborted} -> ok;
{error, enotconn} -> ok;
@@ -72,49 +72,49 @@ handshake(Socket, PeerId) ->
%% if the check fails. Finally, control is handed over to the control
%% pid or we handle an error by closing down.
try
- {ok, {IP, Port}} = inet:peername(Socket),
- {ok, Caps, InfoHash, HisPeerId} = receive_handshake(Socket),
- ok = check_infohash(InfoHash),
- ok = check_peer(IP, Port, InfoHash, HisPeerId, PeerId),
- ok = check_peer_count(),
- {ok, RecvPid, ControlPid} =
- check_torrent_state(Socket, Caps, IP, Port, InfoHash, PeerId),
- ok = handover_control(Socket, RecvPid, ControlPid)
+ {ok, {IP, Port}} = inet:peername(Socket),
+ {ok, Caps, InfoHash, HisPeerId} = receive_handshake(Socket),
+ ok = check_infohash(InfoHash),
+ ok = check_peer(IP, Port, InfoHash, HisPeerId, PeerId),
+ ok = check_peer_count(),
+ {ok, RecvPid, ControlPid} =
+ check_torrent_state(Socket, Caps, IP, Port, InfoHash, PeerId),
+ ok = handover_control(Socket, RecvPid, ControlPid)
catch
error:{badmatch, {error, enotconn}} ->
ok;
- throw:{error, _Reason} ->
- gen_tcp:close(Socket),
- ok;
- throw:{bad_peer, HisPId} ->
- ?INFO([peer_id_is_bad, HisPId]),
- gen_tcp:close(Socket),
- ok
+ throw:{error, _Reason} ->
+ gen_tcp:close(Socket),
+ ok;
+ throw:{bad_peer, HisPId} ->
+ ?INFO([peer_id_is_bad, HisPId]),
+ gen_tcp:close(Socket),
+ ok
end.
receive_handshake(Socket) ->
case etorrent_proto_wire:receive_handshake(Socket) of
{ok, Caps, InfoHash, HisPeerId} ->
- {ok, Caps, InfoHash, HisPeerId};
- {error, Reason} ->
- throw({error, Reason})
+ {ok, Caps, InfoHash, HisPeerId};
+ {error, Reason} ->
+ throw({error, Reason})
end.
check_infohash(InfoHash) ->
case etorrent_table:get_torrent({infohash, InfoHash}) of
- {value, _} ->
- ok;
- not_found ->
- throw({error, infohash_not_found})
+ {value, _} ->
+ ok;
+ not_found ->
+ throw({error, infohash_not_found})
end.
handover_control(Socket, RPid, CPid) ->
case gen_tcp:controlling_process(Socket, RPid) of
- ok -> etorrent_peer_control:initialize(CPid, incoming),
- ok;
- {error, enotconn} ->
- etorrent_peer_control:stop(CPid),
- throw({error, enotconn})
+ ok -> etorrent_peer_control:initialize(CPid, incoming),
+ ok;
+ {error, enotconn} ->
+ etorrent_peer_control:stop(CPid),
+ throw({error, enotconn})
end.
check_peer(_IP, _Port, _InfoHash, PeerId, PeerId) ->
@@ -123,33 +123,31 @@ check_peer(IP, Port, InfoHash, HisPeerId, _OurPeerId) ->
{value, PL} = etorrent_table:get_torrent({infohash, InfoHash}),
case etorrent_peer_mgr:is_bad_peer(IP, Port) of
true ->
- throw({bad_peer, HisPeerId});
+ throw({bad_peer, HisPeerId});
false ->
- ok
+ ok
end,
case etorrent_table:connected_peer(IP, Port, proplists:get_value(id, PL)) of
- true -> throw({error, already_connected});
- false -> ok
+ true -> throw({error, already_connected});
+ false -> ok
end.
check_torrent_state(Socket, Caps, IP, Port, InfoHash, OurPeerId) ->
{value, PL} = etorrent_table:get_torrent({infohash, InfoHash}),
case proplists:get_value(state, PL) of
- started ->
- etorrent_peer_pool:start_child(
- OurPeerId,
- InfoHash,
- proplists:get_value(id, PL),
- {IP, Port},
- Caps,
- Socket);
- _ -> throw({error, not_ready_for_connections})
+ started ->
+ etorrent_peer_pool:start_child(
+ OurPeerId,
+ InfoHash,
+ proplists:get_value(id, PL),
+ {IP, Port},
+ Caps,
+ Socket);
+ _ -> throw({error, not_ready_for_connections})
end.
check_peer_count() ->
case etorrent_counters:slots_left() of
{value, 0} -> throw({error, already_enough_connections});
{value, K} when is_integer(K) -> ok
end.
-
-
@@ -23,7 +23,8 @@
%% access to always when it wants to request.</p>
%% @end
-type ip() :: {integer(), integer(), integer(), integer()}.
--spec allowed_fast(integer(), ip() | binary(), integer(), binary()) -> {value, set()}.
+-spec allowed_fast(integer(), ip() | binary(), integer(), binary()) ->
+ {value, set()}.
allowed_fast(Sz, {B1, B2, B3, B4}, K, InfoHash) ->
B = <<B1:8/integer, B2:8/integer, B3:8/integer, B4:8/integer>>,
allowed_fast(Sz, B, K, InfoHash);
@@ -87,11 +87,12 @@ stop(_State) ->
start_webui() ->
Dispatch = [ {'_', [{'_', etorrent_cowboy_handler, []}]} ],
- {ok, _Pid} = cowboy:start_listener(http, 10,
- cowboy_tcp_transport, [{port, 8080}],
- cowboy_http_protocol, [{dispatch, Dispatch}]
- ).
-
+ {ok, _Pid} =
+ cowboy:start_listener(http, 10,
+ cowboy_tcp_transport, [{port, 8080}],
+ cowboy_http_protocol, [{dispatch, Dispatch}]
+ ).
+
%% @doc Generate a random peer id for use
%% @end
generate_peer_id() ->
@@ -29,7 +29,7 @@
% Retrieval
-export([get_value/2, get_value/3, get_info_value/2, get_info_value/3,
get_binary_value/2, get_binary_value/3,
- get_string_value/2, get_string_value/3]).
+ get_string_value/2, get_string_value/3]).
-type bcode() :: etorrent_types:bcode().
@@ -110,8 +110,8 @@ get_binary_value(Key, PL) ->
%% @end
get_binary_value(Key, PL, Default) ->
case get_value(Key, PL) of
- undefined -> Default;
- B when is_binary(B) -> B
+ undefined -> Default;
+ B when is_binary(B) -> B
end.
%% @doc Read a string Value indexed by Key from the PL dict
@@ -123,8 +123,8 @@ get_string_value(Key, PL) -> binary_to_list(get_binary_value(Key, PL)).
%% @end
get_string_value(Key, PL, Default) ->
case get_value(Key, PL) of
- undefined -> Default;
- V when is_binary(V) -> binary_to_list(V)
+ undefined -> Default;
+ V when is_binary(V) -> binary_to_list(V)
end.
%% @doc Parse a file into a Torrent structure.
@@ -198,9 +198,9 @@ decode_dict_items(String, Accum) ->
prop_inv() ->
?FORALL(BC, bcode(),
begin
- Enc = iolist_to_binary(encode(BC)),
- {ok, Dec} = decode(Enc),
- encode(BC) =:= encode(Dec)
+ Enc = iolist_to_binary(encode(BC)),
+ {ok, Dec} = decode(Enc),
+ encode(BC) =:= encode(Dec)
end).
eqc_test() ->
Oops, something went wrong.

0 comments on commit 88febcc

Please sign in to comment.