Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ config :extracker,
reverse_proxy_address: "",
http_request_timeout: 60_000,
integration: "none",
fake_peers_in_responses: 0,
debug: true

config :logger,
Expand Down
1 change: 1 addition & 0 deletions config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ config :extracker,
reverse_proxy_address: "",
http_request_timeout: 60_000,
integration: "none",
fake_peers_in_responses: 0,
debug: false

config :logger,
Expand Down
1 change: 1 addition & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ if config_env() in [:prod] do
reverse_proxy_address: "", # specify the address of a reverse proxy if present (caddy, nginx, apache, etc)
http_request_timeout: 60_000, # time before *outgoing* http requests timeout (mainly for integrations)
integration: "none", # select which integration (if any) to be enabled (current options: "arcadia", "none")
fake_peers_in_responses: 0, # amount of fake peers to inject in the responses (prevent mass scraping of torrent peer lists), a recommended value is 3
debug: false # enable extra debug logs and checks

config :logger, level: :notice # log minimum level. info and debug may get spammy
Expand Down
1 change: 1 addition & 0 deletions config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ config :extracker,
reverse_proxy_address: "",
http_request_timeout: 60_000,
integration: "none",
fake_peers_in_responses: 0,
debug: false

config :logger,
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ services:
# - EXTRACKER_REVERSE_PROXY_ADDRESS=
# - EXTRACKER_HTTP_REQUEST_TIMEOUT=
# - EXTRACKER_INTEGRATION=
# - EXTRACKER_FAKE_PEERS_IN_RESPONSES=
# - EXTRACKER_DEBUG=false
# - EXTRACKER_ARCADIA_API_BIND_ADDRESS=
# - EXTRACKER_ARCADIA_API_PORT=
Expand Down
35 changes: 33 additions & 2 deletions lib/ex_tracker/swarm.ex
Original file line number Diff line number Diff line change
Expand Up @@ -245,18 +245,49 @@ defmodule ExTracker.Swarm do
# convert the IDs back to the normal type
case include_data do
false ->
Enum.map(result, &PeerID.from_storage/1)
result
|> Enum.map(&PeerID.from_storage/1)
|> add_fake_peers(family, include_data)
true ->
Enum.map(result, fn {sid, data} -> {PeerID.from_storage(sid), data} end)
end

rescue
# the swarm table may be gone while the query reaches this point
e in ArgumentError ->
Logger.debug("get_peers/5: #{Exception.message(e)}")
[]
end
end

def add_fake_peers(peers, :inet, false) do
case Application.get_env(:extracker, :fake_peers_in_responses, 0) do
amount when amount > 0 ->
fake_peers = for _ <- 1..amount do
{a, b, c, d} = {:rand.uniform(255), :rand.uniform(255), :rand.uniform(255), :rand.uniform(255)}
port = :rand.uniform(65535)
PeerID.new({a, b, c, d}, port)
end
peers ++ fake_peers
_ -> peers
end
end

def add_fake_peers(peers, :inet6, false) do
case Application.get_env(:extracker, :fake_peers_in_responses, 0) do
amount when amount > 0 ->
fake_peers = for _ <- 1..amount do
ip = {:rand.uniform(65535), :rand.uniform(65535), :rand.uniform(65535), :rand.uniform(65535),
:rand.uniform(65535), :rand.uniform(65535), :rand.uniform(65535), :rand.uniform(65535)}
port = :rand.uniform(65535)
PeerID.new(ip, port)
end
peers ++ fake_peers
_ -> peers
end
end

def add_fake_peers(peers, :all, _), do: peers

def get_all_peers(swarm, include_data) do
get_peers(swarm, :all, :all, :all, include_data)
Expand Down
Loading