Changeset View
Changeset View
Standalone View
Standalone View
src/net_permissions.cpp
// Copyright (c) 2009-2018 The Bitcoin Core developers | // Copyright (c) 2009-2018 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <net_permissions.h> | #include <net_permissions.h> | ||||
#include <netbase.h> | #include <netbase.h> | ||||
#include <util/error.h> | #include <util/error.h> | ||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <util/translation.h> | #include <util/translation.h> | ||||
const std::vector<std::string> NET_PERMISSIONS_DOC{ | const std::vector<std::string> NET_PERMISSIONS_DOC{ | ||||
"bloomfilter (allow requesting BIP37 filtered blocks and transactions)", | "bloomfilter (allow requesting BIP37 filtered blocks and transactions)", | ||||
"noban (do not ban for misbehavior)", | "noban (do not ban for misbehavior; implies download)", | ||||
"forcerelay (relay transactions that are already in the mempool; implies " | "forcerelay (relay transactions that are already in the mempool; implies " | ||||
"relay)", | "relay)", | ||||
"relay (relay even in -blocksonly mode)", | "relay (relay even in -blocksonly mode)", | ||||
"mempool (allow requesting BIP35 mempool contents)", | "mempool (allow requesting BIP35 mempool contents)", | ||||
"download (allow getheaders during IBD, no disconnect after " | |||||
"maxuploadtarget limit)", | |||||
}; | }; | ||||
namespace { | namespace { | ||||
// The parse the following format "perm1,perm2@xxxxxx" | // The parse the following format "perm1,perm2@xxxxxx" | ||||
bool TryParsePermissionFlags(const std::string str, NetPermissionFlags &output, | bool TryParsePermissionFlags(const std::string str, NetPermissionFlags &output, | ||||
size_t &readen, bilingual_str &error) { | size_t &readen, bilingual_str &error) { | ||||
NetPermissionFlags flags = PF_NONE; | NetPermissionFlags flags = PF_NONE; | ||||
Show All 28 Lines | else { | ||||
if (permission == "bloomfilter" || permission == "bloom") { | if (permission == "bloomfilter" || permission == "bloom") { | ||||
NetPermissions::AddFlag(flags, PF_BLOOMFILTER); | NetPermissions::AddFlag(flags, PF_BLOOMFILTER); | ||||
} else if (permission == "noban") { | } else if (permission == "noban") { | ||||
NetPermissions::AddFlag(flags, PF_NOBAN); | NetPermissions::AddFlag(flags, PF_NOBAN); | ||||
} else if (permission == "forcerelay") { | } else if (permission == "forcerelay") { | ||||
NetPermissions::AddFlag(flags, PF_FORCERELAY); | NetPermissions::AddFlag(flags, PF_FORCERELAY); | ||||
} else if (permission == "mempool") { | } else if (permission == "mempool") { | ||||
NetPermissions::AddFlag(flags, PF_MEMPOOL); | NetPermissions::AddFlag(flags, PF_MEMPOOL); | ||||
} else if (permission == "download") { | |||||
NetPermissions::AddFlag(flags, PF_DOWNLOAD); | |||||
} else if (permission == "all") { | } else if (permission == "all") { | ||||
NetPermissions::AddFlag(flags, PF_ALL); | NetPermissions::AddFlag(flags, PF_ALL); | ||||
} else if (permission == "relay") { | } else if (permission == "relay") { | ||||
NetPermissions::AddFlag(flags, PF_RELAY); | NetPermissions::AddFlag(flags, PF_RELAY); | ||||
} else if (permission.length() == 0) { | } else if (permission.length() == 0) { | ||||
// Allow empty entries | // Allow empty entries | ||||
} else { | } else { | ||||
error = | error = | ||||
Show All 23 Lines | if (NetPermissions::HasFlag(flags, PF_FORCERELAY)) { | ||||
strings.push_back("forcerelay"); | strings.push_back("forcerelay"); | ||||
} | } | ||||
if (NetPermissions::HasFlag(flags, PF_RELAY)) { | if (NetPermissions::HasFlag(flags, PF_RELAY)) { | ||||
strings.push_back("relay"); | strings.push_back("relay"); | ||||
} | } | ||||
if (NetPermissions::HasFlag(flags, PF_MEMPOOL)) { | if (NetPermissions::HasFlag(flags, PF_MEMPOOL)) { | ||||
strings.push_back("mempool"); | strings.push_back("mempool"); | ||||
} | } | ||||
if (NetPermissions::HasFlag(flags, PF_DOWNLOAD)) { | |||||
strings.push_back("download"); | |||||
} | |||||
return strings; | return strings; | ||||
} | } | ||||
bool NetWhitebindPermissions::TryParse(const std::string str, | bool NetWhitebindPermissions::TryParse(const std::string str, | ||||
NetWhitebindPermissions &output, | NetWhitebindPermissions &output, | ||||
bilingual_str &error) { | bilingual_str &error) { | ||||
NetPermissionFlags flags; | NetPermissionFlags flags; | ||||
size_t offset; | size_t offset; | ||||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |