After looking at #16248 and #19191, the current code seems correct.
This line was changed in e5b26deaaa6, which pre-dates the download permission being extracted from noban in #19191:
0- if (addrBind.IsRoutable() && fDiscover && !fWhitelisted)
1+ if (addrBind.IsRoutable() && fDiscover && (permissions & PF_NOBAN) == 0)
The intent of adding the Download flag in #19191 was: “It should be possible to grant nodes in a local network (e.g. home, university, enterprise, …) permission to download blocks even after the maxuploadtarget is hit. Currently this is only possible by setting the noban permission, which has some adverse effects, especially if the peers can’t be fully trusted. Fix this by extracting a download permission from noban.”
So, in reply to your questions:
-
(If I understand correctly) the existing lone bitwise AND here, e.g. HasAnyFlag(Noban)
is correct (but the precise behavior is not covered by tests)
-
I guess we could replace HasAnyFlag(Noban)
with the more verbose HasFlag(Noban) || HasFlag(Download)
if that seems clearer
-
Elsewhere, HasFlag()
appears to be what we want in the cases where it is used, AFAICT