Suggestions to simplify Session management #5
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:
Clone
andCopy
derive 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.