mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 18:53:23 -03:00
net: improve encapsulation of CNetAddr
Do not access `CNetAddr::ip` directly from `CService` methods. This improvement will help later when we change the type of `CNetAddr::ip` (in the BIP155 implementation). Co-authored-by: Carl Dong <contact@carldong.me>
This commit is contained in:
parent
fd9db45c3e
commit
bc74a40a56
2 changed files with 9 additions and 7 deletions
|
@ -726,12 +726,10 @@ bool CService::GetSockAddr(struct sockaddr* paddr, socklen_t *addrlen) const
|
||||||
*/
|
*/
|
||||||
std::vector<unsigned char> CService::GetKey() const
|
std::vector<unsigned char> CService::GetKey() const
|
||||||
{
|
{
|
||||||
std::vector<unsigned char> vKey;
|
auto key = GetAddrBytes();
|
||||||
vKey.resize(18);
|
key.push_back(port / 0x100); // most significant byte of our port
|
||||||
memcpy(vKey.data(), ip, 16);
|
key.push_back(port & 0x0FF); // least significant byte of our port
|
||||||
vKey[16] = port / 0x100; // most significant byte of our port
|
return key;
|
||||||
vKey[17] = port & 0x0FF; // least significant byte of our port
|
|
||||||
return vKey;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CService::ToStringPort() const
|
std::string CService::ToStringPort() const
|
||||||
|
|
|
@ -160,7 +160,11 @@ class CService : public CNetAddr
|
||||||
CService(const struct in6_addr& ipv6Addr, uint16_t port);
|
CService(const struct in6_addr& ipv6Addr, uint16_t port);
|
||||||
explicit CService(const struct sockaddr_in6& addr);
|
explicit CService(const struct sockaddr_in6& addr);
|
||||||
|
|
||||||
SERIALIZE_METHODS(CService, obj) { READWRITE(obj.ip, Using<BigEndianFormatter<2>>(obj.port)); }
|
SERIALIZE_METHODS(CService, obj)
|
||||||
|
{
|
||||||
|
READWRITEAS(CNetAddr, obj);
|
||||||
|
READWRITE(Using<BigEndianFormatter<2>>(obj.port));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
bool SanityCheckASMap(const std::vector<bool>& asmap);
|
bool SanityCheckASMap(const std::vector<bool>& asmap);
|
||||||
|
|
Loading…
Add table
Reference in a new issue