Skip to content

Commit 64d6f77

Browse files
committed
net: put CJDNS prefix byte in a constant
1 parent 78fd3c2 commit 64d6f77

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/netaddress.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ static const std::array<uint8_t, 6> INTERNAL_IN_IPV6_PREFIX{
8181
0xFD, 0x6B, 0x88, 0xC0, 0x87, 0x24 // 0xFD + sha256("bitcoin")[0:5].
8282
};
8383

84+
/// All CJDNS addresses start with 0xFC. See
85+
/// https://github.com/cjdelisle/cjdns/blob/master/doc/Whitepaper.md#pulling-it-all-together
86+
static constexpr uint8_t CJDNS_PREFIX{0xFC};
87+
8488
/// Size of IPv4 address (in bytes).
8589
static constexpr size_t ADDR_IPV4_SIZE = 4;
8690

@@ -174,7 +178,7 @@ class CNetAddr
174178
[[nodiscard]] bool IsTor() const { return m_net == NET_ONION; }
175179
[[nodiscard]] bool IsI2P() const { return m_net == NET_I2P; }
176180
[[nodiscard]] bool IsCJDNS() const { return m_net == NET_CJDNS; }
177-
[[nodiscard]] bool HasCJDNSPrefix() const { return m_addr[0] == 0xfc; }
181+
[[nodiscard]] bool HasCJDNSPrefix() const { return m_addr[0] == CJDNS_PREFIX; }
178182
bool IsLocal() const;
179183
bool IsRoutable() const;
180184
bool IsInternal() const;

src/netgroup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ std::vector<unsigned char> NetGroupManager::GetGroup(const CNetAddr& address) co
5252
} else if (address.IsCJDNS()) {
5353
// Treat in the same way as Tor and I2P because the address in all of
5454
// them is "random" bytes (derived from a public key). However in CJDNS
55-
// the first byte is a constant 0xfc, so the random bytes come after it.
56-
// Thus skip the constant 8 bits at the start.
55+
// the first byte is a constant (see CJDNS_PREFIX), so the random bytes
56+
// come after it. Thus skip the constant 8 bits at the start.
5757
nBits = 12;
5858
} else if (address.IsHeNet()) {
5959
// for he.net, use /36 groups

0 commit comments

Comments
 (0)