Skip to content

Commit a95540c

Browse files
committed
scripted-diff: rename NetPermissionFlags enumerators
- drop redundant PF_ permission flags prefixes - drop ALL_CAPS naming per https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Renum-caps - rename IsImplicit to Implicit -BEGIN VERIFY SCRIPT- s() { git grep -l "$1" src | xargs sed -i "s/$1/$2/g"; } s 'PF_NONE' 'None' s 'PF_BLOOMFILTER' 'BloomFilter' s 'PF_RELAY' 'Relay' s 'PF_FORCERELAY' 'ForceRelay' s 'PF_DOWNLOAD' 'Download' s 'PF_NOBAN' 'NoBan' s 'PF_MEMPOOL' 'Mempool' s 'PF_ADDR' 'Addr' s 'PF_ISIMPLICIT' 'Implicit' s 'PF_ALL' 'All' -END VERIFY SCRIPT-
1 parent 810d092 commit a95540c

File tree

9 files changed

+108
-108
lines changed

9 files changed

+108
-108
lines changed

src/net.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ bool CConnman::AttemptToEvictConnection()
10051005

10061006
LOCK(cs_vNodes);
10071007
for (const CNode* node : vNodes) {
1008-
if (node->HasPermission(NetPermissionFlags::PF_NOBAN))
1008+
if (node->HasPermission(NetPermissionFlags::NoBan))
10091009
continue;
10101010
if (!node->IsInboundConn())
10111011
continue;
@@ -1062,7 +1062,7 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
10621062

10631063
const CAddress addr_bind = GetBindAddress(hSocket);
10641064

1065-
NetPermissionFlags permissionFlags = NetPermissionFlags::PF_NONE;
1065+
NetPermissionFlags permissionFlags = NetPermissionFlags::None;
10661066
hListenSocket.AddSocketPermissionFlags(permissionFlags);
10671067

10681068
CreateNodeFromAcceptedSocket(hSocket, permissionFlags, addr_bind, addr);
@@ -1077,12 +1077,12 @@ void CConnman::CreateNodeFromAcceptedSocket(SOCKET hSocket,
10771077
int nMaxInbound = nMaxConnections - m_max_outbound;
10781078

10791079
AddWhitelistPermissionFlags(permissionFlags, addr);
1080-
if (NetPermissions::HasFlag(permissionFlags, NetPermissionFlags::PF_ISIMPLICIT)) {
1081-
NetPermissions::ClearFlag(permissionFlags, NetPermissionFlags::PF_ISIMPLICIT);
1082-
if (gArgs.GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY)) NetPermissions::AddFlag(permissionFlags, NetPermissionFlags::PF_FORCERELAY);
1083-
if (gArgs.GetBoolArg("-whitelistrelay", DEFAULT_WHITELISTRELAY)) NetPermissions::AddFlag(permissionFlags, NetPermissionFlags::PF_RELAY);
1084-
NetPermissions::AddFlag(permissionFlags, NetPermissionFlags::PF_MEMPOOL);
1085-
NetPermissions::AddFlag(permissionFlags, NetPermissionFlags::PF_NOBAN);
1080+
if (NetPermissions::HasFlag(permissionFlags, NetPermissionFlags::Implicit)) {
1081+
NetPermissions::ClearFlag(permissionFlags, NetPermissionFlags::Implicit);
1082+
if (gArgs.GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY)) NetPermissions::AddFlag(permissionFlags, NetPermissionFlags::ForceRelay);
1083+
if (gArgs.GetBoolArg("-whitelistrelay", DEFAULT_WHITELISTRELAY)) NetPermissions::AddFlag(permissionFlags, NetPermissionFlags::Relay);
1084+
NetPermissions::AddFlag(permissionFlags, NetPermissionFlags::Mempool);
1085+
NetPermissions::AddFlag(permissionFlags, NetPermissionFlags::NoBan);
10861086
}
10871087

10881088
{
@@ -1111,7 +1111,7 @@ void CConnman::CreateNodeFromAcceptedSocket(SOCKET hSocket,
11111111

11121112
// Don't accept connections from banned peers.
11131113
bool banned = m_banman && m_banman->IsBanned(addr);
1114-
if (!NetPermissions::HasFlag(permissionFlags, NetPermissionFlags::PF_NOBAN) && banned)
1114+
if (!NetPermissions::HasFlag(permissionFlags, NetPermissionFlags::NoBan) && banned)
11151115
{
11161116
LogPrint(BCLog::NET, "connection from %s dropped (banned)\n", addr.ToString());
11171117
CloseSocket(hSocket);
@@ -1120,7 +1120,7 @@ void CConnman::CreateNodeFromAcceptedSocket(SOCKET hSocket,
11201120

11211121
// Only accept connections from discouraged peers if our inbound slots aren't (almost) full.
11221122
bool discouraged = m_banman && m_banman->IsDiscouraged(addr);
1123-
if (!NetPermissions::HasFlag(permissionFlags, NetPermissionFlags::PF_NOBAN) && nInbound + 1 >= nMaxInbound && discouraged)
1123+
if (!NetPermissions::HasFlag(permissionFlags, NetPermissionFlags::NoBan) && nInbound + 1 >= nMaxInbound && discouraged)
11241124
{
11251125
LogPrint(BCLog::NET, "connection from %s dropped (discouraged)\n", addr.ToString());
11261126
CloseSocket(hSocket);
@@ -1141,7 +1141,7 @@ void CConnman::CreateNodeFromAcceptedSocket(SOCKET hSocket,
11411141
uint64_t nonce = GetDeterministicRandomizer(RANDOMIZER_ID_LOCALHOSTNONCE).Write(id).Finalize();
11421142

11431143
ServiceFlags nodeServices = nLocalServices;
1144-
if (NetPermissions::HasFlag(permissionFlags, NetPermissionFlags::PF_BLOOMFILTER)) {
1144+
if (NetPermissions::HasFlag(permissionFlags, NetPermissionFlags::BloomFilter)) {
11451145
nodeServices = static_cast<ServiceFlags>(nodeServices | NODE_BLOOM);
11461146
}
11471147

@@ -2253,7 +2253,7 @@ void CConnman::ThreadI2PAcceptIncoming()
22532253
continue;
22542254
}
22552255

2256-
CreateNodeFromAcceptedSocket(conn.sock->Release(), NetPermissionFlags::PF_NONE,
2256+
CreateNodeFromAcceptedSocket(conn.sock->Release(), NetPermissionFlags::None,
22572257
CAddress{conn.me, NODE_NONE}, CAddress{conn.peer, NODE_NONE});
22582258
}
22592259
}
@@ -2411,7 +2411,7 @@ bool CConnman::Bind(const CService &addr, unsigned int flags, NetPermissionFlags
24112411
return false;
24122412
}
24132413

2414-
if (addr.IsRoutable() && fDiscover && !(flags & BF_DONT_ADVERTISE) && !NetPermissions::HasFlag(permissions, NetPermissionFlags::PF_NOBAN)) {
2414+
if (addr.IsRoutable() && fDiscover && !(flags & BF_DONT_ADVERTISE) && !NetPermissions::HasFlag(permissions, NetPermissionFlags::NoBan)) {
24152415
AddLocal(addr, LOCAL_BIND);
24162416
}
24172417

@@ -2425,7 +2425,7 @@ bool CConnman::InitBinds(
24252425
{
24262426
bool fBound = false;
24272427
for (const auto& addrBind : binds) {
2428-
fBound |= Bind(addrBind, (BF_EXPLICIT | BF_REPORT_ERROR), NetPermissionFlags::PF_NONE);
2428+
fBound |= Bind(addrBind, (BF_EXPLICIT | BF_REPORT_ERROR), NetPermissionFlags::None);
24292429
}
24302430
for (const auto& addrBind : whiteBinds) {
24312431
fBound |= Bind(addrBind.m_service, (BF_EXPLICIT | BF_REPORT_ERROR), addrBind.m_flags);
@@ -2434,12 +2434,12 @@ bool CConnman::InitBinds(
24342434
struct in_addr inaddr_any;
24352435
inaddr_any.s_addr = htonl(INADDR_ANY);
24362436
struct in6_addr inaddr6_any = IN6ADDR_ANY_INIT;
2437-
fBound |= Bind(CService(inaddr6_any, GetListenPort()), BF_NONE, NetPermissionFlags::PF_NONE);
2438-
fBound |= Bind(CService(inaddr_any, GetListenPort()), !fBound ? BF_REPORT_ERROR : BF_NONE, NetPermissionFlags::PF_NONE);
2437+
fBound |= Bind(CService(inaddr6_any, GetListenPort()), BF_NONE, NetPermissionFlags::None);
2438+
fBound |= Bind(CService(inaddr_any, GetListenPort()), !fBound ? BF_REPORT_ERROR : BF_NONE, NetPermissionFlags::None);
24392439
}
24402440

24412441
for (const auto& addr_bind : onion_binds) {
2442-
fBound |= Bind(addr_bind, BF_EXPLICIT | BF_DONT_ADVERTISE, NetPermissionFlags::PF_NONE);
2442+
fBound |= Bind(addr_bind, BF_EXPLICIT | BF_DONT_ADVERTISE, NetPermissionFlags::None);
24432443
}
24442444

24452445
return fBound;

src/net.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ class CNode
402402
std::unique_ptr<TransportDeserializer> m_deserializer;
403403
std::unique_ptr<TransportSerializer> m_serializer;
404404

405-
NetPermissionFlags m_permissionFlags{NetPermissionFlags::PF_NONE};
405+
NetPermissionFlags m_permissionFlags{NetPermissionFlags::None};
406406
std::atomic<ServiceFlags> nServices{NODE_NONE};
407407
SOCKET hSocket GUARDED_BY(cs_hSocket);
408408
/** Total size of all vSendMsg entries */

src/net_permissions.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ namespace {
2323
// The parse the following format "perm1,perm2@xxxxxx"
2424
bool TryParsePermissionFlags(const std::string str, NetPermissionFlags& output, size_t& readen, bilingual_str& error)
2525
{
26-
NetPermissionFlags flags = NetPermissionFlags::PF_NONE;
26+
NetPermissionFlags flags = NetPermissionFlags::None;
2727
const auto atSeparator = str.find('@');
2828

2929
// if '@' is not found (ie, "xxxxx"), the caller should apply implicit permissions
3030
if (atSeparator == std::string::npos) {
31-
NetPermissions::AddFlag(flags, NetPermissionFlags::PF_ISIMPLICIT);
31+
NetPermissions::AddFlag(flags, NetPermissionFlags::Implicit);
3232
readen = 0;
3333
}
3434
// else (ie, "perm1,perm2@xxxxx"), let's enumerate the permissions by splitting by ',' and calculate the flags
@@ -44,14 +44,14 @@ bool TryParsePermissionFlags(const std::string str, NetPermissionFlags& output,
4444
readen += len; // We read "perm1"
4545
if (commaSeparator != std::string::npos) readen++; // We read ","
4646

47-
if (permission == "bloomfilter" || permission == "bloom") NetPermissions::AddFlag(flags, NetPermissionFlags::PF_BLOOMFILTER);
48-
else if (permission == "noban") NetPermissions::AddFlag(flags, NetPermissionFlags::PF_NOBAN);
49-
else if (permission == "forcerelay") NetPermissions::AddFlag(flags, NetPermissionFlags::PF_FORCERELAY);
50-
else if (permission == "mempool") NetPermissions::AddFlag(flags, NetPermissionFlags::PF_MEMPOOL);
51-
else if (permission == "download") NetPermissions::AddFlag(flags, NetPermissionFlags::PF_DOWNLOAD);
52-
else if (permission == "all") NetPermissions::AddFlag(flags, NetPermissionFlags::PF_ALL);
53-
else if (permission == "relay") NetPermissions::AddFlag(flags, NetPermissionFlags::PF_RELAY);
54-
else if (permission == "addr") NetPermissions::AddFlag(flags, NetPermissionFlags::PF_ADDR);
47+
if (permission == "bloomfilter" || permission == "bloom") NetPermissions::AddFlag(flags, NetPermissionFlags::BloomFilter);
48+
else if (permission == "noban") NetPermissions::AddFlag(flags, NetPermissionFlags::NoBan);
49+
else if (permission == "forcerelay") NetPermissions::AddFlag(flags, NetPermissionFlags::ForceRelay);
50+
else if (permission == "mempool") NetPermissions::AddFlag(flags, NetPermissionFlags::Mempool);
51+
else if (permission == "download") NetPermissions::AddFlag(flags, NetPermissionFlags::Download);
52+
else if (permission == "all") NetPermissions::AddFlag(flags, NetPermissionFlags::All);
53+
else if (permission == "relay") NetPermissions::AddFlag(flags, NetPermissionFlags::Relay);
54+
else if (permission == "addr") NetPermissions::AddFlag(flags, NetPermissionFlags::Addr);
5555
else if (permission.length() == 0); // Allow empty entries
5656
else {
5757
error = strprintf(_("Invalid P2P permission: '%s'"), permission);
@@ -71,13 +71,13 @@ bool TryParsePermissionFlags(const std::string str, NetPermissionFlags& output,
7171
std::vector<std::string> NetPermissions::ToStrings(NetPermissionFlags flags)
7272
{
7373
std::vector<std::string> strings;
74-
if (NetPermissions::HasFlag(flags, NetPermissionFlags::PF_BLOOMFILTER)) strings.push_back("bloomfilter");
75-
if (NetPermissions::HasFlag(flags, NetPermissionFlags::PF_NOBAN)) strings.push_back("noban");
76-
if (NetPermissions::HasFlag(flags, NetPermissionFlags::PF_FORCERELAY)) strings.push_back("forcerelay");
77-
if (NetPermissions::HasFlag(flags, NetPermissionFlags::PF_RELAY)) strings.push_back("relay");
78-
if (NetPermissions::HasFlag(flags, NetPermissionFlags::PF_MEMPOOL)) strings.push_back("mempool");
79-
if (NetPermissions::HasFlag(flags, NetPermissionFlags::PF_DOWNLOAD)) strings.push_back("download");
80-
if (NetPermissions::HasFlag(flags, NetPermissionFlags::PF_ADDR)) strings.push_back("addr");
74+
if (NetPermissions::HasFlag(flags, NetPermissionFlags::BloomFilter)) strings.push_back("bloomfilter");
75+
if (NetPermissions::HasFlag(flags, NetPermissionFlags::NoBan)) strings.push_back("noban");
76+
if (NetPermissions::HasFlag(flags, NetPermissionFlags::ForceRelay)) strings.push_back("forcerelay");
77+
if (NetPermissions::HasFlag(flags, NetPermissionFlags::Relay)) strings.push_back("relay");
78+
if (NetPermissions::HasFlag(flags, NetPermissionFlags::Mempool)) strings.push_back("mempool");
79+
if (NetPermissions::HasFlag(flags, NetPermissionFlags::Download)) strings.push_back("download");
80+
if (NetPermissions::HasFlag(flags, NetPermissionFlags::Addr)) strings.push_back("addr");
8181
return strings;
8282
}
8383

src/net_permissions.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,27 @@ struct bilingual_str;
1616
extern const std::vector<std::string> NET_PERMISSIONS_DOC;
1717

1818
enum class NetPermissionFlags : uint32_t {
19-
PF_NONE = 0,
19+
None = 0,
2020
// Can query bloomfilter even if -peerbloomfilters is false
21-
PF_BLOOMFILTER = (1U << 1),
21+
BloomFilter = (1U << 1),
2222
// Relay and accept transactions from this peer, even if -blocksonly is true
2323
// This peer is also not subject to limits on how many transaction INVs are tracked
24-
PF_RELAY = (1U << 3),
24+
Relay = (1U << 3),
2525
// Always relay transactions from this peer, even if already in mempool
2626
// Keep parameter interaction: forcerelay implies relay
27-
PF_FORCERELAY = (1U << 2) | PF_RELAY,
27+
ForceRelay = (1U << 2) | Relay,
2828
// Allow getheaders during IBD and block-download after maxuploadtarget limit
29-
PF_DOWNLOAD = (1U << 6),
29+
Download = (1U << 6),
3030
// Can't be banned/disconnected/discouraged for misbehavior
31-
PF_NOBAN = (1U << 4) | PF_DOWNLOAD,
31+
NoBan = (1U << 4) | Download,
3232
// Can query the mempool
33-
PF_MEMPOOL = (1U << 5),
33+
Mempool = (1U << 5),
3434
// Can request addrs without hitting a privacy-preserving cache
35-
PF_ADDR = (1U << 7),
35+
Addr = (1U << 7),
3636

3737
// True if the user did not specifically set fine grained permissions
38-
PF_ISIMPLICIT = (1U << 31),
39-
PF_ALL = PF_BLOOMFILTER | PF_FORCERELAY | PF_RELAY | PF_NOBAN | PF_MEMPOOL | PF_DOWNLOAD | PF_ADDR,
38+
Implicit = (1U << 31),
39+
All = BloomFilter | ForceRelay | Relay | NoBan | Mempool | Download | Addr,
4040
};
4141
static inline constexpr NetPermissionFlags operator|(NetPermissionFlags a, NetPermissionFlags b)
4242
{
@@ -58,14 +58,14 @@ class NetPermissions
5858
{
5959
flags = flags | f;
6060
}
61-
//! ClearFlag is only called with `f` == NetPermissionFlags::PF_ISIMPLICIT.
61+
//! ClearFlag is only called with `f` == NetPermissionFlags::Implicit.
6262
//! If that should change in the future, be aware that ClearFlag should not
63-
//! be called with a subflag of a multiflag, e.g. NetPermissionFlags::PF_RELAY
64-
//! or NetPermissionFlags::PF_DOWNLOAD, as that would leave `flags` in an
63+
//! be called with a subflag of a multiflag, e.g. NetPermissionFlags::Relay
64+
//! or NetPermissionFlags::Download, as that would leave `flags` in an
6565
//! invalid state corresponding to none of the existing flags.
6666
static inline void ClearFlag(NetPermissionFlags& flags, NetPermissionFlags f)
6767
{
68-
assert(f == NetPermissionFlags::PF_ISIMPLICIT);
68+
assert(f == NetPermissionFlags::Implicit);
6969
using t = typename std::underlying_type<NetPermissionFlags>::type;
7070
flags = static_cast<NetPermissionFlags>(static_cast<t>(flags) & ~static_cast<t>(f));
7171
}

0 commit comments

Comments
 (0)