What I do for the OOM handler in this PR is that I clear the cache with purge_expired_resolves() with now as the current time, and increase the interval by an hour until either we cleared enough memory or there are no more entries.
My question is, what is that argument going to be called? If there is no name yet, should I create it?
If I have to make something, I am thinking about something like: OOMHandlerClearOnlyDNS (0/1) where 0 is the default (run all OOM checks) and 1 is to only run OOM on DNS (if you're an exit).
UPDATE: Also, should I allow this option for all relays or only exits?
If I have to make something, I am thinking about something like: OOMHandlerClearOnlyDNS (0/1) where 0 is the default (run all OOM checks) and 1 is to only run OOM on DNS (if you're an exit).
Wait no, no need for that at all. What I was saying is that we should only run that OOM handler in the case tor is running as an Exit and one way to look at that is with ExitRelay 1 global option ;).
If I have to make something, I am thinking about something like: OOMHandlerClearOnlyDNS (0/1) where 0 is the default (run all OOM checks) and 1 is to only run OOM on DNS (if you're an exit).
Wait no, no need for that at all. What I was saying is that we should only run that OOM handler in the case tor is running as an Exit and one way to look at that is with ExitRelay 1 global option ;).
That's not how ExitRelay works:
ExitRelay 0|1|autoTells Tor whether to run as an exit relay. If Tor is running as a non-bridge server, and ExitRelay is set to 1, then Tor allows traffic to exit according to the ExitPolicy option (or the default ExitPolicy if none is specified).If ExitRelay is set to 0, no traffic is allowed to exit, and the ExitPolicy option is ignored.If ExitRelay is set to "auto", then Tor behaves as if it were set to 1, but warns the user if this would cause traffic to exit. In a future version, the default value will be 0. (Default: auto)
smartlist_t *exit_policy = router_get_my_routerinfo()->exit_policy;if (!policy_is_reject_star(exit_policy, AF_INET) || !policy_is_reject_star(exit_policy, AF_INET6)) { /* Run the OOM handler on DNS */}
But that won't handle OOM when the operator has turned exiting off, but used to have it on. So instead, maybe we should:
always run the OOM handler on DNS
check the approximate size of the DNS cache before running the OOM handler on it, or
set a flag when we run the OOM handler and we're not an exit, then clear the flag when we become an exit.
True, ExitRelay won't work. I'm also not very enthusiastic on using policy_is_reject_star() which possibly goes over the entire policy just to learn if we are an Exit relay with a non reject policy.
The Roles we've added recently for the callbacks in tor should be what we look at imo, but we don't have one for the Exit just yet (legacy/trac#25899 (moved)).
So for now, lets always run it, checking the HT size is very cheap and the OOM is only triggered on memory pressure so shouldn't be that often in most cases.
Sorry neel, the PR looks good, just remove the ExitRelay condition :P. Thanks!