LCOV - code coverage report
Current view: top level - src - net_permissions.h (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 16 16 100.0 %
Date: 2021-06-29 14:35:33 Functions: 5 23 21.7 %
Legend: Modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed

Not modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed
Branches: 0 0 -

           Branch data     Line data    Source code
#       1                 :            : // Copyright (c) 2009-2020 The Bitcoin Core developers
#       2                 :            : // Distributed under the MIT software license, see the accompanying
#       3                 :            : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#       4                 :            : 
#       5                 :            : #include <netaddress.h>
#       6                 :            : 
#       7                 :            : #include <string>
#       8                 :            : #include <type_traits>
#       9                 :            : #include <vector>
#      10                 :            : 
#      11                 :            : #ifndef BITCOIN_NET_PERMISSIONS_H
#      12                 :            : #define BITCOIN_NET_PERMISSIONS_H
#      13                 :            : 
#      14                 :            : struct bilingual_str;
#      15                 :            : 
#      16                 :            : extern const std::vector<std::string> NET_PERMISSIONS_DOC;
#      17                 :            : 
#      18                 :            : enum class NetPermissionFlags : uint32_t {
#      19                 :            :     None = 0,
#      20                 :            :     // Can query bloomfilter even if -peerbloomfilters is false
#      21                 :            :     BloomFilter = (1U << 1),
#      22                 :            :     // Relay and accept transactions from this peer, even if -blocksonly is true
#      23                 :            :     // This peer is also not subject to limits on how many transaction INVs are tracked
#      24                 :            :     Relay = (1U << 3),
#      25                 :            :     // Always relay transactions from this peer, even if already in mempool
#      26                 :            :     // Keep parameter interaction: forcerelay implies relay
#      27                 :            :     ForceRelay = (1U << 2) | Relay,
#      28                 :            :     // Allow getheaders during IBD and block-download after maxuploadtarget limit
#      29                 :            :     Download = (1U << 6),
#      30                 :            :     // Can't be banned/disconnected/discouraged for misbehavior
#      31                 :            :     NoBan = (1U << 4) | Download,
#      32                 :            :     // Can query the mempool
#      33                 :            :     Mempool = (1U << 5),
#      34                 :            :     // Can request addrs without hitting a privacy-preserving cache
#      35                 :            :     Addr = (1U << 7),
#      36                 :            : 
#      37                 :            :     // True if the user did not specifically set fine grained permissions
#      38                 :            :     Implicit = (1U << 31),
#      39                 :            :     All = BloomFilter | ForceRelay | Relay | NoBan | Mempool | Download | Addr,
#      40                 :            : };
#      41                 :            : static inline constexpr NetPermissionFlags operator|(NetPermissionFlags a, NetPermissionFlags b)
#      42                 :        933 : {
#      43                 :        933 :     using t = typename std::underlying_type<NetPermissionFlags>::type;
#      44                 :        933 :     return static_cast<NetPermissionFlags>(static_cast<t>(a) | static_cast<t>(b));
#      45                 :        933 : }
#      46                 :            : 
#      47                 :            : class NetPermissions
#      48                 :            : {
#      49                 :            : public:
#      50                 :            :     NetPermissionFlags m_flags;
#      51                 :            :     static std::vector<std::string> ToStrings(NetPermissionFlags flags);
#      52                 :            :     static inline bool HasFlag(NetPermissionFlags flags, NetPermissionFlags f)
#      53                 :     871241 :     {
#      54                 :     871241 :         using t = typename std::underlying_type<NetPermissionFlags>::type;
#      55                 :     871241 :         return (static_cast<t>(flags) & static_cast<t>(f)) == static_cast<t>(f);
#      56                 :     871241 :     }
#      57                 :            :     static inline void AddFlag(NetPermissionFlags& flags, NetPermissionFlags f)
#      58                 :        909 :     {
#      59                 :        909 :         flags = flags | f;
#      60                 :        909 :     }
#      61                 :            :     //! ClearFlag is only called with `f` == NetPermissionFlags::Implicit.
#      62                 :            :     //! 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::Relay
#      64                 :            :     //! or NetPermissionFlags::Download, as that would leave `flags` in an
#      65                 :            :     //! invalid state corresponding to none of the existing flags.
#      66                 :            :     static inline void ClearFlag(NetPermissionFlags& flags, NetPermissionFlags f)
#      67                 :          8 :     {
#      68                 :          8 :         assert(f == NetPermissionFlags::Implicit);
#      69                 :          8 :         using t = typename std::underlying_type<NetPermissionFlags>::type;
#      70                 :          8 :         flags = static_cast<NetPermissionFlags>(static_cast<t>(flags) & ~static_cast<t>(f));
#      71                 :          8 :     }
#      72                 :            : };
#      73                 :            : 
#      74                 :            : class NetWhitebindPermissions : public NetPermissions
#      75                 :            : {
#      76                 :            : public:
#      77                 :            :     static bool TryParse(const std::string& str, NetWhitebindPermissions& output, bilingual_str& error);
#      78                 :            :     CService m_service;
#      79                 :            : };
#      80                 :            : 
#      81                 :            : class NetWhitelistPermissions : public NetPermissions
#      82                 :            : {
#      83                 :            : public:
#      84                 :            :     static bool TryParse(const std::string& str, NetWhitelistPermissions& output, bilingual_str& error);
#      85                 :            :     CSubNet m_subnet;
#      86                 :            : };
#      87                 :            : 
#      88                 :            : #endif // BITCOIN_NET_PERMISSIONS_H

Generated by: LCOV version 1.14