p2p: allow NetPermissions::ClearFlag() only with PF_ISIMPLICIT

NetPermissions::ClearFlag() is currently only called in the codebase with
an `f` value of NetPermissionFlags::PF_ISIMPLICIT.

If that should change in the future, ClearFlag() should not be called
with `f` being a subflag of a multiflag, e.g. NetPermissionFlags::PF_RELAY
or NetPermissionFlags::PF_DOWNLOAD, as that would leave `flags` in an
invalid state corresponding to none of the existing NetPermissionFlags.

Therefore, allow only calling ClearFlag with the implicit flag for now.

Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
This commit is contained in:
Jon Atack
2021-04-14 17:10:28 +02:00
parent 4e0d5788ba
commit 36fb036d25
2 changed files with 8 additions and 2 deletions

View File

@@ -51,8 +51,14 @@ public:
{
flags = static_cast<NetPermissionFlags>(flags | f);
}
//! ClearFlag is only called with `f` == NetPermissionFlags::PF_ISIMPLICIT.
//! If that should change in the future, be aware that ClearFlag should not
//! be called with a subflag of a multiflag, e.g. NetPermissionFlags::PF_RELAY
//! or NetPermissionFlags::PF_DOWNLOAD, as that would leave `flags` in an
//! invalid state corresponding to none of the existing flags.
static inline void ClearFlag(NetPermissionFlags& flags, NetPermissionFlags f)
{
assert(f == NetPermissionFlags::PF_ISIMPLICIT);
flags = static_cast<NetPermissionFlags>(flags & ~f);
}
};