Skip to content

Conversation

@FrenchGithubUser
Copy link
Contributor

@FrenchGithubUser FrenchGithubUser commented Sep 13, 2025

I directly added a block in get_peers(), it seemed to make more sense to me.

This is my first time writing some elixir, let me know if there's anything to change!

Closes #3

@FrenchGithubUser FrenchGithubUser marked this pull request as draft September 13, 2025 13:26
@FrenchGithubUser FrenchGithubUser changed the title add fake peer injection mechanism, closes #7 add fake peer injection mechanism, closes #3 Sep 13, 2025
@FrenchGithubUser FrenchGithubUser changed the title add fake peer injection mechanism, closes #3 add fake peer injection mechanism Sep 13, 2025
@Dahrkael
Copy link
Owner

good start but that doesnt work at it is.
if we wanna handle only compact responses (to avoid having to fake peer ids and things like that too) the block should go into the previous case (line 248) when include_data is false.
you are generating peers in Storage format but at that point they have to be of type PeerID (check types/peer_id.ex for the constructor).
you also need to account if the function is returning ipv4 or ipv6 peers (or both) based on the family parameter. if family is :all we most likely are doing internal stuff and dont need to add fake ones.

I'd say create a new set of functions based on the signature:
add_fake_peers(peers, family, include_data) :: list()

which means adding the ones we want right now:
def add_fake_peers(peers, :inet, false) # add fake ipv4 peers without data
def add_fake_peers(peers, :inet6, false) # add fake ipv6 peers without data
def add_fake_peers(peers, :all, _), do: peers # do nothing

and then pipe the list of real peers through it

@FrenchGithubUser
Copy link
Contributor Author

Thanks for your review! Hopefully it's better with this new commit!

@Dahrkael
Copy link
Owner

much better! this should be enough but if you want to give it the last twist I'd say get rid of the if else, which is not very common in elixir and directly match the config variable with a case:

case Application.get_env(:extracker, :fake_peers_in_responses, 0) do
amount when amount > 0 ->
fake_peers = for _ <- 1..fake_peers_amount do
....
_ -> peers
end

@FrenchGithubUser FrenchGithubUser marked this pull request as ready for review September 15, 2025 08:14
@FrenchGithubUser
Copy link
Contributor Author

There you go :) I hope that the code formatting is good as well!

@Dahrkael Dahrkael merged commit b4d1cc4 into Dahrkael:master Sep 15, 2025
4 checks passed
@Dahrkael
Copy link
Owner

all good, in it goes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Privacy Feature Fake Peer Injection

2 participants