Suggestions to simplify Session management#5
Merged
emhane merged 3 commits intoemhane:nat-hole-punch-discv5.2from Jan 17, 2024
Merged
Suggestions to simplify Session management#5emhane merged 3 commits intoemhane:nat-hole-punch-discv5.2from
emhane merged 3 commits intoemhane:nat-hole-punch-discv5.2from
Conversation
103e73d to
1dc77cf
Compare
1dc77cf to
2ecc61f
Compare
emhane
reviewed
Jan 15, 2024
src/handler/mod.rs
Outdated
|
|
||
| // Decide whether to establish this connection based on our apettiite for unreachable | ||
| if enr_not_reachable | ||
| && Some(self.sessions.tagged()) > self.nat_utils.unreachable_enr_limit |
Owner
There was a problem hiding this comment.
Suggested change
| && Some(self.sessions.tagged()) > self.nat_utils.unreachable_enr_limit | |
| && Some(self.sessions.tagged() + 1) > self.nat_utils.unreachable_enr_limit |
emhane
reviewed
Jan 15, 2024
emhane
reviewed
Jan 15, 2024
emhane
requested changes
Jan 15, 2024
Owner
emhane
left a comment
There was a problem hiding this comment.
lgtm, not so good to clippy. left a some suggestions, if you commit those I'm happy with it.
jxs
reviewed
Jan 15, 2024
| } | ||
| /// Determines if an ENR is reachable or not based on its assigned keys. | ||
| pub fn is_enr_reachable(enr: &Enr) -> bool { | ||
| enr.udp4_socket().is_some() || enr.udp6_socket().is_some() |
There was a problem hiding this comment.
nit:
Suggested change
| enr.udp4_socket().is_some() || enr.udp6_socket().is_some() | |
| enr.udp4_socket().or(enr.udp6_socket()).is_some() |
Author
There was a problem hiding this comment.
Dont think we can do this, because the types are different. SocketAddrv4 vs SocketAddrv6
Author
|
Ok. I think i've addressed everything here. Will continue with the main review :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I've made some changes which I think solve some bugs, simplify the code and make the diff smaller.
The main part of it was moving unreachable enr tracking to inside the LRUTimeCache in a generic way, by adding the concept of tagging. Elements can be optionally tagged when inserted into the cache. If we need to know how many tagged elements are in there we can just go like
cache.tagged().This allows us to easily track the number of unreachable sessions, just by checking tagged. There are a number of reasons why I think this is an improvement:
get_mut()orlen()on the cache was called. So elements could expire (time-wise) but the task will not get awoken until either of these functions are called. More importantly, the channel does not get populated whenremove()is called. So in the NATHolePuncher tracking case, these were not being registered. I replaced this logic with a HashSetDelay, because it seemed we only cared about when elements were expiring. This is a true async struct and will fire exactly when things expire.remove()function, they were not being counted as being removed from the tracker. I duplicated this logic in the nat_hole_puncher_tracker with a delay hashmap.In addition a few more changes I made:
CloneandCopyderive from Session and Keys. These are private keys and we don't want to copy them in memory for security reasons. For private keys, we try to keep one point in memory to store them and we zeroize that memory when it goes out of scope. I think the copy and clone were only needed for tests, from what I can tell.I think I have replicated all the logic however. If there's a mismatch let me know.