Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Peer Diversity for Routing Table and Querying #88

Merged
merged 9 commits into from
Jun 3, 2020

Conversation

aarshkshah1992
Copy link
Contributor

@aarshkshah1992 aarshkshah1992 commented Jun 1, 2020

Implementation of the filter for Routing Table Diversity.

Copy link
Contributor

@aschmahmann aschmahmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of comments, let me know what you think. The comments are spread between both PRs, so you may want to take a look through both before doing a response review (I've gone back and corrected myself a few times as I've been going through the review).

Thought: Would it make sense to have the filter live in the DHT? It seems like the only thing that the routing table actually needs access to is something that implements the interface TryAdd(peer.ID) bool and Remove(peer.ID). That would mean we could touch the code in this repo less so we have fewer of these two repo PRs.

peerdiversity/filter.go Outdated Show resolved Hide resolved
peerdiversity/filter.go Outdated Show resolved Hide resolved
peerdiversity/filter.go Outdated Show resolved Hide resolved
peerdiversity/filter.go Outdated Show resolved Hide resolved
peerdiversity/filter.go Outdated Show resolved Hide resolved
bls: cidranger.NewPCTrieRanger(),
legacyCidrs: legacyCidrs,
logKey: appName,
cplFnc: cplFnc,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems bizarre that the "default" cpl implementation needs to be passed in externally like func (p peer.ID) int {return kb.CommonPrefixLen(dht.selfKey, kb.ConvertPeerID(p))} instead of just being included in the default object. What was the idea here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason is to not have a dependency on the kbucket package.

I'll fix this if we move this to the DHT package.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so trying to avoid circular dependencies? This will likely cause problems even in the DHT package (RT still needs Filter and Filter still needs RT). However, if the RT takes an interface this goes away.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed offline, let's punt this for now and we can pay this tech debt later if required.

table.go Show resolved Hide resolved
Comment on lines +231 to +233
// WhitelistIPNetwork will always allow IP addresses from networks with the given CIDR.
// This will always override the blacklist.
func (f *Filter) WhitelistIPNetwork(cidr string) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible that we'd want to whitelist more than just domain ranges (e.g. peers I've been well connected to for more than a month are exempted whitelisted no matter their IP address). If we were passing an interface instead of a struct into NewRoutingTable I could just make a new filter with additional whitelist criteria, but if we're only going to have one implmentation then it should be more flexible (e.g. AddWhitelist(func(p peer.ID) bool).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aschmahmann I don't see the point of having a Filter interface for now as we really only have one implementation. Let's just wait till this evolves to create it ?

Have added a WhiteListPeerIds function for now and a test to go with it. We can even have an interface just for the WhiteListing stuff and inject it into the Filter later on if this functionality evolves more.

}
group := PeerGroupInfo{Id: p, Cpl: cpl, IPGroupKey: key}

if rs, _ := f.wls.ContainingNetworks(ip); len(rs) != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the example use cases for whitelists? I'm wondering if peers that are whitelisted should count as 0 across the board instead of just getting an approval. For example, peer A is part of groups 1 + 2 and is whitelisted, while peer B is part of group 1 only. If we add B and then A they will both make it into the table, but if we add A and then B it's possible B might not make it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aschmahmann

One example use case right now is whitelisting all the private IP address (I'm still figuring out how that'd work). Once we figure out the long lived peers logic, we might want to whitelist their peer Ids as well.

Also, I agree with you. I don't think whitelisted peers should take up slots/tickets. I've changed the code accordingly and added a test for it. Let me know what you think.

Comment on lines +168 to +170
// add it to the diversity filter for now.
// if we aren't able to find a place for the peer in the table,
// we will simply remove it from the Filter later.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This is a little awkward, especially since we can fix this by checking the diversity filter after we check if there's room instead of the other way around. This doesn't seem like it's necessarily a big deal though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this is a bit awkward. I think I just didn't feel like calling filter.Add at multiple places here.

@aarshkshah1992
Copy link
Contributor Author

@aschmahmann I believe I've replied to all your comments on this PR. Please take a look and let me know what you think.

@aarshkshah1992 aarshkshah1992 merged commit 86c2b9a into master Jun 3, 2020
@aarshkshah1992 aarshkshah1992 deleted the feat/ip-filtering branch June 3, 2020 17:12
@aschmahmann aschmahmann mentioned this pull request Sep 22, 2020
72 tasks
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.

3 participants