Skip to content
This repository
Browse code

Whitespace...

  • Loading branch information...
commit 88febcc825c9f57eec04e33685c926699fb71560 1 parent f6937bb
Jesper Louis Andersen authored
86 apps/etorrent/src/etorrent_acceptor.erl
@@ -48,8 +48,8 @@ handle_cast(_Msg, State) ->
48 48 handle_info(timeout, #state { our_peer_id = PeerId } = S) ->
49 49 case gen_tcp:accept(S#state.listen_socket) of
50 50 {ok, Socket} ->
51   - {ok, _Pid} = etorrent_listen_sup:start_child(),
52   - handshake(Socket, PeerId);
  51 + {ok, _Pid} = etorrent_listen_sup:start_child(),
  52 + handshake(Socket, PeerId);
53 53 {error, closed} -> ok;
54 54 {error, econnaborted} -> ok;
55 55 {error, enotconn} -> ok;
@@ -72,49 +72,49 @@ handshake(Socket, PeerId) ->
72 72 %% if the check fails. Finally, control is handed over to the control
73 73 %% pid or we handle an error by closing down.
74 74 try
75   - {ok, {IP, Port}} = inet:peername(Socket),
76   - {ok, Caps, InfoHash, HisPeerId} = receive_handshake(Socket),
77   - ok = check_infohash(InfoHash),
78   - ok = check_peer(IP, Port, InfoHash, HisPeerId, PeerId),
79   - ok = check_peer_count(),
80   - {ok, RecvPid, ControlPid} =
81   - check_torrent_state(Socket, Caps, IP, Port, InfoHash, PeerId),
82   - ok = handover_control(Socket, RecvPid, ControlPid)
  75 + {ok, {IP, Port}} = inet:peername(Socket),
  76 + {ok, Caps, InfoHash, HisPeerId} = receive_handshake(Socket),
  77 + ok = check_infohash(InfoHash),
  78 + ok = check_peer(IP, Port, InfoHash, HisPeerId, PeerId),
  79 + ok = check_peer_count(),
  80 + {ok, RecvPid, ControlPid} =
  81 + check_torrent_state(Socket, Caps, IP, Port, InfoHash, PeerId),
  82 + ok = handover_control(Socket, RecvPid, ControlPid)
83 83 catch
84 84 error:{badmatch, {error, enotconn}} ->
85 85 ok;
86   - throw:{error, _Reason} ->
87   - gen_tcp:close(Socket),
88   - ok;
89   - throw:{bad_peer, HisPId} ->
90   - ?INFO([peer_id_is_bad, HisPId]),
91   - gen_tcp:close(Socket),
92   - ok
  86 + throw:{error, _Reason} ->
  87 + gen_tcp:close(Socket),
  88 + ok;
  89 + throw:{bad_peer, HisPId} ->
  90 + ?INFO([peer_id_is_bad, HisPId]),
  91 + gen_tcp:close(Socket),
  92 + ok
93 93 end.
94 94
95 95 receive_handshake(Socket) ->
96 96 case etorrent_proto_wire:receive_handshake(Socket) of
97 97 {ok, Caps, InfoHash, HisPeerId} ->
98   - {ok, Caps, InfoHash, HisPeerId};
99   - {error, Reason} ->
100   - throw({error, Reason})
  98 + {ok, Caps, InfoHash, HisPeerId};
  99 + {error, Reason} ->
  100 + throw({error, Reason})
101 101 end.
102 102
103 103 check_infohash(InfoHash) ->
104 104 case etorrent_table:get_torrent({infohash, InfoHash}) of
105   - {value, _} ->
106   - ok;
107   - not_found ->
108   - throw({error, infohash_not_found})
  105 + {value, _} ->
  106 + ok;
  107 + not_found ->
  108 + throw({error, infohash_not_found})
109 109 end.
110 110
111 111 handover_control(Socket, RPid, CPid) ->
112 112 case gen_tcp:controlling_process(Socket, RPid) of
113   - ok -> etorrent_peer_control:initialize(CPid, incoming),
114   - ok;
115   - {error, enotconn} ->
116   - etorrent_peer_control:stop(CPid),
117   - throw({error, enotconn})
  113 + ok -> etorrent_peer_control:initialize(CPid, incoming),
  114 + ok;
  115 + {error, enotconn} ->
  116 + etorrent_peer_control:stop(CPid),
  117 + throw({error, enotconn})
118 118 end.
119 119
120 120 check_peer(_IP, _Port, _InfoHash, PeerId, PeerId) ->
@@ -123,27 +123,27 @@ check_peer(IP, Port, InfoHash, HisPeerId, _OurPeerId) ->
123 123 {value, PL} = etorrent_table:get_torrent({infohash, InfoHash}),
124 124 case etorrent_peer_mgr:is_bad_peer(IP, Port) of
125 125 true ->
126   - throw({bad_peer, HisPeerId});
  126 + throw({bad_peer, HisPeerId});
127 127 false ->
128   - ok
  128 + ok
129 129 end,
130 130 case etorrent_table:connected_peer(IP, Port, proplists:get_value(id, PL)) of
131   - true -> throw({error, already_connected});
132   - false -> ok
  131 + true -> throw({error, already_connected});
  132 + false -> ok
133 133 end.
134 134
135 135 check_torrent_state(Socket, Caps, IP, Port, InfoHash, OurPeerId) ->
136 136 {value, PL} = etorrent_table:get_torrent({infohash, InfoHash}),
137 137 case proplists:get_value(state, PL) of
138   - started ->
139   - etorrent_peer_pool:start_child(
140   - OurPeerId,
141   - InfoHash,
142   - proplists:get_value(id, PL),
143   - {IP, Port},
144   - Caps,
145   - Socket);
146   - _ -> throw({error, not_ready_for_connections})
  138 + started ->
  139 + etorrent_peer_pool:start_child(
  140 + OurPeerId,
  141 + InfoHash,
  142 + proplists:get_value(id, PL),
  143 + {IP, Port},
  144 + Caps,
  145 + Socket);
  146 + _ -> throw({error, not_ready_for_connections})
147 147 end.
148 148
149 149 check_peer_count() ->
@@ -151,5 +151,3 @@ check_peer_count() ->
151 151 {value, 0} -> throw({error, already_enough_connections});
152 152 {value, K} when is_integer(K) -> ok
153 153 end.
154   -
155   -
3  apps/etorrent/src/etorrent_allowed_fast.erl
@@ -23,7 +23,8 @@
23 23 %% access to always when it wants to request.</p>
24 24 %% @end
25 25 -type ip() :: {integer(), integer(), integer(), integer()}.
26   --spec allowed_fast(integer(), ip() | binary(), integer(), binary()) -> {value, set()}.
  26 +-spec allowed_fast(integer(), ip() | binary(), integer(), binary()) ->
  27 + {value, set()}.
27 28 allowed_fast(Sz, {B1, B2, B3, B4}, K, InfoHash) ->
28 29 B = <<B1:8/integer, B2:8/integer, B3:8/integer, B4:8/integer>>,
29 30 allowed_fast(Sz, B, K, InfoHash);
11 apps/etorrent/src/etorrent_app.erl
@@ -87,11 +87,12 @@ stop(_State) ->
87 87
88 88 start_webui() ->
89 89 Dispatch = [ {'_', [{'_', etorrent_cowboy_handler, []}]} ],
90   - {ok, _Pid} = cowboy:start_listener(http, 10,
91   - cowboy_tcp_transport, [{port, 8080}],
92   - cowboy_http_protocol, [{dispatch, Dispatch}]
93   - ).
94   -
  90 + {ok, _Pid} =
  91 + cowboy:start_listener(http, 10,
  92 + cowboy_tcp_transport, [{port, 8080}],
  93 + cowboy_http_protocol, [{dispatch, Dispatch}]
  94 + ).
  95 +
95 96 %% @doc Generate a random peer id for use
96 97 %% @end
97 98 generate_peer_id() ->
16 apps/etorrent/src/etorrent_bcoding.erl
@@ -29,7 +29,7 @@
29 29 % Retrieval
30 30 -export([get_value/2, get_value/3, get_info_value/2, get_info_value/3,
31 31 get_binary_value/2, get_binary_value/3,
32   - get_string_value/2, get_string_value/3]).
  32 + get_string_value/2, get_string_value/3]).
33 33
34 34 -type bcode() :: etorrent_types:bcode().
35 35
@@ -110,8 +110,8 @@ get_binary_value(Key, PL) ->
110 110 %% @end
111 111 get_binary_value(Key, PL, Default) ->
112 112 case get_value(Key, PL) of
113   - undefined -> Default;
114   - B when is_binary(B) -> B
  113 + undefined -> Default;
  114 + B when is_binary(B) -> B
115 115 end.
116 116
117 117 %% @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)).
123 123 %% @end
124 124 get_string_value(Key, PL, Default) ->
125 125 case get_value(Key, PL) of
126   - undefined -> Default;
127   - V when is_binary(V) -> binary_to_list(V)
  126 + undefined -> Default;
  127 + V when is_binary(V) -> binary_to_list(V)
128 128 end.
129 129
130 130 %% @doc Parse a file into a Torrent structure.
@@ -198,9 +198,9 @@ decode_dict_items(String, Accum) ->
198 198 prop_inv() ->
199 199 ?FORALL(BC, bcode(),
200 200 begin
201   - Enc = iolist_to_binary(encode(BC)),
202   - {ok, Dec} = decode(Enc),
203   - encode(BC) =:= encode(Dec)
  201 + Enc = iolist_to_binary(encode(BC)),
  202 + {ok, Dec} = decode(Enc),
  203 + encode(BC) =:= encode(Dec)
204 204 end).
205 205
206 206 eqc_test() ->
257 apps/etorrent/src/etorrent_tracker_communication.erl
@@ -47,16 +47,16 @@
47 47 %% information. The `ControlPid' refers to the Pid of the controller
48 48 %% process. The `UrlTiers' are a list of lists of string() parameters,
49 49 %% each a URL. Next comes the `Infohash' as a binary(), the `PeerId'
50   -%% parameter and finally the `TorrentId': the identifier of the torrent.</p>
  50 +%% parameter and finally the `TorrentId': the identifier of the torrent.</p>
51 51 %% @end
52 52 %% @todo What module, precisely do the control pid come from?
53 53 -spec start_link(pid(), [tier()], binary(), binary(), integer()) ->
54   - ignore | {ok, pid()} | {error, term()}.
  54 + ignore | {ok, pid()} | {error, term()}.
55 55 start_link(ControlPid, UrlTiers, InfoHash, PeerId, TorrentId)
56 56 when is_binary(PeerId) ->
57 57 gen_server:start_link(?MODULE,
58 58 [ControlPid,
59   - UrlTiers, InfoHash, PeerId, TorrentId],
  59 + UrlTiers, InfoHash, PeerId, TorrentId],
60 60 []).
61 61
62 62 %% @doc Prod the tracker and tell it we completed to torrent
@@ -72,9 +72,10 @@ init([ControlPid, UrlTiers, InfoHash, PeerId, TorrentId]) ->
72 72 process_flag(trap_exit, true),
73 73 random:seed(now()),
74 74 HardRef = erlang:send_after(0, self(), hard_timeout),
75   - SoftRef = erlang:send_after(timer:seconds(?DEFAULT_CONNECTION_TIMEOUT_INTERVAL),
76   - self(),
77   - soft_timeout),
  75 + SoftRef = erlang:send_after(
  76 + timer:seconds(?DEFAULT_CONNECTION_TIMEOUT_INTERVAL),
  77 + self(),
  78 + soft_timeout),
78 79 Url = swap_urls(shuffle_tiers(UrlTiers)),
79 80 {ok, #state{control_pid = ControlPid,
80 81 torrent_id = TorrentId,
@@ -105,7 +106,7 @@ handle_cast(Msg, S) ->
105 106
106 107 %% @private
107 108 handle_info(hard_timeout,
108   - #state { queued_message = none } = S) ->
  109 + #state { queued_message = none } = S) ->
109 110 %% There is nothing to do with the hard_timer, just ignore this
110 111 {noreply, S#state { hard_timer = none }};
111 112 handle_info(hard_timeout, S) ->
@@ -139,10 +140,10 @@ contact_tracker(S) ->
139 140
140 141 contact_tracker(Event, #state { url = Tiers } = S) ->
141 142 case contact_tracker(Tiers, Event, S) of
142   - {none, NS} ->
143   - NS;
144   - {ok, NS} ->
145   - NS
  143 + {none, NS} ->
  144 + NS;
  145 + {ok, NS} ->
  146 + NS
146 147 end.
147 148
148 149 contact_tracker(Tiers, Event, S) ->
@@ -152,10 +153,10 @@ contact_tracker([], _Event, S, _Acc) ->
152 153 {none, handle_timeout(S)};
153 154 contact_tracker([Tier | NextTier], Event, S, Acc) ->
154 155 case contact_tracker_tier(Tier, Event, S) of
155   - {ok, NS, NewTier} ->
156   - {ok, NS#state { url = lists:reverse(Acc) ++ [NewTier | NextTier] }};
157   - none ->
158   - contact_tracker(NextTier, Event, S, [Tier | Acc])
  156 + {ok, NS, NewTier} ->
  157 + {ok, NS#state { url = lists:reverse(Acc) ++ [NewTier | NextTier] }};
  158 + none ->
  159 + contact_tracker(NextTier, Event, S, [Tier | Acc])
159 160 end.
160 161
161 162 contact_tracker_tier(Tier, S, Event) ->
@@ -165,35 +166,35 @@ contact_tracker_tier([], _Event, _S, _Acc) ->
165 166 none;
166 167 contact_tracker_tier([Url | Next], Event, S, Acc) ->
167 168 case
168   - case identify_url_type(Url) of
169   - http -> contact_tracker_http(Url, Event, S);
170   - {udp, IP, Port} -> contact_tracker_udp(Url, IP, Port, Event, S)
171   - end
  169 + case identify_url_type(Url) of
  170 + http -> contact_tracker_http(Url, Event, S);
  171 + {udp, IP, Port} -> contact_tracker_udp(Url, IP, Port, Event, S)
  172 + end
172 173 of
173   - {ok, NS} ->
174   - {ok, NS, [Url] ++ lists:reverse(Acc) ++ Next};
175   - error ->
176   - %% For private torrent (BEP 27), disconnect all peers coming
177   - %% from the tracker before switching to another one
178   - case etorrent_torrent:is_private(S#state.torrent_id) of
179   - true -> disconnect_tracker(Url);
180   - _ -> ok
181   - end,
182   - contact_tracker_tier(Next, Event, S, [Url | Acc])
  174 + {ok, NS} ->
  175 + {ok, NS, [Url] ++ lists:reverse(Acc) ++ Next};
  176 + error ->
  177 + %% For private torrent (BEP 27), disconnect all peers coming
  178 + %% from the tracker before switching to another one
  179 + case etorrent_torrent:is_private(S#state.torrent_id) of
  180 + true -> disconnect_tracker(Url);
  181 + _ -> ok
  182 + end,
  183 + contact_tracker_tier(Next, Event, S, [Url | Acc])
183 184 end.
184 185
185 186 identify_url_type(Url) ->
186 187 case etorrent_http_uri:parse(Url) of
187   - {S1, _UserInfo, Host, Port, _Path, _Query} ->
188   - case S1 of
189   - http ->
190   - http;
191   - udp ->
192   - {udp, Host, Port}
193   - end;
194   - {error, Reason} ->
195   - ?WARN([Reason, Url]),
196   - exit(identify_url_type)
  188 + {S1, _UserInfo, Host, Port, _Path, _Query} ->
  189 + case S1 of
  190 + http ->
  191 + http;
  192 + udp ->
  193 + {udp, Host, Port}
  194 + end;
  195 + {error, Reason} ->
  196 + ?WARN([Reason, Url]),
  197 + exit(identify_url_type)
197 198
198 199 end.
199 200
@@ -205,73 +206,76 @@ identify_url_type(Url) ->
205 206 -spec disconnect_tracker(string()) -> ok.
206 207 disconnect_tracker(Url) ->
207 208 F = fun(P) ->
208   - etorrent_peer_control:stop(P)
209   - end,
  209 + etorrent_peer_control:stop(P)
  210 + end,
210 211 etorrent_table:foreach_peer_of_tracker(Url, F),
211 212 ok.
212 213
213 214 contact_tracker_udp(Url, IP, Port, Event,
214   - #state { torrent_id = Id,
215   - info_hash = InfoHash,
216   - peer_id = PeerId } = S) ->
  215 + #state { torrent_id = Id,
  216 + info_hash = InfoHash,
  217 + peer_id = PeerId } = S) ->
217 218 {value, PL} = etorrent_torrent:lookup(Id),
218 219 Uploaded = proplists:get_value(uploaded, PL),
219 220 Downloaded = proplists:get_value(downloaded, PL),
220 221 Left = proplists:get_value(left, PL),
221 222 PropList = [{info_hash, InfoHash},
222   - {peer_id, PeerId},
223   - {up, Uploaded},
224   - {down, Downloaded},
225   - {left, Left},
226   - {port, Port},
227   - {key, 0}, %% @todo: Actually process the key correctly for private tracking
228   - {event, Event}],
  223 + {peer_id, PeerId},
  224 + {up, Uploaded},
  225 + {down, Downloaded},
  226 + {left, Left},
  227 + {port, Port},
  228 + %% @todo: Actually process the key correctly for
  229 + %% private tracking
  230 + {key, 0},
  231 + {event, Event}],
229 232 ?INFO([announcing_via_udp]),
230   - case etorrent_udp_tracker_mgr:announce({IP, Port}, PropList, timer:seconds(60)) of
231   - {ok, {announce, Peers, Status}} ->
232   - ?INFO([udp_reply_handled]),
233   - {I, MI} = handle_udp_response(Url, Id, Peers, Status),
234   - {ok, handle_timeout(I, MI, S)};
235   - timeout ->
236   - error
  233 + case etorrent_udp_tracker_mgr:announce(
  234 + {IP, Port}, PropList, timer:seconds(60)) of
  235 + {ok, {announce, Peers, Status}} ->
  236 + ?INFO([udp_reply_handled]),
  237 + {I, MI} = handle_udp_response(Url, Id, Peers, Status),
  238 + {ok, handle_timeout(I, MI, S)};
  239 + timeout ->
  240 + error
237 241 end.
238 242
239 243 %% @todo: consider not passing around the state here!
240 244 contact_tracker_http(Url, Event, S) ->
241 245 RequestUrl = build_tracker_url(Url, Event, S),
242 246 case etorrent_http:request(RequestUrl) of
243   - {ok, {{200, _}, _, Body}} ->
244   - case etorrent_bcoding:decode(Body) of
245   - {ok, BC} -> {ok, handle_tracker_response(Url, BC, S)};
246   - {error, _} ->
247   - etorrent_event:notify({malformed_tracker_response, Body}),
  247 + {ok, {{200, _}, _, Body}} ->
  248 + case etorrent_bcoding:decode(Body) of
  249 + {ok, BC} -> {ok, handle_tracker_response(Url, BC, S)};
  250 + {error, _} ->
  251 + etorrent_event:notify({malformed_tracker_response, Body}),
  252 + error
  253 + end;
  254 + {error, Type} ->
  255 + case Type of
  256 + etimedout -> ignore;
  257 + econnrefused -> ignore;
  258 + session_remotly_closed -> ignore;
  259 + Err ->
  260 + Msg = {error, [{contact_tracker, Err},
  261 + {id, S#state.torrent_id}]},
  262 + etorrent_event:notify(Msg),
  263 + ?INFO([Msg]),
  264 + ignore
  265 + end,
248 266 error
249   - end;
250   - {error, Type} ->
251   - case Type of
252   - etimedout -> ignore;
253   - econnrefused -> ignore;
254   - session_remotly_closed -> ignore;
255   - Err ->
256   - Msg = {error, [{contact_tracker, Err},
257   - {id, S#state.torrent_id}]},
258   - etorrent_event:notify(Msg),
259   - ?INFO([Msg]),
260   - ignore
261   - end,
262   - error
263 267 end.
264 268
265 269 handle_tracker_response(Url, BC, S) ->
266 270 case etorrent_bcoding:get_string_value("failure reason", BC, none) of
267   - none ->
268   - report_warning(
269   - S#state.torrent_id,
270   - etorrent_bcoding:get_string_value("warning message", BC, none)),
271   - handle_tracker_bcoding(Url, BC, S);
272   - Err ->
273   - etorrent_event:notify({tracker_error, S#state.torrent_id, Err}),
274   - handle_timeout(BC, S)
  271 + none ->
  272 + report_warning(
  273 + S#state.torrent_id,
  274 + etorrent_bcoding:get_string_value("warning message", BC, none)),
  275 + handle_tracker_bcoding(Url, BC, S);
  276 + Err ->
  277 + etorrent_event:notify({tracker_error, S#state.torrent_id, Err}),
  278 + handle_timeout(BC, S)
275 279 end.
276 280
277 281 report_warning(_Id, none) -> ok;
@@ -285,20 +289,21 @@ handle_tracker_bcoding(Url, BC, S) ->
285 289 response_ips(BC)),
286 290 %% Update the state of the torrent
287 291 ok = etorrent_torrent:statechange(
288   - S#state.torrent_id,
289   - [{tracker_report,
290   - etorrent_bcoding:get_value("complete", BC, 0),
291   - etorrent_bcoding:get_value("incomplete", BC, 0)}]),
  292 + S#state.torrent_id,
  293 + [{tracker_report,
  294 + etorrent_bcoding:get_value("complete", BC, 0),
  295 + etorrent_bcoding:get_value("incomplete", BC, 0)}]),
292 296 %% Timeout
293 297 handle_timeout(BC, S).
294 298
295 299 handle_udp_response(Url, Id, Peers, Status) ->
296 300 etorrent_peer_mgr:add_peers(Url, Id, Peers),
297 301 etorrent_torrent:statechange(Id,
298   - [{tracker_report,
299   - proplists:get_value(seeders, Status, 0),
300   - proplists:get_value(leechers, Status, 0)}]),
301   - {proplists:get_value(interval, Status), ?DEFAULT_CONNECTION_TIMEOUT_MIN_INTERVAL}.
  302 + [{tracker_report,
  303 + proplists:get_value(seeders, Status, 0),
  304 + proplists:get_value(leechers, Status, 0)}]),
  305 + {proplists:get_value(interval, Status),
  306 + ?DEFAULT_CONNECTION_TIMEOUT_MIN_INTERVAL}.
302 307
303 308 handle_timeout(S) ->
304 309 Interval = ?DEFAULT_CONNECTION_TIMEOUT_INTERVAL,
@@ -306,7 +311,8 @@ handle_timeout(S) ->
306 311 handle_timeout(Interval, MinInterval, S).
307 312
308 313 handle_timeout(BC, S) ->
309   - Interval = etorrent_bcoding:get_value("interval", BC, ?DEFAULT_REQUEST_TIMEOUT),
  314 + Interval =
  315 + etorrent_bcoding:get_value("interval", BC, ?DEFAULT_REQUEST_TIMEOUT),
310 316 MinInterval = etorrent_bcoding:get_value("min interval", BC, none),
311 317 handle_timeout(Interval, MinInterval, S).
312 318
@@ -325,9 +331,9 @@ cancel_timer(none) -> ok;
325 331 cancel_timer(TRef) -> erlang:cancel_timer(TRef).
326 332
327 333 build_tracker_url(Url, Event,
328   - #state { torrent_id = Id,
329   - info_hash = InfoHash,
330   - peer_id = PeerId }) ->
  334 + #state { torrent_id = Id,
  335 + info_hash = InfoHash,
  336 + peer_id = PeerId }) ->
331 337 {value, PL} = etorrent_torrent:lookup(Id),
332 338 Uploaded = proplists:get_value(uploaded, PL),
333 339 Downloaded = proplists:get_value(downloaded, PL),
@@ -349,24 +355,22 @@ build_tracker_url(Url, Event,
349 355 completed -> [{"event", "completed"} | Request]
350 356 end,
351 357
352   - % Url can already has `?'.
353   - % For example,
354   - % /announce.php?passkey=43c08a5dd9e70a19f62adfd0ad76dw04
355   - FlatUrl = lists:flatten(Url),
356   - Delim = case lists:member($?, FlatUrl) of
357   - true -> "&";
358   - false -> "?"
359   - end,
360   -
361   - lists:concat([Url, Delim, etorrent_http:mk_header(EReq)]).
362   -
  358 + %% Url can already has `?'.
  359 + %% For example,
  360 + %% /announce.php?passkey=43c08a5dd9e70a19f62adfd0ad76dw04
  361 + FlatUrl = lists:flatten(Url),
  362 + Delim = case lists:member($?, FlatUrl) of
  363 + true -> "&";
  364 + false -> "?"
  365 + end,
363 366
  367 + lists:concat([Url, Delim, etorrent_http:mk_header(EReq)]).
364 368
365 369 %%% Tracker response lookup functions
366 370 response_ips(BC) ->
367 371 case etorrent_bcoding:get_value("peers", BC, none) of
368   - none -> [];
369   - IPs -> etorrent_utils:decode_ips(IPs)
  372 + none -> [];
  373 + IPs -> etorrent_utils:decode_ips(IPs)
370 374 end.
371 375
372 376
@@ -396,14 +400,15 @@ swap([Url | R]) ->
396 400 swap_in_tier(Url, [], Acc) -> {Url, lists:reverse(Acc)};
397 401 swap_in_tier(Url, [H | T], Acc) ->
398 402 case should_swap_for(Url, H) of
399   - true ->
400   - {H, lists:reverse(Acc) ++ [Url | T]};
401   - false ->
402   - swap_in_tier(Url, T, [H | Acc])
  403 + true ->
  404 + {H, lists:reverse(Acc) ++ [Url | T]};
  405 + false ->
  406 + swap_in_tier(Url, T, [H | Acc])
403 407 end.
404 408
405 409 should_swap_for(Url1, Url2) ->
406   - {S1, _UserInfo, Host1, _Port, _Path, _Query} = etorrent_http_uri:parse(Url1),
  410 + {S1, _UserInfo, Host1, _Port, _Path, _Query} =
  411 + etorrent_http_uri:parse(Url1),
407 412 {_S2, _, Host2, _, _, _} = etorrent_http_uri:parse(Url2),
408 413 Host1 == Host2 andalso S1 == http.
409 414
@@ -422,19 +427,21 @@ splice_test() ->
422 427 swap_test() ->
423 428 Swapped = swap(lists:concat(tier())),
424 429 ?assertEqual(["udp://one.com", "udp://two.com", "http://one.com",
425   - "udp://four.com", "http://two.com", "http://three.com"],
426   - Swapped).
  430 + "udp://four.com", "http://two.com", "http://three.com"],
  431 + Swapped).
427 432
428 433 swap_urls_test() ->
429 434 Swapped = swap_urls(tier()),
430 435 ?assertEqual([["udp://one.com", "udp://two.com", "http://one.com"],
431   - ["udp://four.com", "http://two.com", "http://three.com"]],
432   - Swapped).
  436 + ["udp://four.com", "http://two.com", "http://three.com"]],
  437 + Swapped).
433 438
434 439 should_swap_test() ->
435 440 ?assertEqual(true, should_swap_for("http://foo.com", "udp://foo.com")),
436 441 ?assertEqual(false, should_swap_for("http://foo.com", "udp://bar.com")),
437   - ?assertEqual(true, should_swap_for("http://foo.com", "udp://foo.com/something/more")).
  442 + ?assertEqual(true,
  443 + should_swap_for("http://foo.com",
  444 + "udp://foo.com/something/more")).
438 445
439 446 -ifdef(PROPER).
440 447
@@ -444,17 +451,17 @@ host() -> oneof(["one.com", "two.com", "three.com", "four.com", "five.com"]).
444 451
445 452 url() ->
446 453 ?LET({Scheme, Host}, {scheme(), host()},
447   - atom_to_list(Scheme) ++ "://" ++ Host).
  454 + atom_to_list(Scheme) ++ "://" ++ Host).
448 455
449 456 g_tier() -> list(url()).
450 457 g_tiers() -> list(g_tier()).
451 458
452 459 prop_splice_unsplice_inv() ->
453 460 ?FORALL(In, g_tiers(),
454   - begin
455   - {K, Spliced} = splice(In),
456   - In =:= unsplice(K, Spliced)
457   - end).
  461 + begin
  462 + {K, Spliced} = splice(In),
  463 + In =:= unsplice(K, Spliced)
  464 + end).
458 465
459 466 eqc_test() ->
460 467 ?assert(proper:quickcheck(prop_splice_unsplice_inv())).

0 comments on commit 88febcc

Please sign in to comment.
Something went wrong with that request. Please try again.