Skip to content

Commit

Permalink
net: improve encapsulation of CNetAddr.
Browse files Browse the repository at this point in the history
 This improvement will help later when we change the type of `CNetAddr::ip` (in the BIP155 implementation).

 Adaptation of btc@bc74a40a56128f81f11151d5966f53b82f19038c
  • Loading branch information
furszy committed Aug 10, 2021
1 parent 910d5c4 commit 3337219
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/netaddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,12 +666,10 @@ bool CService::GetSockAddr(struct sockaddr* paddr, socklen_t *addrlen) const

std::vector<unsigned char> CService::GetKey() const
{
std::vector<unsigned char> vKey;
vKey.resize(18);
memcpy(vKey.data(), ip, 16);
vKey[16] = port / 0x100;
vKey[17] = port & 0x0FF;
return vKey;
auto key = GetAddrBytes();
key.push_back(port / 0x100); // most significant byte of our port
key.push_back(port & 0x0FF); // least significant byte of our port
return key;
}

std::string CService::ToStringPort() const
Expand Down
1 change: 1 addition & 0 deletions src/netaddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class CNetAddr
uint32_t GetMappedAS(const std::vector<bool> &asmap) const;

std::vector<unsigned char> GetGroup(const std::vector<bool> &asmap) const;
std::vector<unsigned char> GetAddrBytes() const { return {std::begin(ip), std::end(ip)}; }
int GetReachabilityFrom(const CNetAddr* paddrPartner = nullptr) const;

CNetAddr(const struct in6_addr& pipv6Addr, const uint32_t scope = 0);
Expand Down

0 comments on commit 3337219

Please sign in to comment.